bootstrap.mjs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // create package.json, README, etc. for packages that don't have them yet
  2. // @ts-check
  3. import minimist from 'minimist'
  4. import fs from 'node:fs'
  5. import path from 'node:path'
  6. import { createRequire } from 'node:module'
  7. import { fileURLToPath } from 'url'
  8. const args = minimist(process.argv.slice(2))
  9. const require = createRequire(import.meta.url)
  10. const version = require('../package.json').version
  11. const packagesDir = path.resolve(
  12. fileURLToPath(import.meta.url),
  13. '../../packages'
  14. )
  15. const files = fs.readdirSync(packagesDir)
  16. files.forEach(shortName => {
  17. if (!fs.statSync(path.join(packagesDir, shortName)).isDirectory()) {
  18. return
  19. }
  20. const name = shortName === `vue` ? shortName : `@vue/${shortName}`
  21. const pkgPath = path.join(packagesDir, shortName, `package.json`)
  22. const pkgExists = fs.existsSync(pkgPath)
  23. if (pkgExists) {
  24. const pkg = require(pkgPath)
  25. if (pkg.private) {
  26. return
  27. }
  28. }
  29. if (args.force || !pkgExists) {
  30. const json = {
  31. name,
  32. version,
  33. description: name,
  34. main: 'index.js',
  35. module: `dist/${shortName}.esm-bundler.js`,
  36. files: [`index.js`, `dist`],
  37. types: `dist/${shortName}.d.ts`,
  38. repository: {
  39. type: 'git',
  40. url: 'git+https://github.com/vuejs/vue.git'
  41. },
  42. keywords: ['vue'],
  43. author: 'Evan You',
  44. license: 'MIT',
  45. bugs: {
  46. url: 'https://github.com/vuejs/vue/issues'
  47. },
  48. homepage: `https://github.com/vuejs/vue/tree/dev/packages/${shortName}#readme`
  49. }
  50. fs.writeFileSync(pkgPath, JSON.stringify(json, null, 2))
  51. }
  52. const readmePath = path.join(packagesDir, shortName, `README.md`)
  53. if (args.force || !fs.existsSync(readmePath)) {
  54. fs.writeFileSync(readmePath, `# ${name}`)
  55. }
  56. const apiExtractorConfigPath = path.join(
  57. packagesDir,
  58. shortName,
  59. `api-extractor.json`
  60. )
  61. if (args.force || !fs.existsSync(apiExtractorConfigPath)) {
  62. fs.writeFileSync(
  63. apiExtractorConfigPath,
  64. `
  65. {
  66. "extends": "../../api-extractor.json",
  67. "mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
  68. "dtsRollup": {
  69. "publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
  70. }
  71. }
  72. `.trim()
  73. )
  74. }
  75. const srcDir = path.join(packagesDir, shortName, `src`)
  76. const indexPath = path.join(packagesDir, shortName, `src/index.ts`)
  77. if (args.force || !fs.existsSync(indexPath)) {
  78. if (!fs.existsSync(srcDir)) {
  79. fs.mkdirSync(srcDir)
  80. }
  81. fs.writeFileSync(indexPath, ``)
  82. }
  83. const nodeIndexPath = path.join(packagesDir, shortName, 'index.js')
  84. if (args.force || !fs.existsSync(nodeIndexPath)) {
  85. fs.writeFileSync(
  86. nodeIndexPath,
  87. `
  88. 'use strict'
  89. if (process.env.NODE_ENV === 'production') {
  90. module.exports = require('./dist/${shortName}.cjs.prod.js')
  91. } else {
  92. module.exports = require('./dist/${shortName}.cjs.js')
  93. }
  94. `.trim() + '\n'
  95. )
  96. }
  97. })