bootstrap.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. types: 'dist/index.d.ts',
  25. repository: {
  26. type: 'git',
  27. url: 'git+https://github.com/vuejs/vue.git'
  28. },
  29. keywords: ['vue'],
  30. author: 'Evan You',
  31. license: 'MIT',
  32. bugs: {
  33. url: 'https://github.com/vuejs/vue/issues'
  34. },
  35. homepage: `https://github.com/vuejs/vue/tree/dev/packages/${shortName}#readme`
  36. }
  37. fs.writeFileSync(pkgPath, JSON.stringify(json, null, 2))
  38. }
  39. const readmePath = path.join(packagesDir, shortName, `README.md`)
  40. if (args.force || !fs.existsSync(readmePath)) {
  41. fs.writeFileSync(readmePath, `# ${name}`)
  42. }
  43. const npmIgnorePath = path.join(packagesDir, shortName, `.npmignore`)
  44. if (args.force || !fs.existsSync(npmIgnorePath)) {
  45. fs.writeFileSync(npmIgnorePath, `__tests__/\n__mocks__/\ndist/packages`)
  46. }
  47. const srcDir = path.join(packagesDir, shortName, `src`)
  48. const indexPath = path.join(packagesDir, shortName, `src/index.ts`)
  49. if (args.force || !fs.existsSync(indexPath)) {
  50. if (!fs.existsSync(srcDir)) {
  51. fs.mkdirSync(srcDir)
  52. }
  53. fs.writeFileSync(indexPath, ``)
  54. }
  55. const nodeIndexPath = path.join(packagesDir, shortName, 'index.js')
  56. if (args.force || !fs.existsSync(nodeIndexPath)) {
  57. fs.writeFileSync(
  58. nodeIndexPath,
  59. `
  60. 'use strict'
  61. if (process.env.NODE_ENV === 'production') {
  62. module.exports = require('./dist/${shortName}.cjs.prod.js')
  63. } else {
  64. module.exports = require('./dist/${shortName}.cjs.js')
  65. }
  66. `.trim() + '\n'
  67. )
  68. }
  69. })