@next-core/yo 1.2.7 → 1.4.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/yo",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Generator for next v3",
|
|
5
5
|
"homepage": "https://github.com/easyops-cn/next-core/tree/v3/packages/yo",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"plop": "^3.1.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@next-core/build-next-bricks": "^1.
|
|
27
|
+
"@next-core/build-next-bricks": "^1.13.0",
|
|
28
28
|
"@next-core/build-next-libs": "^1.0.5",
|
|
29
|
-
"@next-core/element": "^1.0
|
|
29
|
+
"@next-core/element": "^1.1.0",
|
|
30
30
|
"@next-core/i18n": "^1.0.21",
|
|
31
|
-
"@next-core/react-element": "^1.0.
|
|
31
|
+
"@next-core/react-element": "^1.0.8",
|
|
32
32
|
"@next-core/test-next": "^1.0.6",
|
|
33
33
|
"@next-core/theme": "^1.1.1",
|
|
34
34
|
"react": "0.0.0-experimental-ee8509801-20230117"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "06fca79a3a3b63a995d92729cfbed8e312cfdccd"
|
|
37
37
|
}
|
package/src/plopfile.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import { readFile, readdir } from "node:fs/promises";
|
|
3
|
+
import { readFile, readdir, writeFile } from "node:fs/promises";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
6
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -64,6 +64,25 @@ export default function (
|
|
|
64
64
|
"libDevDependencies",
|
|
65
65
|
getObjectPartialInPackageJson(libDevDependencies)
|
|
66
66
|
);
|
|
67
|
+
plop.setHelper("getTagName", (brickType, pkgName, brickName, lastNameOnly) =>
|
|
68
|
+
brickType === "common"
|
|
69
|
+
? `eo-${brickName}`
|
|
70
|
+
: lastNameOnly
|
|
71
|
+
? brickName
|
|
72
|
+
: `${pkgName}.${brickName}`
|
|
73
|
+
);
|
|
74
|
+
plop.setPartial(
|
|
75
|
+
"tagName",
|
|
76
|
+
"{{getTagName brickType pkgName brickName false}}"
|
|
77
|
+
);
|
|
78
|
+
plop.setPartial(
|
|
79
|
+
"lastTagName",
|
|
80
|
+
"{{getTagName brickType pkgName brickName true}}"
|
|
81
|
+
);
|
|
82
|
+
plop.setPartial(
|
|
83
|
+
"className",
|
|
84
|
+
"{{pascalCase (getTagName brickType pkgName brickName true)}}"
|
|
85
|
+
);
|
|
67
86
|
|
|
68
87
|
// create your generators here
|
|
69
88
|
plop.setGenerator("basics", {
|
|
@@ -153,6 +172,24 @@ export default function (
|
|
|
153
172
|
return true;
|
|
154
173
|
},
|
|
155
174
|
},
|
|
175
|
+
{
|
|
176
|
+
type: "list",
|
|
177
|
+
name: "brickType",
|
|
178
|
+
message: "Select your brick type:",
|
|
179
|
+
when(data) {
|
|
180
|
+
return data.type === "brick";
|
|
181
|
+
},
|
|
182
|
+
choices: [
|
|
183
|
+
{
|
|
184
|
+
name: "Business-specific brick (starts with namespace)",
|
|
185
|
+
value: "specific",
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: "Common brick (starts with `eo-`, no namespace)",
|
|
189
|
+
value: "common",
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
},
|
|
156
193
|
{
|
|
157
194
|
type: "input",
|
|
158
195
|
name: "brickName",
|
|
@@ -160,17 +197,41 @@ export default function (
|
|
|
160
197
|
when(data) {
|
|
161
198
|
return data.type === "brick";
|
|
162
199
|
},
|
|
163
|
-
validate(value, data) {
|
|
164
|
-
|
|
200
|
+
async validate(value, data) {
|
|
201
|
+
const realBrickName =
|
|
202
|
+
data.brickType === "common" ? `eo-${value}` : value;
|
|
203
|
+
if (!validBrickName.test(realBrickName)) {
|
|
165
204
|
return "Please enter a lower-kebab-case brick name.";
|
|
166
205
|
}
|
|
167
206
|
|
|
168
207
|
if (existsSync(path.join(bricksDir, data.pkgName, "src", value))) {
|
|
169
|
-
return `Brick "${
|
|
208
|
+
return `Brick "${realBrickName}" seems to be existed, please enter another name.`;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const commonBricksJsonFile = path.join(
|
|
212
|
+
rootDir,
|
|
213
|
+
"shared/common-bricks/common-bricks.json"
|
|
214
|
+
);
|
|
215
|
+
if (data.brickType === "common" && existsSync(commonBricksJsonFile)) {
|
|
216
|
+
const commonBricksJson = JSON.parse(
|
|
217
|
+
await readFile(commonBricksJsonFile, "utf-8")
|
|
218
|
+
);
|
|
219
|
+
for (const [pkg, commonBricks] of Object.entries(
|
|
220
|
+
commonBricksJson
|
|
221
|
+
)) {
|
|
222
|
+
if (commonBricks.includes(realBrickName)) {
|
|
223
|
+
return `Brick "${realBrickName}" existed in package "${pkg}", please enter another name.`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
170
226
|
}
|
|
171
227
|
|
|
172
228
|
return true;
|
|
173
229
|
},
|
|
230
|
+
transformer(input, data) {
|
|
231
|
+
return data.brickType === "common"
|
|
232
|
+
? `eo-${input}`
|
|
233
|
+
: `${data.pkgName}.${input}`;
|
|
234
|
+
},
|
|
174
235
|
},
|
|
175
236
|
{
|
|
176
237
|
type: "input",
|
|
@@ -199,6 +260,9 @@ export default function (
|
|
|
199
260
|
|
|
200
261
|
return true;
|
|
201
262
|
},
|
|
263
|
+
transformer(input, data) {
|
|
264
|
+
return `${data.pkgName}.${input}`;
|
|
265
|
+
},
|
|
202
266
|
},
|
|
203
267
|
],
|
|
204
268
|
actions(data) {
|
|
@@ -218,9 +282,49 @@ export default function (
|
|
|
218
282
|
},
|
|
219
283
|
{
|
|
220
284
|
type: "add",
|
|
221
|
-
path: "bricks/{{pkgName}}/docs/{{
|
|
285
|
+
path: "bricks/{{pkgName}}/docs/{{>lastTagName}}.md",
|
|
222
286
|
templateFile: "templates/brick.md.hbs",
|
|
223
287
|
},
|
|
288
|
+
async function modifyCommonBricksJson(answers) {
|
|
289
|
+
if (answers.brickType === "common") {
|
|
290
|
+
const realBrickName = `eo-${answers.brickName}`;
|
|
291
|
+
const commonBricksJsonFile = path.join(
|
|
292
|
+
rootDir,
|
|
293
|
+
"shared/common-bricks/common-bricks.json"
|
|
294
|
+
);
|
|
295
|
+
/** @type {Record<string, string[]>} */
|
|
296
|
+
let commonBricksJson;
|
|
297
|
+
/** @type {string[]} */
|
|
298
|
+
let commonBricks;
|
|
299
|
+
if (existsSync(commonBricksJsonFile)) {
|
|
300
|
+
commonBricksJson = JSON.parse(
|
|
301
|
+
await readFile(commonBricksJsonFile, "utf-8")
|
|
302
|
+
);
|
|
303
|
+
if (
|
|
304
|
+
Object.prototype.hasOwnProperty.call(
|
|
305
|
+
commonBricksJson,
|
|
306
|
+
answers.pkgName
|
|
307
|
+
)
|
|
308
|
+
) {
|
|
309
|
+
commonBricks = commonBricksJson[answers.pkgName];
|
|
310
|
+
} else {
|
|
311
|
+
commonBricks = commonBricksJson[answers.pkgName] = [];
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
commonBricksJson = {};
|
|
315
|
+
commonBricks = commonBricksJson[answers.pkgName] = [];
|
|
316
|
+
}
|
|
317
|
+
commonBricks.push(realBrickName);
|
|
318
|
+
await writeFile(
|
|
319
|
+
commonBricksJsonFile,
|
|
320
|
+
JSON.stringify(commonBricksJson, null, 2)
|
|
321
|
+
);
|
|
322
|
+
return plop.renderString(
|
|
323
|
+
`added {{pkgName}}: ${realBrickName} in /shared/common-bricks/common-bricks.json`,
|
|
324
|
+
answers
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
},
|
|
224
328
|
];
|
|
225
329
|
} else if (data.type === "provider") {
|
|
226
330
|
return [
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { describe, test, expect, jest } from "@jest/globals";
|
|
2
2
|
import { act } from "react-dom/test-utils";
|
|
3
3
|
import "./";
|
|
4
|
-
import { {{
|
|
4
|
+
import { {{>className}} } from "./index.js";
|
|
5
5
|
|
|
6
6
|
jest.mock("@next-core/theme", () => ({}));
|
|
7
7
|
|
|
8
|
-
describe("{{
|
|
8
|
+
describe("{{>tagName}}", () => {
|
|
9
9
|
test("basic usage", async () => {
|
|
10
|
-
const element = document.createElement("{{
|
|
10
|
+
const element = document.createElement("{{>tagName}}") as {{>className}};
|
|
11
11
|
|
|
12
12
|
expect(element.shadowRoot).toBeFalsy();
|
|
13
13
|
|
|
@@ -12,21 +12,21 @@ import styleText from "./styles.shadow.css";
|
|
|
12
12
|
const { defineElement, property } = createDecorators();
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* 构件 {{
|
|
15
|
+
* 构件 `{{>tagName}}`
|
|
16
16
|
*/
|
|
17
17
|
export
|
|
18
|
-
@defineElement("{{
|
|
18
|
+
@defineElement("{{>tagName}}", {
|
|
19
19
|
styleTexts: [styleText],
|
|
20
20
|
})
|
|
21
|
-
class {{
|
|
21
|
+
class {{>className}} extends ReactNextElement {
|
|
22
22
|
render() {
|
|
23
23
|
return (
|
|
24
|
-
<{{
|
|
24
|
+
<{{>className}}Component />
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export function {{
|
|
29
|
+
export function {{>className}}Component() {
|
|
30
30
|
// const { t } = useTranslation(NS);
|
|
31
31
|
// const hello = t(K.HELLO);
|
|
32
32
|
return <div>It works!</div>;
|