@next-core/build-next-bricks 1.17.0 → 1.19.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/bin/build-next-bricks.js +2 -0
- package/package.json +2 -2
- package/src/EmitBricksJsonPlugin.js +3 -0
- package/src/build.js +43 -4
- package/src/buildStories.js +90 -0
package/bin/build-next-bricks.js
CHANGED
|
@@ -4,6 +4,7 @@ import { existsSync } from "node:fs";
|
|
|
4
4
|
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
import build from "../src/build.js";
|
|
7
|
+
import buildStories from "../src/buildStories.js";
|
|
7
8
|
import scanBricks from "../src/scanBricks.js";
|
|
8
9
|
import generatePkgBuild from "../src/generatePkgBuild.js";
|
|
9
10
|
|
|
@@ -100,6 +101,7 @@ try {
|
|
|
100
101
|
if (
|
|
101
102
|
configList.some((config) => !config.type || config.type === "bricks")
|
|
102
103
|
) {
|
|
104
|
+
await buildStories(packageDir);
|
|
103
105
|
await generatePkgBuild(packageDir);
|
|
104
106
|
}
|
|
105
107
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/build-next-bricks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "Build next bricks",
|
|
5
5
|
"homepage": "https://github.com/easyops-cn/next-core/tree/v3/packages/build-next-bricks",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@next-core/brick-manifest": "^0.7.0"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "442a43ffcd1065b2c42463f85a3361b4f4e77a37"
|
|
60
60
|
}
|
|
@@ -19,6 +19,7 @@ export default class EmitBricksJsonPlugin {
|
|
|
19
19
|
this.manifest = options.manifest;
|
|
20
20
|
this.types = options.types;
|
|
21
21
|
this.examples = options.examples;
|
|
22
|
+
this.deprecatedElements = options.deprecatedElements;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -57,6 +58,7 @@ export default class EmitBricksJsonPlugin {
|
|
|
57
58
|
processors: this.processors,
|
|
58
59
|
dependencies: this.dependencies,
|
|
59
60
|
filePath: jsFilePath,
|
|
61
|
+
deprecatedElements: this.deprecatedElements,
|
|
60
62
|
},
|
|
61
63
|
null,
|
|
62
64
|
2
|
|
@@ -89,6 +91,7 @@ export default class EmitBricksJsonPlugin {
|
|
|
89
91
|
console.log("Defined elements:", this.elements);
|
|
90
92
|
console.log("Defined processors:", this.processors);
|
|
91
93
|
console.log("Found dependencies:", this.dependencies);
|
|
94
|
+
console.log("Found deprecated elements:", this.deprecatedElements);
|
|
92
95
|
callback();
|
|
93
96
|
}
|
|
94
97
|
);
|
package/src/build.js
CHANGED
|
@@ -83,20 +83,53 @@ async function getWebpackConfig(config) {
|
|
|
83
83
|
packageDir,
|
|
84
84
|
"../../shared/common-bricks/common-bricks.json"
|
|
85
85
|
);
|
|
86
|
+
|
|
87
|
+
const deprecatedBricksJsonFile = path.join(
|
|
88
|
+
packageDir,
|
|
89
|
+
"../../shared/common-bricks/deprecated-bricks.json"
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const deprecatedBricksJson = existsSync(deprecatedBricksJsonFile)
|
|
93
|
+
? JSON.parse(await readFile(deprecatedBricksJsonFile, "utf-8"))
|
|
94
|
+
: {};
|
|
95
|
+
|
|
86
96
|
if (existsSync(commonBricksJsonFile)) {
|
|
87
97
|
const commonBricksJson = JSON.parse(
|
|
88
98
|
await readFile(commonBricksJsonFile, "utf-8")
|
|
89
99
|
);
|
|
90
100
|
|
|
91
|
-
/** @type {
|
|
101
|
+
/** @type {Map<string, string | string[]>} */
|
|
92
102
|
const commonBricksMap = new Map();
|
|
93
103
|
for (const [pkg, bricks] of Object.entries(commonBricksJson)) {
|
|
94
104
|
for (const brick of bricks) {
|
|
95
105
|
const existedPkg = commonBricksMap.get(brick);
|
|
96
106
|
if (existedPkg && existedPkg !== pkg) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
107
|
+
if (Array.isArray(existedPkg)) {
|
|
108
|
+
const pkgs = existedPkg.concat(pkg);
|
|
109
|
+
|
|
110
|
+
const othersPkgs = pkgs.filter(
|
|
111
|
+
(p) => !deprecatedBricksJson[p]?.includes(brick)
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
throw new Error(
|
|
115
|
+
`Conflicted common brick: "${brick}" in package "${othersPkgs[0]}" and "${othersPkgs[1]}"`
|
|
116
|
+
);
|
|
117
|
+
} else {
|
|
118
|
+
const existedPkgDeprecated = deprecatedBricksJson[existedPkg];
|
|
119
|
+
const pkgDeprecated = deprecatedBricksJson[pkg];
|
|
120
|
+
|
|
121
|
+
if (
|
|
122
|
+
(existedPkgDeprecated && existedPkgDeprecated.includes(brick)) ||
|
|
123
|
+
(pkgDeprecated && pkgDeprecated.includes(brick))
|
|
124
|
+
) {
|
|
125
|
+
commonBricksMap.set(brick, [pkg].concat(existedPkg));
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
throw new Error(
|
|
130
|
+
`Conflicted common brick: "${brick}" in package "${existedPkg}" and "${pkg}"`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
100
133
|
}
|
|
101
134
|
commonBricksMap.set(brick, pkg);
|
|
102
135
|
}
|
|
@@ -470,6 +503,12 @@ async function getWebpackConfig(config) {
|
|
|
470
503
|
manifest: config.manifest,
|
|
471
504
|
types: config.types,
|
|
472
505
|
examples: config.examples,
|
|
506
|
+
deprecatedElements: Object.prototype.hasOwnProperty.call(
|
|
507
|
+
deprecatedBricksJson,
|
|
508
|
+
packageName
|
|
509
|
+
)
|
|
510
|
+
? deprecatedBricksJson[packageName]
|
|
511
|
+
: undefined,
|
|
473
512
|
}),
|
|
474
513
|
]
|
|
475
514
|
: []),
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import webpack from "webpack";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { createRequire } from "module";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { writeFile, rm } from "node:fs/promises";
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
function getBuildStoriesWebpackConfig(packageDir, storiesPath) {
|
|
10
|
+
const outputPath = path.join(packageDir, "dist");
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
entry: storiesPath,
|
|
14
|
+
output: {
|
|
15
|
+
publicPath: `bricks/${path.basename(packageDir)}/dist/`,
|
|
16
|
+
path: outputPath,
|
|
17
|
+
filename: `stories.cjs`,
|
|
18
|
+
library: {
|
|
19
|
+
type: "commonjs",
|
|
20
|
+
export: "default",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
resolve: {
|
|
24
|
+
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
|
|
25
|
+
extensionAlias: {
|
|
26
|
+
".js": [".ts", ".tsx", ".js", ".jsx"],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
module: {
|
|
30
|
+
rules: [
|
|
31
|
+
{
|
|
32
|
+
test: /\.ts?$/,
|
|
33
|
+
loader: "babel-loader",
|
|
34
|
+
exclude: /node_modules/,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
test: /\.svg$/i,
|
|
38
|
+
type: "asset/resource",
|
|
39
|
+
generator: {
|
|
40
|
+
filename: "stories-assets/[name].[contenthash][ext]",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
devtool: false,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} packageDir
|
|
50
|
+
* @returns {Promise<void>}
|
|
51
|
+
*/
|
|
52
|
+
const buildStories = async (packageDir) => {
|
|
53
|
+
const storiesPath = path.join(packageDir, "stories");
|
|
54
|
+
if (existsSync(storiesPath)) {
|
|
55
|
+
const compiler = await webpack(
|
|
56
|
+
await getBuildStoriesWebpackConfig(packageDir, storiesPath)
|
|
57
|
+
);
|
|
58
|
+
await new Promise((resolve, reject) => {
|
|
59
|
+
compiler.run((err, stats) => {
|
|
60
|
+
if (err || stats.hasErrors()) {
|
|
61
|
+
console.error("Failed to build stories:");
|
|
62
|
+
reject(err || stats.toString());
|
|
63
|
+
} else {
|
|
64
|
+
resolve();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const transformStoriesPath = path.join(packageDir, "dist/stories.cjs");
|
|
70
|
+
|
|
71
|
+
if (existsSync(transformStoriesPath)) {
|
|
72
|
+
const result = require(transformStoriesPath);
|
|
73
|
+
|
|
74
|
+
const stories = Object.values(result);
|
|
75
|
+
if (stories.length) {
|
|
76
|
+
const distDir = path.join(packageDir, "dist");
|
|
77
|
+
|
|
78
|
+
await writeFile(
|
|
79
|
+
path.join(distDir, "stories.json"),
|
|
80
|
+
JSON.stringify(stories, null, 2)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
await rm(transformStoriesPath);
|
|
85
|
+
console.log("Build stories done");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default buildStories;
|