2018-09-19 23:35:38 +08:00
|
|
|
// create package.json, README, etc. for packages that don't have them yet
|
|
|
|
|
|
|
|
const args = require('minimist')(process.argv.slice(2))
|
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
2019-12-11 07:24:59 +08:00
|
|
|
const version = require('../package.json').version
|
2018-09-19 23:35:38 +08:00
|
|
|
|
|
|
|
const packagesDir = path.resolve(__dirname, '../packages')
|
|
|
|
const files = fs.readdirSync(packagesDir)
|
|
|
|
|
|
|
|
files.forEach(shortName => {
|
|
|
|
if (!fs.statSync(path.join(packagesDir, shortName)).isDirectory()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const name = shortName === `vue` ? shortName : `@vue/${shortName}`
|
|
|
|
const pkgPath = path.join(packagesDir, shortName, `package.json`)
|
2019-10-05 01:08:06 +08:00
|
|
|
const pkgExists = fs.existsSync(pkgPath)
|
|
|
|
if (pkgExists) {
|
|
|
|
const pkg = require(pkgPath)
|
|
|
|
if (pkg.private) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.force || !pkgExists) {
|
2018-09-19 23:35:38 +08:00
|
|
|
const json = {
|
|
|
|
name,
|
2019-12-11 07:24:59 +08:00
|
|
|
version,
|
2018-09-19 23:35:38 +08:00
|
|
|
description: name,
|
|
|
|
main: 'index.js',
|
2018-09-20 09:51:21 +08:00
|
|
|
module: `dist/${shortName}.esm-bundler.js`,
|
2019-09-04 00:16:22 +08:00
|
|
|
files: [`index.js`, `dist`],
|
|
|
|
types: `dist/${shortName}.d.ts`,
|
2018-09-19 23:35:38 +08:00
|
|
|
repository: {
|
|
|
|
type: 'git',
|
|
|
|
url: 'git+https://github.com/vuejs/vue.git'
|
|
|
|
},
|
|
|
|
keywords: ['vue'],
|
|
|
|
author: 'Evan You',
|
|
|
|
license: 'MIT',
|
|
|
|
bugs: {
|
|
|
|
url: 'https://github.com/vuejs/vue/issues'
|
|
|
|
},
|
|
|
|
homepage: `https://github.com/vuejs/vue/tree/dev/packages/${shortName}#readme`
|
|
|
|
}
|
|
|
|
fs.writeFileSync(pkgPath, JSON.stringify(json, null, 2))
|
|
|
|
}
|
|
|
|
|
|
|
|
const readmePath = path.join(packagesDir, shortName, `README.md`)
|
|
|
|
if (args.force || !fs.existsSync(readmePath)) {
|
|
|
|
fs.writeFileSync(readmePath, `# ${name}`)
|
|
|
|
}
|
|
|
|
|
2019-09-17 03:06:45 +08:00
|
|
|
const apiExtractorConfigPath = path.join(
|
|
|
|
packagesDir,
|
|
|
|
shortName,
|
|
|
|
`api-extractor.json`
|
|
|
|
)
|
|
|
|
if (args.force || !fs.existsSync(apiExtractorConfigPath)) {
|
|
|
|
fs.writeFileSync(
|
|
|
|
apiExtractorConfigPath,
|
|
|
|
`
|
|
|
|
{
|
|
|
|
"extends": "../../api-extractor.json",
|
|
|
|
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
|
|
|
|
"dtsRollup": {
|
2020-05-01 05:04:35 +08:00
|
|
|
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
|
2019-09-17 03:06:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`.trim()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-19 23:35:38 +08:00
|
|
|
const srcDir = path.join(packagesDir, shortName, `src`)
|
|
|
|
const indexPath = path.join(packagesDir, shortName, `src/index.ts`)
|
|
|
|
if (args.force || !fs.existsSync(indexPath)) {
|
|
|
|
if (!fs.existsSync(srcDir)) {
|
|
|
|
fs.mkdirSync(srcDir)
|
|
|
|
}
|
|
|
|
fs.writeFileSync(indexPath, ``)
|
|
|
|
}
|
|
|
|
|
|
|
|
const nodeIndexPath = path.join(packagesDir, shortName, 'index.js')
|
|
|
|
if (args.force || !fs.existsSync(nodeIndexPath)) {
|
|
|
|
fs.writeFileSync(
|
|
|
|
nodeIndexPath,
|
|
|
|
`
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
module.exports = require('./dist/${shortName}.cjs.prod.js')
|
|
|
|
} else {
|
|
|
|
module.exports = require('./dist/${shortName}.cjs.js')
|
|
|
|
}
|
|
|
|
`.trim() + '\n'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|