@next-core/build-next-bricks 1.18.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.
@@ -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.18.0",
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": "48ac4bbeff115c782d19fcfce56c3a093d565438"
59
+ "gitHead": "442a43ffcd1065b2c42463f85a3361b4f4e77a37"
60
60
  }
@@ -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;