2018-10-25 11:22:31 +00:00
|
|
|
#!/usr/bin/env node -r esm
|
|
|
|
import path from 'path'
|
|
|
|
import fs from 'fs-extra'
|
|
|
|
import consola from 'consola'
|
|
|
|
|
|
|
|
import Package from './package.js'
|
|
|
|
|
2018-11-01 04:00:28 +00:00
|
|
|
const useCjs = new Set([
|
|
|
|
'@nuxt/cli'
|
|
|
|
])
|
|
|
|
|
|
|
|
const stub = {
|
|
|
|
es: `export * from '../src/index'`,
|
|
|
|
cjs: `const esm = require('esm')
|
|
|
|
|
|
|
|
const _require = esm(module, {
|
|
|
|
cache: false,
|
|
|
|
cjs: {
|
|
|
|
cache: true,
|
|
|
|
vars: true,
|
|
|
|
namedExports: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = _require('../src/index')
|
|
|
|
`}
|
|
|
|
|
2018-10-25 11:22:31 +00:00
|
|
|
async function main() {
|
|
|
|
// Read package at current directory
|
|
|
|
const rootPackage = new Package()
|
|
|
|
const workspacePackages = rootPackage.getWorkspacePackages()
|
|
|
|
|
|
|
|
// Create a dev-only entrypoint to the src
|
|
|
|
for (const pkg of workspacePackages) {
|
2018-10-26 17:58:21 +00:00
|
|
|
if (!pkg.pkg.main || !pkg.options.build) {
|
2018-10-25 11:22:31 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
consola.info(pkg.pkg.main)
|
|
|
|
const distMain = pkg.resolvePath(pkg.pkg.main)
|
|
|
|
await fs.mkdirp(path.dirname(distMain))
|
2018-11-01 04:00:28 +00:00
|
|
|
await fs.writeFile(distMain, useCjs.has(pkg.pkg.name) ? stub.cjs : stub.es)
|
2018-10-25 11:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((error) => {
|
|
|
|
consola.error(error)
|
|
|
|
process.exit(1)
|
|
|
|
})
|