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