bootstrap.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 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. })