@next-core/yo 1.6.2 → 1.6.4

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.6.2",
3
+ "version": "1.6.4",
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",
@@ -26,7 +26,7 @@
26
26
  "plop": "^4.0.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@next-core/build-next-bricks": "^1.24.0",
29
+ "@next-core/build-next-bricks": "^1.25.0",
30
30
  "@next-core/build-next-libs": "^1.0.25",
31
31
  "@next-core/element": "^1.2.19",
32
32
  "@next-core/i18n": "^1.0.87",
@@ -35,5 +35,5 @@
35
35
  "@next-core/theme": "^1.6.1",
36
36
  "react": "0.0.0-experimental-ee8509801-20230117"
37
37
  },
38
- "gitHead": "30de503f4f8d9eea764201203c5049ec45f65733"
38
+ "gitHead": "b82dcf1b907a7238cb888454a9e86a0687ae019f"
39
39
  }
package/src/plopfile.js CHANGED
@@ -314,6 +314,62 @@ export default function (
314
314
  path: "bricks/{{pkgName}}/docs/{{>lastTagName}}.md",
315
315
  templateFile: "templates/brick.md.hbs",
316
316
  },
317
+ async function updateJsxDts(answers) {
318
+ const jsxDtsFile = path.join(
319
+ bricksDir,
320
+ answers.pkgName,
321
+ "src/jsx.d.ts"
322
+ );
323
+ /** @type {string} */
324
+ let jsxDtsContent;
325
+ if (!existsSync(jsxDtsFile)) {
326
+ // jsxDtsContent = `import type { DetailedHTMLProps, HTMLAttributes } from "react"`;
327
+ const jsxDtsTemplateFile = path.join(
328
+ __dirname,
329
+ "templates/bricks/src/jsx.d.ts.hbs"
330
+ );
331
+ jsxDtsContent = await readFile(jsxDtsTemplateFile, "utf-8");
332
+ } else {
333
+ jsxDtsContent = await readFile(jsxDtsFile, "utf-8");
334
+ }
335
+ const tagName = plop.renderString(
336
+ "{{getTagName brickType pkgName brickName false false}}",
337
+ answers
338
+ );
339
+ const className = plop.renderString(
340
+ "{{pascalCase (getTagName brickType pkgName brickName true true)}}",
341
+ answers
342
+ );
343
+ const propName = `${className}Props`;
344
+ const importStatement = `import type { ${className}, ${propName} } from "./${answers.brickName}";`;
345
+ const definitionProp = ` "${tagName.replaceAll(".", "--")}": DetailedHTMLProps<HTMLAttributes<${className}>, ${className}> & ${propName};`;
346
+
347
+ /** @type {[RegExp, string][]} */
348
+ const replacementPatterns = [
349
+ [
350
+ /(\r?\n)(\r?\n)?(declare global )/,
351
+ `$1${importStatement}$1$2$3`,
352
+ ],
353
+ [
354
+ // eslint-disable-next-line no-regex-spaces
355
+ /(\r?\n)( \}\r?\n \}\r?\n\}\r?\n)$/,
356
+ `$1${definitionProp}$1$2`,
357
+ ],
358
+ ];
359
+
360
+ for (const [pattern, replacement] of replacementPatterns) {
361
+ const newJsxDts = jsxDtsContent.replace(pattern, replacement);
362
+ if (newJsxDts === jsxDtsContent) {
363
+ throw new Error(
364
+ `Failed to add definition in jsx.d.ts for ${tagName}.`
365
+ );
366
+ }
367
+ jsxDtsContent = newJsxDts;
368
+ }
369
+
370
+ await writeFile(jsxDtsFile, jsxDtsContent);
371
+ return `Updated jsx.d.ts to include ${tagName} definition.`;
372
+ },
317
373
  async function modifyCommonBricksJson(answers) {
318
374
  if (answers.brickType === "common") {
319
375
  const realBrickName = `eo-${answers.brickName}`;
@@ -11,10 +11,12 @@
11
11
  "dist-types",
12
12
  "docs"
13
13
  ],
14
+ "types": "dist-types/jsx.d.ts",
14
15
  "exports": {
15
16
  "./package.json": "./package.json",
16
17
  "./dist/bricks.json": "./dist/bricks.json",
17
18
  "./dist/manifest.json": "./dist/manifest.json",
19
+ ".": "./dist-types/jsx.d.ts",
18
20
  "./*": {
19
21
  "types": "./dist-types/*/index.d.ts"
20
22
  }
@@ -23,7 +25,7 @@
23
25
  "start": "cross-env NODE_ENV=development build-next-bricks --watch",
24
26
  "build": "npm run build:main && npm run build:types",
25
27
  "build:main": "cross-env NODE_ENV=production build-next-bricks",
26
- "build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist-types --project tsconfig.json",
28
+ "build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist-types --project tsconfig.json && copy-jsx-d-ts",
27
29
  "build:manifest": "cross-env NODE_ENV=production build-next-bricks --manifest-only",
28
30
  "test": "cross-env NODE_ENV='test' test-next",
29
31
  "test:ci": "cross-env NODE_ENV='test' CI=true test-next",
@@ -0,0 +1,9 @@
1
+ import type { DetailedHTMLProps, HTMLAttributes } from "react";
2
+
3
+ declare global {
4
+ namespace JSX {
5
+ interface IntrinsicElements {
6
+ // Extend with brick definitions here
7
+ }
8
+ }
9
+ }