bootstrap.js 2.2 KB

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