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'
|
|
|
|
|
2019-01-16 17:53:14 +00:00
|
|
|
const useCjs = [
|
2018-11-01 04:00:28 +00:00
|
|
|
'@nuxt/cli'
|
2019-01-16 17:53:14 +00:00
|
|
|
]
|
2018-11-01 04:00:28 +00:00
|
|
|
|
|
|
|
const stub = {
|
2019-11-26 22:42:39 +00:00
|
|
|
es: 'export * from \'../src/index\'',
|
2020-06-11 13:59:13 +00:00
|
|
|
cjs: `const _require = typeof jest === 'undefined' ? require('esm')(module) : require
|
2020-06-24 08:23:29 +00:00
|
|
|
global.__NUXT_DEV__ = true
|
|
|
|
module.exports = _require('../src/index')
|
2019-11-26 22:42:39 +00:00
|
|
|
`
|
|
|
|
}
|
2018-11-01 04:00:28 +00:00
|
|
|
|
2019-07-10 10:45:49 +00:00
|
|
|
async function main () {
|
2018-10-25 11:22:31 +00:00
|
|
|
// Read package at current directory
|
|
|
|
const rootPackage = new Package()
|
2018-11-27 15:32:00 +00:00
|
|
|
const workspacePackages = await rootPackage.getWorkspacePackages()
|
2018-10-25 11:22:31 +00:00
|
|
|
|
|
|
|
// 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))
|
2019-01-16 17:53:14 +00:00
|
|
|
await fs.writeFile(distMain, useCjs.includes(pkg.pkg.name) ? stub.cjs : stub.es)
|
2018-10-25 11:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((error) => {
|
|
|
|
consola.error(error)
|
|
|
|
process.exit(1)
|
|
|
|
})
|