forked from vuejs/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.js
99 lines (89 loc) · 2.64 KB
/
bootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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')
const version = require('../package.json').version
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`)
const pkgExists = fs.existsSync(pkgPath)
if (pkgExists) {
const pkg = require(pkgPath)
if (pkg.private) {
return
}
}
if (args.force || !pkgExists) {
const json = {
name,
version,
description: name,
main: 'index.js',
module: `dist/${shortName}.esm-bundler.js`,
files: [`index.js`, `dist`],
types: `dist/${shortName}.d.ts`,
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}`)
}
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": {
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
}
}
`.trim()
)
}
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'
)
}
})