forked from aris-creator/jancok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.js
95 lines (85 loc) · 2.53 KB
/
bootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// create package.json, README, etc. for packages that don't have them yet
const args = require("minimist")(process.argv.slice(2));
const fs = require("fs");
const path = require("path");
const baseVersion = require("../package.json").version;
const packagesDir = path.resolve(__dirname, "../packages");
const files = fs.readdirSync(packagesDir);
files.forEach((shortName) => {
if (!fs.statSync(path.join(packagesDir, shortName)).isDirectory()) {
return;
}
const name = `@shopware-pwa/${shortName}`;
const pkgPath = path.join(packagesDir, shortName, `package.json`);
const pkgExists = fs.existsSync(pkgPath);
if (pkgExists) {
const pkg = require(pkgPath);
if (pkg.private) {
return;
}
}
if (args.force || !pkgExists) {
const json = {
name,
version: baseVersion,
description: name,
main: `dist/${shortName}.cjs.js`,
module: `dist/${shortName}.esm.js`,
files: [`dist`],
types: `dist/${shortName}.d.ts`,
unpkg: `dist/${shortName}.global.js`,
sideEffects: false,
repository: {
type: "git",
url: "git+https://github.com/DivanteLtd/shopware-pwa",
},
license: "MIT",
};
fs.writeFileSync(pkgPath, JSON.stringify(json, null, 2));
}
const readmePath = path.join(packagesDir, shortName, `README.md`);
if (args.force || !fs.existsSync(readmePath)) {
fs.writeFileSync(readmePath, `# ${name}`);
}
const apiExtractorConfigPath = path.join(
packagesDir,
shortName,
`api-extractor.json`
);
if (args.force || !fs.existsSync(apiExtractorConfigPath)) {
fs.writeFileSync(
apiExtractorConfigPath,
`
{
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
}
}
`.trim()
);
}
const srcDir = path.join(packagesDir, shortName, `src`);
const indexPath = path.join(packagesDir, shortName, `src/index.ts`);
if (args.force || !fs.existsSync(indexPath)) {
if (!fs.existsSync(srcDir)) {
fs.mkdirSync(srcDir);
}
fs.writeFileSync(indexPath, ``);
}
const nodeIndexPath = path.join(packagesDir, shortName, "index.js");
if (args.force || !fs.existsSync(nodeIndexPath)) {
fs.writeFileSync(
nodeIndexPath,
`
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/${shortName}.cjs.prod.js')
} else {
module.exports = require('./dist/${shortName}.cjs.js')
}
`.trim() + "\n"
);
}
});