bootstrap.js 2.6 KB

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