pob 19.2.0 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/lib/generators/app/PobAppGenerator.js +120 -120
- package/lib/generators/app/e2e-testing/AppE2ETestingGenerator.js +11 -11
- package/lib/generators/app/ignorePaths.js +24 -24
- package/lib/generators/app/nextjs/AppNextjsGenerator.js +9 -9
- package/lib/generators/app/remix/AppRemixGenerator.js +7 -7
- package/lib/generators/common/babel/CommonBabelGenerator.js +146 -146
- package/lib/generators/common/format-lint/CommonLintGenerator.js +185 -185
- package/lib/generators/common/format-lint/updateEslintConfig.js +13 -13
- package/lib/generators/common/husky/CommonHuskyGenerator.js +44 -44
- package/lib/generators/common/old-dependencies/CommonRemoveOldDependenciesGenerator.js +44 -44
- package/lib/generators/common/release/CommonReleaseGenerator.js +40 -40
- package/lib/generators/common/testing/CommonTestingGenerator.js +190 -190
- package/lib/generators/common/testing/templates/index.js +3 -3
- package/lib/generators/common/transpiler/CommonTranspilerGenerator.js +163 -163
- package/lib/generators/common/typescript/CommonTypescriptGenerator.js +79 -79
- package/lib/generators/core/ci/CoreCIGenerator.js +72 -72
- package/lib/generators/core/clean/CoreCleanGenerator.js +4 -4
- package/lib/generators/core/editorconfig/CoreEditorConfigGenerator.js +3 -3
- package/lib/generators/core/git/CoreGitGenerator.js +43 -43
- package/lib/generators/core/git/generators/github/CoreGitGithubGenerator.js +43 -43
- package/lib/generators/core/gitignore/CoreGitignoreGenerator.js +19 -19
- package/lib/generators/core/npm/CoreNpmGenerator.js +20 -20
- package/lib/generators/core/package/CorePackageGenerator.js +98 -98
- package/lib/generators/core/package/askName.js +4 -4
- package/lib/generators/core/renovate/CoreRenovateGenerator.js +28 -28
- package/lib/generators/core/sort-package/CoreSortPackageGenerator.js +6 -6
- package/lib/generators/core/vscode/CoreVSCodeGenerator.js +43 -43
- package/lib/generators/core/yarn/CoreYarnGenerator.js +70 -70
- package/lib/generators/lib/PobLibGenerator.js +111 -111
- package/lib/generators/lib/doc/LibDocGenerator.js +45 -45
- package/lib/generators/lib/readme/LibReadmeGenerator.js +21 -21
- package/lib/generators/monorepo/PobMonorepoGenerator.js +89 -89
- package/lib/generators/monorepo/lerna/MonorepoLernaGenerator.js +47 -47
- package/lib/generators/monorepo/typescript/MonorepoTypescriptGenerator.js +38 -38
- package/lib/generators/monorepo/workspaces/MonorepoWorkspacesGenerator.js +57 -57
- package/lib/generators/pob/PobBaseGenerator.js +81 -81
- package/lib/pob-dirname.cjs +1 -1
- package/lib/pob.js +143 -143
- package/lib/utils/dependenciesPackages.cjs +4 -4
- package/lib/utils/ensureJsonFileFormatted.js +5 -5
- package/lib/utils/inMonorepo.js +8 -8
- package/lib/utils/json5.js +1 -1
- package/lib/utils/package.js +43 -43
- package/lib/utils/packagejson.cjs +2 -2
- package/lib/utils/templateUtils.js +1 -1
- package/lib/utils/writeAndFormat.js +9 -10
- package/package.json +7 -7
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { execSync } from
|
|
2
|
-
import fs from
|
|
3
|
-
import { platform } from
|
|
4
|
-
import { getPluginConfiguration } from
|
|
5
|
-
import { Configuration, Project } from
|
|
6
|
-
import { ppath } from
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { platform } from "node:process";
|
|
4
|
+
import { getPluginConfiguration } from "@yarnpkg/cli";
|
|
5
|
+
import { Configuration, Project } from "@yarnpkg/core";
|
|
6
|
+
import { ppath } from "@yarnpkg/fslib";
|
|
7
7
|
import {
|
|
8
8
|
buildTopologicalOrderBatches,
|
|
9
9
|
buildDependenciesMaps,
|
|
10
10
|
getWorkspaceName,
|
|
11
|
-
} from
|
|
12
|
-
import Generator from
|
|
13
|
-
import * as packageUtils from
|
|
14
|
-
import { copyAndFormatTpl } from
|
|
11
|
+
} from "yarn-workspace-utils";
|
|
12
|
+
import Generator from "yeoman-generator";
|
|
13
|
+
import * as packageUtils from "../../utils/package.js";
|
|
14
|
+
import { copyAndFormatTpl } from "../../utils/writeAndFormat.js";
|
|
15
15
|
|
|
16
16
|
export const createYarnProject = async () => {
|
|
17
17
|
const portablePath = ppath.cwd();
|
|
@@ -19,7 +19,7 @@ export const createYarnProject = async () => {
|
|
|
19
19
|
const configuration = await Configuration.find(
|
|
20
20
|
portablePath,
|
|
21
21
|
// eslint-disable-next-line unicorn/no-array-method-this-argument -- not an array
|
|
22
|
-
getPluginConfiguration()
|
|
22
|
+
getPluginConfiguration()
|
|
23
23
|
);
|
|
24
24
|
// eslint-disable-next-line unicorn/no-array-method-this-argument -- not an array
|
|
25
25
|
const { project } = await Project.find(configuration, portablePath);
|
|
@@ -28,7 +28,7 @@ export const createYarnProject = async () => {
|
|
|
28
28
|
|
|
29
29
|
const getAppTypes = (configs) => {
|
|
30
30
|
const appConfigs = configs.filter(
|
|
31
|
-
(config) => config && config.project && config.project.type ===
|
|
31
|
+
(config) => config && config.project && config.project.type === "app"
|
|
32
32
|
);
|
|
33
33
|
|
|
34
34
|
const appTypes = new Set();
|
|
@@ -42,12 +42,12 @@ const getAppTypes = (configs) => {
|
|
|
42
42
|
const hasDist = (packages, configs) =>
|
|
43
43
|
configs.some(
|
|
44
44
|
(config, index) =>
|
|
45
|
-
!!(config && config.project && config.project.type ===
|
|
45
|
+
!!(config && config.project && config.project.type === "lib") &&
|
|
46
46
|
!!(
|
|
47
47
|
packages[index].pob &&
|
|
48
48
|
packages[index].pob.babelEnvs &&
|
|
49
49
|
packages[index].pob.babelEnvs.length > 0
|
|
50
|
-
)
|
|
50
|
+
)
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
const hasBuild = (packages, configs) =>
|
|
@@ -56,53 +56,53 @@ const hasBuild = (packages, configs) =>
|
|
|
56
56
|
!!(
|
|
57
57
|
config &&
|
|
58
58
|
config.project &&
|
|
59
|
-
config.project.type ===
|
|
60
|
-
config.app.type ===
|
|
61
|
-
)
|
|
59
|
+
config.project.type === "app" &&
|
|
60
|
+
config.app.type === "alp-node"
|
|
61
|
+
)
|
|
62
62
|
);
|
|
63
63
|
|
|
64
64
|
export default class PobMonorepoGenerator extends Generator {
|
|
65
65
|
constructor(args, opts) {
|
|
66
66
|
super(args, opts);
|
|
67
67
|
|
|
68
|
-
this.option(
|
|
68
|
+
this.option("updateOnly", {
|
|
69
69
|
type: Boolean,
|
|
70
70
|
required: false,
|
|
71
71
|
default: false,
|
|
72
|
-
desc:
|
|
72
|
+
desc: "Avoid asking questions",
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
this.option(
|
|
75
|
+
this.option("isAppProject", {
|
|
76
76
|
type: Boolean,
|
|
77
77
|
required: false,
|
|
78
78
|
default: false,
|
|
79
|
-
desc:
|
|
79
|
+
desc: "app project, no pusblishing on npm",
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
this.option(
|
|
82
|
+
this.option("packageManager", {
|
|
83
83
|
type: String,
|
|
84
|
-
default:
|
|
85
|
-
desc:
|
|
84
|
+
default: "yarn",
|
|
85
|
+
desc: "yarn or npm",
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
this.option(
|
|
88
|
+
this.option("yarnNodeLinker", {
|
|
89
89
|
type: String,
|
|
90
90
|
required: false,
|
|
91
|
-
default:
|
|
92
|
-
desc:
|
|
91
|
+
default: "pnp",
|
|
92
|
+
desc: "Defines what linker should be used for installing Node packages (useful to enable the node-modules plugin), one of: pnp, node-modules.",
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
this.option(
|
|
95
|
+
this.option("onlyLatestLTS", {
|
|
96
96
|
type: Boolean,
|
|
97
97
|
required: true,
|
|
98
|
-
desc:
|
|
98
|
+
desc: "only latest lts",
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
this.option(
|
|
101
|
+
this.option("disableYarnGitCache", {
|
|
102
102
|
type: Boolean,
|
|
103
103
|
required: false,
|
|
104
104
|
default: false,
|
|
105
|
-
desc:
|
|
105
|
+
desc: "Disable git cache. See https://yarnpkg.com/features/caching#offline-mirror.",
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -110,7 +110,7 @@ export default class PobMonorepoGenerator extends Generator {
|
|
|
110
110
|
const yarnProject = await createYarnProject(this.destinationPath());
|
|
111
111
|
const batches = buildTopologicalOrderBatches(
|
|
112
112
|
yarnProject,
|
|
113
|
-
buildDependenciesMaps(yarnProject)
|
|
113
|
+
buildDependenciesMaps(yarnProject)
|
|
114
114
|
);
|
|
115
115
|
|
|
116
116
|
this.packages = [];
|
|
@@ -119,7 +119,7 @@ export default class PobMonorepoGenerator extends Generator {
|
|
|
119
119
|
for (const batch of batches) {
|
|
120
120
|
// sort by name to ensure consistent ordering
|
|
121
121
|
batch.sort((a, b) =>
|
|
122
|
-
getWorkspaceName(a).localeCompare(getWorkspaceName(b),
|
|
122
|
+
getWorkspaceName(a).localeCompare(getWorkspaceName(b), "en")
|
|
123
123
|
);
|
|
124
124
|
|
|
125
125
|
batch.forEach((workspace) => {
|
|
@@ -143,89 +143,89 @@ export default class PobMonorepoGenerator extends Generator {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
async prompting() {
|
|
146
|
-
const config = this.config.get(
|
|
146
|
+
const config = this.config.get("monorepo");
|
|
147
147
|
|
|
148
148
|
if (this.options.updateOnly && config) {
|
|
149
149
|
this.pobLernaConfig = config;
|
|
150
150
|
this.pobLernaConfig.packageNames = this.packageNames;
|
|
151
|
-
this.config.set(
|
|
151
|
+
this.config.set("monorepo", this.pobLernaConfig);
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
this.pobLernaConfig = await this.prompt([
|
|
156
156
|
{
|
|
157
|
-
type:
|
|
158
|
-
name:
|
|
159
|
-
message:
|
|
157
|
+
type: "confirm",
|
|
158
|
+
name: "ci",
|
|
159
|
+
message: "Would you like ci with github actions ?",
|
|
160
160
|
default: config
|
|
161
161
|
? config.ci
|
|
162
|
-
: this.fs.exists(this.destinationPath(
|
|
163
|
-
this.fs.exists(this.destinationPath(
|
|
162
|
+
: this.fs.exists(this.destinationPath(".circleci/config.yml")) ||
|
|
163
|
+
this.fs.exists(this.destinationPath(".github/workflows")),
|
|
164
164
|
},
|
|
165
165
|
{
|
|
166
|
-
type:
|
|
167
|
-
name:
|
|
168
|
-
message:
|
|
166
|
+
type: "confirm",
|
|
167
|
+
name: "testing",
|
|
168
|
+
message: "Would you like testing ?",
|
|
169
169
|
when: (answers) => answers.ci,
|
|
170
170
|
default: config ? config.testing : true,
|
|
171
171
|
},
|
|
172
172
|
{
|
|
173
|
-
type:
|
|
174
|
-
name:
|
|
175
|
-
message:
|
|
173
|
+
type: "confirm",
|
|
174
|
+
name: "codecov",
|
|
175
|
+
message: "Would you like code coverage ?",
|
|
176
176
|
when: (answers) => answers.ci && answers.testing,
|
|
177
177
|
default: config ? config.codecov : true,
|
|
178
178
|
},
|
|
179
179
|
{
|
|
180
|
-
type:
|
|
181
|
-
name:
|
|
182
|
-
message:
|
|
180
|
+
type: "confirm",
|
|
181
|
+
name: "documentation",
|
|
182
|
+
message: "Would you like documentation ?",
|
|
183
183
|
when: (answers) => answers.ci && !this.options.isAppProject,
|
|
184
184
|
default: config ? config.documentation : true,
|
|
185
185
|
},
|
|
186
186
|
{
|
|
187
|
-
type:
|
|
188
|
-
name:
|
|
189
|
-
message:
|
|
187
|
+
type: "confirm",
|
|
188
|
+
name: "typescript",
|
|
189
|
+
message: "Would you like typescript monorepo ?",
|
|
190
190
|
default: config ? config.typescript : true,
|
|
191
191
|
},
|
|
192
192
|
{
|
|
193
|
-
type:
|
|
194
|
-
name:
|
|
195
|
-
message:
|
|
193
|
+
type: "confirm",
|
|
194
|
+
name: "eslint",
|
|
195
|
+
message: "Would you like eslint in monorepo ?",
|
|
196
196
|
default: config ? config.eslint : true,
|
|
197
197
|
},
|
|
198
198
|
]);
|
|
199
199
|
this.pobLernaConfig.packageNames = this.packageNames;
|
|
200
|
-
this.config.set(
|
|
201
|
-
this.config.delete(
|
|
200
|
+
this.config.set("monorepo", this.pobLernaConfig);
|
|
201
|
+
this.config.delete("pob-config");
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
default() {
|
|
205
|
-
const pkg = this.fs.readJSON(this.destinationPath(
|
|
205
|
+
const pkg = this.fs.readJSON(this.destinationPath("package.json"), {});
|
|
206
206
|
|
|
207
207
|
const packageNames = this.packageNames;
|
|
208
208
|
const packagePaths = this.packageLocations.filter(
|
|
209
209
|
this.pobLernaConfig.typescript
|
|
210
210
|
? (packagePath) => fs.existsSync(`${packagePath}/tsconfig.json`)
|
|
211
|
-
: Boolean
|
|
211
|
+
: Boolean
|
|
212
212
|
);
|
|
213
213
|
|
|
214
214
|
if (packagePaths.length === 0 && packageNames.length > 0) {
|
|
215
215
|
console.log(packageNames, packagePaths);
|
|
216
|
-
throw new Error(
|
|
216
|
+
throw new Error("packages should not be empty");
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
this.composeWith(
|
|
219
|
+
this.composeWith("pob:common:husky", {});
|
|
220
220
|
|
|
221
221
|
const isYarnVersionEnabled = this.pobLernaConfig.ci;
|
|
222
222
|
|
|
223
223
|
const splitCIJobs = this.packageNames.length > 8;
|
|
224
224
|
|
|
225
|
-
this.composeWith(
|
|
225
|
+
this.composeWith("pob:common:testing", {
|
|
226
226
|
monorepo: true,
|
|
227
227
|
enable: this.pobLernaConfig.testing,
|
|
228
|
-
runner: this.pobLernaConfig.testRunner ||
|
|
228
|
+
runner: this.pobLernaConfig.testRunner || "jest",
|
|
229
229
|
disableYarnGitCache: this.options.disableYarnGitCache,
|
|
230
230
|
enableReleasePlease: false,
|
|
231
231
|
enableYarnVersion: isYarnVersionEnabled,
|
|
@@ -242,7 +242,7 @@ export default class PobMonorepoGenerator extends Generator {
|
|
|
242
242
|
splitCIJobs,
|
|
243
243
|
});
|
|
244
244
|
|
|
245
|
-
this.composeWith(
|
|
245
|
+
this.composeWith("pob:common:format-lint", {
|
|
246
246
|
monorepo: true,
|
|
247
247
|
documentation: this.pobLernaConfig.documentation,
|
|
248
248
|
typescript: this.pobLernaConfig.typescript,
|
|
@@ -252,15 +252,15 @@ export default class PobMonorepoGenerator extends Generator {
|
|
|
252
252
|
yarnNodeLinker: this.options.yarnNodeLinker,
|
|
253
253
|
appTypes: JSON.stringify(getAppTypes(this.packageConfigs)),
|
|
254
254
|
ignorePaths: [
|
|
255
|
-
hasDist(this.packages, this.packageConfigs) &&
|
|
256
|
-
hasBuild(this.packages, this.packageConfigs) &&
|
|
255
|
+
hasDist(this.packages, this.packageConfigs) && "/dist",
|
|
256
|
+
hasBuild(this.packages, this.packageConfigs) && "/build",
|
|
257
257
|
]
|
|
258
258
|
.filter(Boolean)
|
|
259
|
-
.join(
|
|
259
|
+
.join("\n"),
|
|
260
260
|
rootIgnorePaths: [],
|
|
261
261
|
});
|
|
262
262
|
|
|
263
|
-
this.composeWith(
|
|
263
|
+
this.composeWith("pob:lib:doc", {
|
|
264
264
|
enabled: this.pobLernaConfig.documentation,
|
|
265
265
|
testing: this.pobLernaConfig.testing,
|
|
266
266
|
packageNames: JSON.stringify(packageNames),
|
|
@@ -268,7 +268,7 @@ export default class PobMonorepoGenerator extends Generator {
|
|
|
268
268
|
packageManager: this.options.packageManager,
|
|
269
269
|
});
|
|
270
270
|
|
|
271
|
-
this.composeWith(
|
|
271
|
+
this.composeWith("pob:core:vscode", {
|
|
272
272
|
root: true,
|
|
273
273
|
monorepo: true,
|
|
274
274
|
packageManager: this.options.packageManager,
|
|
@@ -281,16 +281,16 @@ export default class PobMonorepoGenerator extends Generator {
|
|
|
281
281
|
});
|
|
282
282
|
|
|
283
283
|
// Always add a gitignore, because npm publish uses it.
|
|
284
|
-
this.composeWith(
|
|
284
|
+
this.composeWith("pob:core:gitignore", {
|
|
285
285
|
root: true,
|
|
286
286
|
typescript: this.pobLernaConfig.typescript,
|
|
287
287
|
documentation: this.pobLernaConfig.documentation,
|
|
288
288
|
testing: this.pobLernaConfig.testing,
|
|
289
289
|
});
|
|
290
290
|
|
|
291
|
-
this.composeWith(
|
|
291
|
+
this.composeWith("pob:common:remove-old-dependencies");
|
|
292
292
|
|
|
293
|
-
this.composeWith(
|
|
293
|
+
this.composeWith("pob:common:release", {
|
|
294
294
|
enable: true,
|
|
295
295
|
enablePublish: !this.options.isAppProject,
|
|
296
296
|
withBabel: this.pobLernaConfig.typescript,
|
|
@@ -301,7 +301,7 @@ export default class PobMonorepoGenerator extends Generator {
|
|
|
301
301
|
updateOnly: this.options.updateOnly,
|
|
302
302
|
});
|
|
303
303
|
|
|
304
|
-
this.composeWith(
|
|
304
|
+
this.composeWith("pob:monorepo:typescript", {
|
|
305
305
|
enable: this.pobLernaConfig.typescript,
|
|
306
306
|
isAppProject: this.options.isAppProject,
|
|
307
307
|
packageNames: JSON.stringify(packageNames),
|
|
@@ -309,18 +309,18 @@ export default class PobMonorepoGenerator extends Generator {
|
|
|
309
309
|
testRunner: this.pobLernaConfig.testRunner,
|
|
310
310
|
});
|
|
311
311
|
|
|
312
|
-
this.fs.writeJSON(this.destinationPath(
|
|
312
|
+
this.fs.writeJSON(this.destinationPath("package.json"), pkg);
|
|
313
313
|
|
|
314
|
-
if (platform !==
|
|
314
|
+
if (platform !== "win32") {
|
|
315
315
|
execSync(
|
|
316
|
-
`rm -Rf ${[
|
|
316
|
+
`rm -Rf ${["lib-*", "coverage", "docs"].filter(Boolean).join(" ")}`
|
|
317
317
|
);
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
writing() {
|
|
322
322
|
if (!this.options.isAppProject) {
|
|
323
|
-
const pkg = this.fs.readJSON(this.destinationPath(
|
|
323
|
+
const pkg = this.fs.readJSON(this.destinationPath("package.json"), {});
|
|
324
324
|
|
|
325
325
|
const rollupConfigs = [];
|
|
326
326
|
this.packageLocations.forEach((location) => {
|
|
@@ -336,32 +336,32 @@ export default class PobMonorepoGenerator extends Generator {
|
|
|
336
336
|
if (rollupConfigs.length > 0) {
|
|
337
337
|
copyAndFormatTpl(
|
|
338
338
|
this.fs,
|
|
339
|
-
this.templatePath(
|
|
340
|
-
this.destinationPath(
|
|
339
|
+
this.templatePath("monorepo.rollup.config.mjs.ejs"),
|
|
340
|
+
this.destinationPath("rollup.config.mjs"),
|
|
341
341
|
{
|
|
342
342
|
configLocations: rollupConfigs,
|
|
343
|
-
}
|
|
343
|
+
}
|
|
344
344
|
);
|
|
345
345
|
} else {
|
|
346
|
-
this.fs.delete(
|
|
346
|
+
this.fs.delete("rollup.config.mjs");
|
|
347
347
|
}
|
|
348
348
|
packageUtils.addOrRemoveScripts(pkg, rollupConfigs.length > 0, {
|
|
349
|
-
|
|
350
|
-
build:
|
|
351
|
-
watch:
|
|
349
|
+
"clean:build": "yarn workspaces foreach --parallel -A run clean:build",
|
|
350
|
+
build: "yarn clean:build && rollup --config rollup.config.mjs",
|
|
351
|
+
watch: "yarn clean:build && rollup --config rollup.config.mjs --watch",
|
|
352
352
|
});
|
|
353
353
|
packageUtils.addOrRemoveDevDependencies(pkg, rollupConfigs.length, [
|
|
354
|
-
|
|
355
|
-
|
|
354
|
+
"@babel/core",
|
|
355
|
+
"pob-babel",
|
|
356
356
|
]);
|
|
357
|
-
this.fs.writeJSON(this.destinationPath(
|
|
357
|
+
this.fs.writeJSON(this.destinationPath("package.json"), pkg);
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
-
this.composeWith(
|
|
360
|
+
this.composeWith("pob:core:sort-package");
|
|
361
361
|
}
|
|
362
362
|
|
|
363
363
|
end() {
|
|
364
|
-
console.log(
|
|
364
|
+
console.log("save config");
|
|
365
365
|
this.config.save();
|
|
366
366
|
}
|
|
367
367
|
}
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { readdirSync, existsSync } from
|
|
2
|
-
import Generator from
|
|
3
|
-
import * as packageUtils from
|
|
4
|
-
import { writeAndFormatJson } from
|
|
1
|
+
import { readdirSync, existsSync } from "node:fs";
|
|
2
|
+
import Generator from "yeoman-generator";
|
|
3
|
+
import * as packageUtils from "../../../utils/package.js";
|
|
4
|
+
import { writeAndFormatJson } from "../../../utils/writeAndFormat.js";
|
|
5
5
|
|
|
6
6
|
export default class MonorepoLernaGenerator extends Generator {
|
|
7
7
|
constructor(args, opts) {
|
|
8
8
|
super(args, opts);
|
|
9
9
|
|
|
10
|
-
this.option(
|
|
10
|
+
this.option("isAppProject", {
|
|
11
11
|
type: Boolean,
|
|
12
12
|
default: true,
|
|
13
|
-
desc:
|
|
13
|
+
desc: "is app project",
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
this.option(
|
|
16
|
+
this.option("packageManager", {
|
|
17
17
|
type: String,
|
|
18
|
-
default:
|
|
19
|
-
desc:
|
|
18
|
+
default: "yarn",
|
|
19
|
+
desc: "yarn or npm",
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
this.option(
|
|
22
|
+
this.option("disableYarnGitCache", {
|
|
23
23
|
type: Boolean,
|
|
24
24
|
required: false,
|
|
25
25
|
default: false,
|
|
26
|
-
desc:
|
|
26
|
+
desc: "Disable git cache. See https://yarnpkg.com/features/caching#offline-mirror.",
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// TODO pass packages as options ?
|
|
31
31
|
initializing() {
|
|
32
|
-
const pkg = this.fs.readJSON(this.destinationPath(
|
|
32
|
+
const pkg = this.fs.readJSON(this.destinationPath("package.json"), {});
|
|
33
33
|
const packagesPaths = pkg.workspaces
|
|
34
|
-
? pkg.workspaces.map((workspace) => workspace.replace(/\/\*$/,
|
|
35
|
-
: [
|
|
34
|
+
? pkg.workspaces.map((workspace) => workspace.replace(/\/\*$/, ""))
|
|
35
|
+
: ["packages"];
|
|
36
36
|
|
|
37
37
|
this.packagePaths = packagesPaths.flatMap((packagesPath) =>
|
|
38
38
|
existsSync(`${packagesPath}/`)
|
|
39
39
|
? readdirSync(`${packagesPath}/`).map(
|
|
40
|
-
(packageName) => `${packagesPath}/${packageName}
|
|
40
|
+
(packageName) => `${packagesPath}/${packageName}`
|
|
41
41
|
)
|
|
42
|
-
: []
|
|
42
|
+
: []
|
|
43
43
|
);
|
|
44
44
|
this.packages = this.packagePaths
|
|
45
45
|
.map((packagePath) =>
|
|
46
|
-
this.fs.readJSON(this.destinationPath(`${packagePath}/package.json`))
|
|
46
|
+
this.fs.readJSON(this.destinationPath(`${packagePath}/package.json`))
|
|
47
47
|
)
|
|
48
48
|
.filter(Boolean);
|
|
49
49
|
this.packagesConfig = this.packagePaths
|
|
50
50
|
.map((packagePath) =>
|
|
51
|
-
this.fs.readJSON(this.destinationPath(`${packagePath}/.yo-rc.json`))
|
|
51
|
+
this.fs.readJSON(this.destinationPath(`${packagePath}/.yo-rc.json`))
|
|
52
52
|
)
|
|
53
53
|
.filter(Boolean);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
default() {
|
|
57
|
-
const pkg = this.fs.readJSON(this.destinationPath(
|
|
57
|
+
const pkg = this.fs.readJSON(this.destinationPath("package.json"), {});
|
|
58
58
|
|
|
59
59
|
const lernaCurrentConfig = this.fs.readJSON(
|
|
60
|
-
this.destinationPath(
|
|
61
|
-
pkg.lerna || {}
|
|
60
|
+
this.destinationPath("lerna.json"),
|
|
61
|
+
pkg.lerna || {}
|
|
62
62
|
);
|
|
63
63
|
|
|
64
64
|
this.npm =
|
|
65
|
-
lernaCurrentConfig.version && lernaCurrentConfig.npmClient !==
|
|
65
|
+
lernaCurrentConfig.version && lernaCurrentConfig.npmClient !== "yarn";
|
|
66
66
|
|
|
67
67
|
// lerna.json
|
|
68
68
|
const lernaConfig = this.npm
|
|
69
69
|
? {
|
|
70
|
-
version:
|
|
70
|
+
version: "independent",
|
|
71
71
|
}
|
|
72
72
|
: {
|
|
73
|
-
version: lernaCurrentConfig.version ||
|
|
74
|
-
npmClient:
|
|
73
|
+
version: lernaCurrentConfig.version || "independent",
|
|
74
|
+
npmClient: "yarn",
|
|
75
75
|
useWorkspaces: true,
|
|
76
76
|
};
|
|
77
77
|
|
|
@@ -87,17 +87,17 @@ export default class MonorepoLernaGenerator extends Generator {
|
|
|
87
87
|
|
|
88
88
|
writeAndFormatJson(
|
|
89
89
|
this.fs,
|
|
90
|
-
this.destinationPath(
|
|
91
|
-
lernaConfig
|
|
90
|
+
this.destinationPath("lerna.json"),
|
|
91
|
+
lernaConfig
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
writing() {
|
|
96
96
|
// package.json
|
|
97
|
-
const pkg = this.fs.readJSON(this.destinationPath(
|
|
97
|
+
const pkg = this.fs.readJSON(this.destinationPath("package.json"), {});
|
|
98
98
|
delete pkg.lerna;
|
|
99
|
-
packageUtils.removeDependencies(pkg, [
|
|
100
|
-
packageUtils.removeDevDependencies(pkg, [
|
|
99
|
+
packageUtils.removeDependencies(pkg, ["lerna"]);
|
|
100
|
+
packageUtils.removeDevDependencies(pkg, ["lerna"]);
|
|
101
101
|
|
|
102
102
|
// TODO remove lerna completely
|
|
103
103
|
const isYarnVersionEnabled = true;
|
|
@@ -107,55 +107,55 @@ export default class MonorepoLernaGenerator extends Generator {
|
|
|
107
107
|
...(config && config.pob),
|
|
108
108
|
});
|
|
109
109
|
const withBabel = this.packages.some(
|
|
110
|
-
(config) => getPackagePobConfig(config).babelEnvs.length > 0
|
|
110
|
+
(config) => getPackagePobConfig(config).babelEnvs.length > 0
|
|
111
111
|
);
|
|
112
112
|
|
|
113
113
|
// lerna.json
|
|
114
114
|
const lernaConfig = this.fs.readJSON(
|
|
115
|
-
this.destinationPath(
|
|
116
|
-
{}
|
|
115
|
+
this.destinationPath("lerna.json"),
|
|
116
|
+
{}
|
|
117
117
|
);
|
|
118
118
|
|
|
119
119
|
// TODO pass that to yarn plugin
|
|
120
120
|
lernaConfig.command.publish.ignoreChanges = [
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
"**/.yo-rc.json",
|
|
122
|
+
"**/.eslintrc.json",
|
|
123
123
|
];
|
|
124
124
|
|
|
125
125
|
if (withBabel) {
|
|
126
|
-
lernaConfig.command.publish.ignoreChanges.push(
|
|
126
|
+
lernaConfig.command.publish.ignoreChanges.push("**/tsconfig.json");
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
if (isYarnVersionEnabled) {
|
|
130
|
-
if (pkg.version ===
|
|
131
|
-
if (lernaConfig.version ===
|
|
130
|
+
if (pkg.version === "0.0.0" && lernaConfig && lernaConfig.version) {
|
|
131
|
+
if (lernaConfig.version === "independent") {
|
|
132
132
|
delete pkg.version;
|
|
133
133
|
} else {
|
|
134
134
|
pkg.version = lernaConfig.version;
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
this.fs.delete(this.destinationPath(
|
|
137
|
+
this.fs.delete(this.destinationPath("lerna.json"));
|
|
138
138
|
} else {
|
|
139
139
|
writeAndFormatJson(
|
|
140
140
|
this.fs,
|
|
141
|
-
this.destinationPath(
|
|
142
|
-
lernaConfig
|
|
141
|
+
this.destinationPath("lerna.json"),
|
|
142
|
+
lernaConfig
|
|
143
143
|
);
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
if (this.fs.exists(this.destinationPath(
|
|
147
|
-
this.fs.delete(this.destinationPath(
|
|
146
|
+
if (this.fs.exists(this.destinationPath("lerna-debug.log"))) {
|
|
147
|
+
this.fs.delete(this.destinationPath("lerna-debug.log"));
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
packageUtils.addOrRemoveScripts(
|
|
151
151
|
pkg,
|
|
152
|
-
this.options.packageManager ===
|
|
152
|
+
this.options.packageManager === "yarn" && !isYarnVersionEnabled,
|
|
153
153
|
{
|
|
154
154
|
version:
|
|
155
|
-
|
|
156
|
-
}
|
|
155
|
+
"YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn && git add yarn.lock",
|
|
156
|
+
}
|
|
157
157
|
);
|
|
158
158
|
|
|
159
|
-
this.fs.writeJSON(this.destinationPath(
|
|
159
|
+
this.fs.writeJSON(this.destinationPath("package.json"), pkg);
|
|
160
160
|
}
|
|
161
161
|
}
|