2
0

bootstrap.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // create package.json, README, etc. for packages that don't have them yet
  2. const args = require('minimist')(process.argv.slice(2))
  3. const fs = require('fs')
  4. const path = require('path')
  5. const version = require('../package.json').version
  6. const packagesDir = path.resolve(__dirname, '../packages')
  7. const files = fs.readdirSync(packagesDir)
  8. files.forEach(shortName => {
  9. if (!fs.statSync(path.join(packagesDir, shortName)).isDirectory()) {
  10. return
  11. }
  12. const name = shortName === `vue` ? shortName : `@vue/${shortName}`
  13. const pkgPath = path.join(packagesDir, shortName, `package.json`)
  14. const pkgExists = fs.existsSync(pkgPath)
  15. if (pkgExists) {
  16. const pkg = require(pkgPath)
  17. if (pkg.private) {
  18. return
  19. }
  20. }
  21. if (args.force || !pkgExists) {
  22. const json = {
  23. name,
  24. version,
  25. description: name,
  26. main: 'index.js',
  27. module: `dist/${shortName}.esm-bundler.js`,
  28. files: [`index.js`, `dist`],
  29. types: `dist/${shortName}.d.ts`,
  30. repository: {
  31. type: 'git',
  32. url: 'git+https://github.com/vuejs/vue.git'
  33. },
  34. keywords: ['vue'],
  35. author: 'Evan You',
  36. license: 'MIT',
  37. bugs: {
  38. url: 'https://github.com/vuejs/vue/issues'
  39. },
  40. homepage: `https://github.com/vuejs/vue/tree/dev/packages/${shortName}#readme`
  41. }
  42. fs.writeFileSync(pkgPath, JSON.stringify(json, null, 2))
  43. }
  44. const readmePath = path.join(packagesDir, shortName, `README.md`)
  45. if (args.force || !fs.existsSync(readmePath)) {
  46. fs.writeFileSync(readmePath, `# ${name}`)
  47. }
  48. const apiExtractorConfigPath = path.join(
  49. packagesDir,
  50. shortName,
  51. `api-extractor.json`
  52. )
  53. if (args.force || !fs.existsSync(apiExtractorConfigPath)) {
  54. fs.writeFileSync(
  55. apiExtractorConfigPath,
  56. `
  57. {
  58. "extends": "../../api-extractor.json",
  59. "mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
  60. "dtsRollup": {
  61. "publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
  62. }
  63. }
  64. `.trim()
  65. )
  66. }
  67. const srcDir = path.join(packagesDir, shortName, `src`)
  68. const indexPath = path.join(packagesDir, shortName, `src/index.ts`)
  69. if (args.force || !fs.existsSync(indexPath)) {
  70. if (!fs.existsSync(srcDir)) {
  71. fs.mkdirSync(srcDir)
  72. }
  73. fs.writeFileSync(indexPath, ``)
  74. }
  75. const nodeIndexPath = path.join(packagesDir, shortName, 'index.js')
  76. if (args.force || !fs.existsSync(nodeIndexPath)) {
  77. fs.writeFileSync(
  78. nodeIndexPath,
  79. `
  80. 'use strict'
  81. if (process.env.NODE_ENV === 'production') {
  82. module.exports = require('./dist/${shortName}.cjs.prod.js')
  83. } else {
  84. module.exports = require('./dist/${shortName}.cjs.js')
  85. }
  86. `.trim() + '\n'
  87. )
  88. }
  89. })