@digigov/cli-build 2.0.0-rc.25 → 2.0.0-rc.27

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "../../tooling/cli-build": "../../tooling/cli-build:49NIl9fmQJWuxptJyRVMgpTF1wzHD2uibsclo+LHL2c=:",
2
+ "../../tooling/cli-build": "../../tooling/cli-build:02YjlK6+1qui1+paVKGwEISZBfTmSHa5jCm7uK5t+7I=:",
3
3
  "/@babel/cli@7.12.1(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
4
4
  "/@babel/compat-data@7.12.5": "Missing shrinkwrap entry!",
5
5
  "/@babel/core@7.26.0": "Missing shrinkwrap entry!",
@@ -11,6 +11,8 @@
11
11
  "/@babel/preset-env@7.12.13(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
12
12
  "/@babel/preset-react@7.12.13(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
13
13
  "/@babel/preset-typescript@7.12.1(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
14
+ "/@types/fs-extra@11.0.4": "Missing shrinkwrap entry!",
15
+ "/@types/node@18.19.0": "Missing shrinkwrap entry!",
14
16
  "/babel-plugin-inline-import-data-uri@1.0.1": "Missing shrinkwrap entry!",
15
17
  "/babel-plugin-istanbul@7.0.0": "Missing shrinkwrap entry!",
16
18
  "/babel-plugin-module-resolver@4.0.0": "Missing shrinkwrap entry!",
@@ -19,10 +21,14 @@
19
21
  "/babel-plugin-transform-dev-warning@0.1.1": "Missing shrinkwrap entry!",
20
22
  "/babel-plugin-transform-react-constant-elements@6.23.0": "Missing shrinkwrap entry!",
21
23
  "/babel-plugin-transform-react-remove-prop-types@0.4.24": "Missing shrinkwrap entry!",
24
+ "/commander@12.1.0": "Missing shrinkwrap entry!",
22
25
  "/esbuild@0.23.0": "Missing shrinkwrap entry!",
23
26
  "/fs-extra@11.2.0": "Missing shrinkwrap entry!",
24
27
  "/globby@11.0.0": "Missing shrinkwrap entry!",
25
28
  "/next@13.1.1(@babel/core@7.26.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)": "Missing shrinkwrap entry!",
26
29
  "/publint@0.1.8": "Missing shrinkwrap entry!",
27
- "/rimraf@3.0.2": "Missing shrinkwrap entry!"
30
+ "/rimraf@3.0.2": "Missing shrinkwrap entry!",
31
+ "/ts-morph@25.0.0": "Missing shrinkwrap entry!",
32
+ "/typescript@5.6.2": "Missing shrinkwrap entry!",
33
+ "/vitest@2.1.3(@types/node@18.19.0)(happy-dom@15.11.0)(jsdom@20.0.3)(lightningcss@1.22.0)(sass-embedded@1.81.0)(terser@5.33.0)": "Missing shrinkwrap entry!"
28
34
  }
package/build.js ADDED
@@ -0,0 +1,85 @@
1
+ import { DigigovCommand, logger } from "@digigov/cli/lib";
2
+
3
+ import assert from "assert";
4
+ import path from "path";
5
+ import fs from "fs-extra";
6
+ import baseEsbuild from "esbuild";
7
+
8
+ /**
9
+ * Generate TypeScript declaration files
10
+ *
11
+ * @param {object} project - The project object
12
+ * @param {string} project.root - The project root directory
13
+ * @param {string} project.src - The project source directory
14
+ * @param {string} project.distDir - The project build directory
15
+ * @param {string} tsconfig - The tsconfig path
16
+ * @param {DigigovCommand} ctx - The command context
17
+ */
18
+ export async function generateTypeDeclarationFiles(project, tsconfig, ctx) {
19
+ logger.debug("Building types...");
20
+
21
+ const distDir = path.resolve(project.root, project.distDir);
22
+ const projectBasename = path.basename(project.root);
23
+
24
+ await ctx.exec("tsc", [
25
+ "--emitDeclarationOnly",
26
+ "--outDir",
27
+ "dist",
28
+ "--project",
29
+ tsconfig,
30
+ ]);
31
+
32
+ const projectBasePath = path.join(distDir, projectBasename);
33
+ logger.debug("Project base path", projectBasePath);
34
+ if (await fs.exists(projectBasePath)) {
35
+ const typesIncluded = await fs.readdir(path.join(distDir));
36
+ const srcPath = path.join(distDir, projectBasename, project.src);
37
+ const paths = await fs.readdir(srcPath);
38
+
39
+ await Promise.all([
40
+ // Move src files to dist
41
+ ...paths.map((p) => {
42
+ logger.debug("Moving types file", p);
43
+ fs.move(path.join(srcPath, p), path.join(distDir, p));
44
+ }),
45
+ // Remove dirs
46
+ ...typesIncluded.map((typesDir) => {
47
+ logger.debug("Removing types directory", typesDir);
48
+ fs.rm(path.join(distDir, typesDir), { recursive: true });
49
+ }),
50
+ ]).catch((err) => {
51
+ logger.error("Error while building types", err);
52
+ });
53
+ }
54
+ logger.debug("Types built.");
55
+ }
56
+
57
+ /**
58
+ * Run esbuild for the given options
59
+ *
60
+ * @param {object} options - The build options
61
+ * @param {string[]} options.files - The files to build
62
+ * @param {string | undefined} options.tsconfig - The tsconfig path
63
+ * @param {"esm" | "cjs"} options.format - The module format
64
+ * @param {string} options.outdir - The output directory
65
+ */
66
+ export function buildFormat({ files: entryPoints, tsconfig, format, outdir }) {
67
+ assert(format === "esm" || format === "cjs", "Invalid format");
68
+
69
+ logger.log(`Running: esbuild for ${format.toUpperCase()} format`);
70
+ return baseEsbuild.build({
71
+ ...BASE_OPTIONS,
72
+ entryPoints,
73
+ tsconfig,
74
+ format,
75
+ outdir,
76
+ });
77
+ }
78
+
79
+ /** @type {baseEsbuild.BuildOptions} */
80
+ export const BASE_OPTIONS = {
81
+ logLevel: "error",
82
+ platform: "node",
83
+ sourcemap: true,
84
+ target: ["esnext"],
85
+ };
package/common.js ADDED
@@ -0,0 +1,20 @@
1
+ import fs from "fs-extra";
2
+ import path from "path";
3
+
4
+ const POSSIBLE_TS_CONFIGS = ["tsconfig.production.json", "tsconfig.json"];
5
+
6
+ /**
7
+ * Get the tsconfig path for the given project
8
+ *
9
+ * @param {string} projectRoot - The project root
10
+ * @returns {string | undefined} - The tsconfig path or undefined if not found
11
+ */
12
+ export function getProjectTsconfig(projectRoot) {
13
+ for (const tsconfig of POSSIBLE_TS_CONFIGS) {
14
+ const tsconfigPath = path.join(projectRoot, tsconfig);
15
+ if (fs.existsSync(tsconfigPath)) {
16
+ return tsconfigPath;
17
+ }
18
+ }
19
+ return;
20
+ }
package/copy-files.js CHANGED
@@ -4,11 +4,8 @@ import path from "path";
4
4
  import glob from "globby";
5
5
 
6
6
  const packagePath = process.cwd();
7
-
8
- function getBuildPath() {
9
- const project = resolveProject();
10
- return path.join(project.root, project.distDir);
11
- }
7
+ const project = resolveProject();
8
+ const buildPath = path.join(project.root, project.distDir);
12
9
 
13
10
  /**
14
11
  * Copy a file from the package to the build directory
@@ -17,10 +14,20 @@ function getBuildPath() {
17
14
  */
18
15
  function includeFileInBuild(file) {
19
16
  const sourcePath = path.resolve(packagePath, file);
20
- const buildPath = getBuildPath();
21
17
  const targetPath = path.resolve(buildPath, path.basename(file));
22
18
  fs.copySync(sourcePath, targetPath);
23
- logger.log(`Copied ${sourcePath} to ${targetPath}`);
19
+ logger.debug(`Copied ${sourcePath} to build directory`);
20
+ }
21
+
22
+ function copyRegistryFilesToSrc() {
23
+ const registryPath = path.resolve(buildPath, "registry/index.js");
24
+ const lazyPath = path.resolve(buildPath, "lazy/index.js");
25
+ if (!fs.existsSync(registryPath) || !fs.existsSync(lazyPath)) return;
26
+
27
+ const srcPath = path.resolve(buildPath, "src");
28
+ logger.debug(`Copying registry and lazy files to ${srcPath}`);
29
+ fs.copySync(registryPath, path.resolve(srcPath, "registry.js"));
30
+ fs.copySync(lazyPath, path.resolve(srcPath, "lazy.js"));
24
31
  }
25
32
 
26
33
  /**
@@ -40,11 +47,10 @@ function createRootPackageFile() {
40
47
  module: "./index.js",
41
48
  typings: "./index.d.ts",
42
49
  };
43
- const buildPath = getBuildPath();
44
50
  const targetPath = path.resolve(buildPath, "./package.json");
45
51
 
46
52
  fs.writeFileSync(targetPath, JSON.stringify(newPackageData, null, 2), "utf8");
47
- logger.log(`Created package.json in ${targetPath}`);
53
+ logger.debug(`Created package.json in build directory`);
48
54
 
49
55
  return newPackageData;
50
56
  }
@@ -54,7 +60,6 @@ function createRootPackageFile() {
54
60
  *
55
61
  */
56
62
  function createNestedPackageFiles() {
57
- const buildPath = getBuildPath();
58
63
  const indexPaths = glob.sync(path.join(buildPath, "**/index.js"), {
59
64
  ignore: [path.join(buildPath, "cjs/**")],
60
65
  });
@@ -86,6 +91,7 @@ function createNestedPackageFiles() {
86
91
  function prepend(file, string) {
87
92
  const data = fs.readFileSync(file, "utf8");
88
93
  fs.writeFileSync(file, string + data, "utf8");
94
+ logger.debug(`Prepended license to ${file}`);
89
95
  }
90
96
 
91
97
  /**
@@ -94,7 +100,6 @@ function prepend(file, string) {
94
100
  * @param {object} packageData - The package data
95
101
  */
96
102
  function addLicense(packageData) {
97
- const buildPath = getBuildPath();
98
103
  const license = `/** @license Digigov v${packageData["version"]}
99
104
  *
100
105
  * This source code is licensed under the BSD-2-Clause license found in the
@@ -111,7 +116,7 @@ function addLicense(packageData) {
111
116
  "code" in err &&
112
117
  err.code === "ENOENT"
113
118
  ) {
114
- logger.log(`Skipped license for ${file}`);
119
+ logger.debug(`Skipped license for ${file}`);
115
120
  } else {
116
121
  throw err;
117
122
  }
@@ -123,7 +128,6 @@ function addLicense(packageData) {
123
128
  * Create separate index modules for each directory
124
129
  */
125
130
  function createSeparateIndexModules() {
126
- const buildPath = getBuildPath();
127
131
  const files = glob.sync(path.join(buildPath, "**/*.js"), {
128
132
  ignore: [path.join(buildPath, "**/index.js")],
129
133
  });
@@ -141,6 +145,7 @@ export default function run() {
141
145
  const packageData = createRootPackageFile();
142
146
  createSeparateIndexModules();
143
147
  createNestedPackageFiles();
148
+ copyRegistryFilesToSrc();
144
149
 
145
150
  [
146
151
  // use enhanced readme from workspace root for `@digigov/ui`
@@ -0,0 +1,268 @@
1
+ import { logger } from "@digigov/cli/lib";
2
+ import path from "path";
3
+ import fs from "fs-extra";
4
+ import { SyntaxKind, Project as TsMorphProject } from "ts-morph";
5
+ import assert from "assert";
6
+
7
+ import { getProjectTsconfig } from "./common.js";
8
+
9
+ /**
10
+ * Generate registry files for the given project
11
+ *
12
+ * @param {object} project - The project object
13
+ * @param {string} project.root - The project root directory
14
+ * @param {string} project.distDir - The project build directory
15
+ * @param {string} project.name - The project name as in package.json
16
+ * @param {string[]} filePaths - The paths of the files to include in the registry
17
+ * @param {boolean} shouldGenerateStoriesRegistry - Whether to export stories in the registry
18
+ * @returns {Promise<[string, string]>} - The paths of the generated registry files
19
+ */
20
+ export async function generateRegistryFiles(
21
+ project,
22
+ filePaths,
23
+ shouldGenerateStoriesRegistry = false,
24
+ ) {
25
+ const registryPath = ensureRegistryPath(project, "registry.js");
26
+ const lazyRegistryPath = ensureRegistryPath(project, "lazy.js");
27
+
28
+ const registry = generateRegistryFileContent(
29
+ project,
30
+ filePaths,
31
+ shouldGenerateStoriesRegistry,
32
+ );
33
+
34
+ const componentPathsOnly = filePaths.filter(
35
+ (path) => !path.includes("stories"),
36
+ );
37
+ const lazyRegistry = generateLazyFileContent(project, componentPathsOnly);
38
+
39
+ await Promise.all([
40
+ fs.writeFile(registryPath, registry),
41
+ fs.writeFile(lazyRegistryPath, lazyRegistry),
42
+ ]);
43
+
44
+ return [registryPath, lazyRegistryPath];
45
+ }
46
+
47
+ /**
48
+ * Ensure that the registry file does not already exist at the given path
49
+ *
50
+ * @param {object} project - The project object
51
+ * @param {string} project.root - The project root directory
52
+ * @param {string} project.distDir - The project build directory
53
+ * @param {string} fileName - The name of the registry file
54
+ */
55
+ function ensureRegistryPath(project, fileName) {
56
+ const registryPath = path.join(project.root, project.distDir, fileName);
57
+ if (fs.existsSync(registryPath))
58
+ throw new Error(`A "${fileName}" file already exists at ${registryPath}.`);
59
+ return registryPath;
60
+ }
61
+
62
+ /**
63
+ * Generate registry file content for the given files
64
+ *
65
+ * @param {object} project - The project object
66
+ * @param {string} project.root - The project root directory
67
+ * @param {string} project.name - The project name as in package.json
68
+ * @param {string[]} absoluteFilePaths - The absolute paths of the files to include in the registry
69
+ * @param {boolean} includeStories - Whether to include stories in the registry
70
+ * @returns {string} - The registry file content or null if no components are found
71
+ */
72
+ export function generateRegistryFileContent(
73
+ project,
74
+ absoluteFilePaths,
75
+ includeStories = false,
76
+ ) {
77
+ const relativePaths = absoluteFilePaths.map((path) => {
78
+ assert(
79
+ path.startsWith(project.root),
80
+ "Expected path to be in project root",
81
+ );
82
+ return toNodeResolvablePath(
83
+ path.replace(`${project.root}/src/`, `${project.name}/`),
84
+ );
85
+ });
86
+ let registryPaths = relativePaths.map((path) => ({
87
+ path,
88
+ uid: createUid(path),
89
+ }));
90
+
91
+ if (registryPaths.length === 0)
92
+ throw new Error(
93
+ "Could not generate registry. No exportable modules found.",
94
+ );
95
+
96
+ const importStatements = registryPaths.map(
97
+ (file) => `import * as ${file.uid} from "${file.path}";`,
98
+ );
99
+ const exportStatements = registryPaths.map(
100
+ (file) => ` '${file.path}': lazyImport(${file.uid})`,
101
+ );
102
+
103
+ const [components, stories] = splitStoriesExports(exportStatements);
104
+ logger.debug(`Including ${components.length} component modules in registry`);
105
+
106
+ if (includeStories) {
107
+ logger.debug(`Including ${stories.length} stories in registry`);
108
+ }
109
+
110
+ let out = `
111
+ ${importStatements.join("\n")}
112
+ function lazyImport(pkgImport) {
113
+ return new Proxy(
114
+ {},
115
+ {
116
+ get: (_target, name) => {
117
+ if (name === '__esModule' || name === 'default') {
118
+ return pkgImport.default;
119
+ } else if(
120
+ name === '*'
121
+ ) {
122
+ return pkgImport;
123
+ } else {
124
+ return pkgImport[name];
125
+ }
126
+ },
127
+ }
128
+ )
129
+ }
130
+ export default {
131
+ ${components.join(",\n")}
132
+ };
133
+ `;
134
+
135
+ if (includeStories) {
136
+ out += `
137
+
138
+ export const stories = {
139
+ ${stories.join(",\n")}
140
+ };
141
+ `;
142
+ }
143
+ return out;
144
+ }
145
+
146
+ /**
147
+ * Extract a node-resolvable path
148
+ *
149
+ * @param {string} inputPath - The file path
150
+ * @returns {string} - The node-resolvable path
151
+ */
152
+ export function toNodeResolvablePath(inputPath) {
153
+ const dir = path.dirname(inputPath);
154
+ const base = path.basename(inputPath, path.extname(inputPath));
155
+
156
+ return base === "index" ? dir : path.join(dir, base);
157
+ }
158
+
159
+ /**
160
+ * Create a UID from a path
161
+ *
162
+ * @param {string} inputPath - The path
163
+ * @returns {string} - The UID
164
+ */
165
+ export function createUid(inputPath) {
166
+ return inputPath.replace(/[\/@\-.]/g, "_");
167
+ }
168
+
169
+ /**
170
+ * Split the given files into components and stories
171
+ *
172
+ * @param {string[]} exportStatements - The export statements
173
+ * @returns {[string[], string[]]} - The split components and stories exports
174
+ */
175
+ export function splitStoriesExports(exportStatements) {
176
+ const stories = [];
177
+ const components = [];
178
+ for (const exportStatement of exportStatements) {
179
+ if (exportStatement.includes("_stories")) {
180
+ stories.push(exportStatement);
181
+ } else {
182
+ components.push(exportStatement);
183
+ }
184
+ }
185
+ return [components, stories];
186
+ }
187
+
188
+ /**
189
+ * Generate lazy component registry file content for the given project
190
+ *
191
+ * @param {object} project - The project object
192
+ * @param {string} project.root - The project root directory
193
+ * @param {string} project.name - The project name as in package.json
194
+ * @param {string[]} filePaths - The files whose exports will be included in the lazy registry
195
+ * @returns {string} - The lazy component registry file content or null if no components are found
196
+ */
197
+ export function generateLazyFileContent(project, filePaths) {
198
+ const tsMorphProject = new TsMorphProject({
199
+ tsConfigFilePath: getProjectTsconfig(project.root),
200
+ });
201
+
202
+ /** @type {Record<string, string>} */
203
+ let allComponents = {};
204
+
205
+ for (const filePath of filePaths) {
206
+ const sourceFile = tsMorphProject.addSourceFileAtPath(filePath);
207
+ const exports = sourceFile
208
+ .getExportSymbols()
209
+ .filter(isJsExport)
210
+ .map((symbol) => symbol.getName());
211
+
212
+ for (const exportedComponent of exports) {
213
+ if (
214
+ exportedComponent !== "default" &&
215
+ exportedComponent.match(/^[A-Z]/)
216
+ ) {
217
+ if (
218
+ !allComponents[exportedComponent] ||
219
+ allComponents[exportedComponent].length < filePath.length // Make import path more specific
220
+ ) {
221
+ allComponents[exportedComponent] = toNodeResolvablePath(
222
+ filePath.replace(`${project.root}/src/`, `${project.name}/`),
223
+ );
224
+ }
225
+ }
226
+ }
227
+ }
228
+
229
+ const componentCount = Object.keys(allComponents).length;
230
+
231
+ if (componentCount === 0)
232
+ throw new Error(
233
+ "Could not generate lazy registry. No exportable components found.",
234
+ );
235
+
236
+ logger.debug(`Including ${componentCount} components in lazy registry`);
237
+
238
+ const content = Object.entries(allComponents)
239
+ .map(
240
+ ([component, filePath]) =>
241
+ ` '${component}': lazy(() => import('${filePath}').then((module) => ({ default: module['${component}'] })))`,
242
+ )
243
+ .join(",\n");
244
+
245
+ return `import { lazy } from 'react';
246
+ export default {
247
+ ${content}
248
+ };
249
+ `;
250
+ }
251
+
252
+ /**
253
+ * Check if a symbol is a JS export
254
+ *
255
+ * @param {import("ts-morph").Symbol} symbol - The symbol to check
256
+ */
257
+ function isJsExport(symbol) {
258
+ const declarations = symbol.getDeclarations();
259
+ return declarations.some((declaration) => {
260
+ const kind = declaration.getKind();
261
+ return (
262
+ kind === SyntaxKind.FunctionDeclaration ||
263
+ kind === SyntaxKind.ClassDeclaration ||
264
+ kind === SyntaxKind.VariableDeclaration ||
265
+ kind === SyntaxKind.ExportSpecifier
266
+ );
267
+ });
268
+ }
package/index.js CHANGED
@@ -1,85 +1,106 @@
1
- import { DigigovCommand, resolveProject } from "@digigov/cli/lib";
1
+ import { DigigovCommand, resolveProject, logger } from "@digigov/cli/lib";
2
+ import { buildFormat, generateTypeDeclarationFiles } from "./build.js";
3
+ import { generateRegistryFiles } from "./generate-registry.js";
2
4
  import copyFiles from "./copy-files.js";
3
5
 
4
- import fs from "fs-extra";
6
+ import { Option } from "commander";
5
7
  import path from "path";
6
- import esbuild from "esbuild";
7
8
  import glob from "globby";
9
+ import assert from "assert";
10
+ import { getProjectTsconfig } from "./common.js";
8
11
 
9
- const command = new DigigovCommand("build", import.meta.url).action(build);
12
+ const command = new DigigovCommand("build", import.meta.url)
13
+ .option(
14
+ "--generate-registry",
15
+ "Generate a registry file for the build output",
16
+ )
17
+ .addOption(
18
+ new Option("--include-stories", "Include stories in the output").implies({
19
+ generateRegistry: true,
20
+ }),
21
+ )
22
+ .action(main);
10
23
  export default command;
11
24
 
25
+ const SRC_GLOB = "src/**/*.{tsx,ts,js,jsx}";
26
+ const TEST_GLOBS = [
27
+ "**/*.test.{js,jsx,ts,tsx}",
28
+ "**/*.spec.{js,jsx,ts,tsx}",
29
+ "**/__tests__/**/*.{js,jsx,ts,tsx}",
30
+ ];
31
+ const STORIES_GLOBS = [
32
+ "**/*.stories.{js,jsx,ts,tsx}",
33
+ "**/__stories__/**/*.{js,jsxts,tsx}",
34
+ ];
35
+
12
36
  /**
37
+ * @param {object} options - The command options
38
+ * @param {boolean} options.generateRegistry - Generate a registry file for the build output
39
+ * @param {boolean} options.includeStories - Include stories in the generated registry file
13
40
  * @param {DigigovCommand} ctx
14
41
  */
15
- async function build(_, ctx) {
16
- await ctx.exec("rimraf", ["dist"]);
42
+ async function main(options, ctx) {
17
43
  const project = resolveProject();
18
44
 
19
- const distDir = path.resolve(project.root, project.distDir);
20
- const basename = path.basename(project.root);
45
+ await ctx.exec("rimraf", [project.distDir]);
21
46
 
47
+ /**
48
+ * The project tsconfig, or undefined if the project is not using TypeScript
49
+ * @type {string | undefined}
50
+ */
51
+ let tsconfig;
22
52
  if (project.isTs) {
23
- const tsconfigProduction = path.join(
24
- project.root,
25
- "tsconfig.production.json",
26
- );
27
- /** @type {string[]} */
28
- const tsArgs = [];
29
- if (fs.existsSync(tsconfigProduction)) {
30
- tsArgs.push("--project", tsconfigProduction);
31
- }
32
- await ctx.exec("tsc", [
33
- "--emitDeclarationOnly",
34
- "--outDir",
35
- "dist",
36
- ...tsArgs,
37
- ]);
38
- if (fs.existsSync(path.join(distDir, basename))) {
39
- const typesIncluded = fs.readdirSync(path.join(distDir));
40
- const paths = fs.readdirSync(path.join(distDir, basename, project.src));
41
- paths.forEach((p) => {
42
- fs.renameSync(
43
- path.join(distDir, basename, project.src, p),
44
- path.join(distDir, p),
45
- );
46
- });
47
- typesIncluded.forEach((typesDir) => {
48
- fs.rmSync(path.join(distDir, typesDir), { recursive: true });
49
- });
50
- }
53
+ tsconfig = getProjectTsconfig(project.root);
54
+ assert(tsconfig, "Expected tsconfig to be in project");
55
+ await generateTypeDeclarationFiles(project, tsconfig, ctx);
51
56
  }
52
57
 
53
- const files = glob.sync(
54
- path.join(project.root, "src", "**/*.{tsx,ts,js,jsx}"),
55
- {
56
- ignore: ["**/*.{spec,test}.{ts,tsx,js,jsx}"],
57
- },
58
- );
59
- const commonBuildOptions = {
60
- entryPoints: files,
61
- platform: "node",
62
- sourcemap: true,
63
- target: ["esnext"],
64
- logLevel: "error",
65
- };
66
- if (fs.existsSync(path.join(project.root, "tsconfig.production.json"))) {
67
- commonBuildOptions["tsconfig"] = "tsconfig.production.json";
68
- } else if (fs.existsSync(path.join(project.root, "tsconfig.json"))) {
69
- commonBuildOptions["tsconfig"] = "tsconfig.json";
58
+ const ignore = [...TEST_GLOBS];
59
+ if (options.includeStories) {
60
+ logger.debug("Including stories in the build");
61
+ } else {
62
+ ignore.push(...STORIES_GLOBS);
70
63
  }
71
-
64
+ const filesToBuild = await glob(path.join(project.root, SRC_GLOB), {
65
+ ignore,
66
+ });
67
+ logger.debug("Bundling ESM and CJS...");
72
68
  await Promise.all([
73
- esbuild.build({
74
- ...commonBuildOptions,
75
- format: "esm",
76
- outdir: `dist`,
77
- }),
78
- esbuild.build({
79
- ...commonBuildOptions,
69
+ buildFormat({
70
+ files: filesToBuild,
71
+ tsconfig: tsconfig,
80
72
  format: "cjs",
81
- outdir: `dist/cjs`,
73
+ outdir: project.distDir + "/cjs",
74
+ }),
75
+ buildFormat({
76
+ files: filesToBuild,
77
+ tsconfig,
78
+ format: "esm",
79
+ outdir: project.distDir,
82
80
  }),
83
81
  ]);
82
+ logger.debug("Bundling done.");
83
+
84
+ if (options.generateRegistry) {
85
+ const registryFiles = filesToBuild.filter(
86
+ (file) => !(file.includes("native") || file.endsWith(".d.ts")),
87
+ );
88
+ logger.debug("Generating registry files...");
89
+ const registryFilePaths = await generateRegistryFiles(
90
+ project,
91
+ registryFiles,
92
+ options.includeStories,
93
+ );
94
+ await buildFormat({
95
+ files: registryFilePaths,
96
+ tsconfig: tsconfig,
97
+ format: "cjs",
98
+ outdir: project.distDir + "/cjs",
99
+ });
100
+ logger.log("Generated registry files");
101
+ }
102
+
103
+ logger.debug("Copying files to build directory...");
84
104
  copyFiles();
105
+ logger.debug("Files copied.");
85
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digigov/cli-build",
3
- "version": "2.0.0-rc.25",
3
+ "version": "2.0.0-rc.27",
4
4
  "description": "Build plugin for Digigov CLI",
5
5
  "main": "./index.js",
6
6
  "type": "module",
@@ -28,17 +28,23 @@
28
28
  "babel-plugin-transform-react-remove-prop-types": "0.4.24",
29
29
  "fs-extra": "11.2.0",
30
30
  "globby": "11.0.0",
31
- "@digigov/babel-ts-to-proptypes": "1.1.0-rc.23-rc.25",
32
31
  "babel-plugin-istanbul": "7.0.0",
33
32
  "publint": "0.1.8",
34
33
  "rimraf": "3.0.2",
35
- "esbuild": "0.23.0"
34
+ "esbuild": "0.23.0",
35
+ "commander": "12.1.0",
36
+ "ts-morph": "25.0.0"
36
37
  },
37
38
  "devDependencies": {
38
- "publint": "0.1.8"
39
+ "publint": "0.1.8",
40
+ "vitest": "2.1.3",
41
+ "@digigov/cli-test": "2.0.0-rc.27",
42
+ "@types/fs-extra": "11.0.4",
43
+ "@types/node": "18.19.0",
44
+ "typescript": "5.6.2"
39
45
  },
40
46
  "peerDependencies": {
41
- "@digigov/cli": "2.0.0-rc.25",
47
+ "@digigov/cli": "2.0.0-rc.27",
42
48
  "next": "13.1.1"
43
49
  },
44
50
  "peerDependenciesMeta": {
@@ -33,7 +33,10 @@
33
33
  "@digigov/react-experimental/*": ["../libs-ui/react-experimental/src/*"],
34
34
  "@digigov/react-experimental/": ["../libs-ui/react-experimental/src"],
35
35
  "@digigov/react-experimental": ["../libs-ui/react-experimental/src"],
36
- "@digigov/storybook/*": ["../examples/storybook/stories/*"]
36
+ "@digigov/storybook/*": ["../examples/storybook/stories/*"],
37
+ "@uides/stepwise/*": ["./stepwise/src/*"],
38
+ "@uides/stepwise/": ["./stepwise/src"],
39
+ "@uides/stepwise": ["./stepwise/src"]
37
40
  }
38
41
  },
39
42
  "include": [
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "@digigov/cli/tsconfig.cli",
3
+ "compilerOptions": {
4
+ "types": [
5
+ "vitest/globals"
6
+ ]
7
+ },
8
+ "include": [
9
+ "./*.js",
10
+ "__tests__"
11
+ ]
12
+ }