bootstrap.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 npmIgnorePath = path.join(packagesDir, shortName, `.npmignore`)
  45. if (args.force || !fs.existsSync(npmIgnorePath)) {
  46. fs.writeFileSync(npmIgnorePath, `__tests__/\n__mocks__/\ndist/packages`)
  47. }
  48. const srcDir = path.join(packagesDir, shortName, `src`)
  49. const indexPath = path.join(packagesDir, shortName, `src/index.ts`)
  50. if (args.force || !fs.existsSync(indexPath)) {
  51. if (!fs.existsSync(srcDir)) {
  52. fs.mkdirSync(srcDir)
  53. }
  54. fs.writeFileSync(indexPath, ``)
  55. }
  56. const nodeIndexPath = path.join(packagesDir, shortName, 'index.js')
  57. if (args.force || !fs.existsSync(nodeIndexPath)) {
  58. fs.writeFileSync(
  59. nodeIndexPath,
  60. `
  61. 'use strict'
  62. if (process.env.NODE_ENV === 'production') {
  63. module.exports = require('./dist/${shortName}.cjs.prod.js')
  64. } else {
  65. module.exports = require('./dist/${shortName}.cjs.js')
  66. }
  67. `.trim() + '\n'
  68. )
  69. }
  70. })