@digigov/cli-build 1.1.1 → 2.0.0-07ee8440

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/index.js CHANGED
@@ -1,109 +1,106 @@
1
- const { Command, flags } = require("@oclif/command");
2
- const execa = require("execa");
3
- const { resolveProject, DigigovCommand } = require("@digigov/cli/lib");
4
- const path = require("path");
5
- const fs = require("fs");
1
+ import { DigigovCommand, resolveProject, logger } from "@digigov/cli/lib";
2
+ import { buildFormat, generateTypeDeclarationFiles } from "./build.js";
3
+ import { generateRegistryFiles } from "./generate-registry.js";
4
+ import copyFiles from "./copy-files.js";
6
5
 
7
- module.exports = class Build extends DigigovCommand {
8
- static description = "build digigov libraries";
9
- static id = "build";
10
- dirname = __dirname;
11
- static examples = [`$ digigov build`];
12
- static strict = false;
13
- static flags = {
14
- subpackages: flags.boolean({ char: "--subpackages" }),
15
- };
16
- static load() {
17
- return Build;
6
+ import { Option } from "commander";
7
+ import path from "path";
8
+ import glob from "globby";
9
+ import assert from "assert";
10
+ import { getProjectTsconfig } from "./common.js";
11
+
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);
23
+ export default command;
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
+
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
40
+ * @param {DigigovCommand} ctx
41
+ */
42
+ async function main(options, ctx) {
43
+ const project = resolveProject();
44
+
45
+ await ctx.exec("rimraf", [project.distDir]);
46
+
47
+ /**
48
+ * The project tsconfig, or undefined if the project is not using TypeScript
49
+ * @type {string | undefined}
50
+ */
51
+ let tsconfig;
52
+ if (project.isTs) {
53
+ tsconfig = getProjectTsconfig(project.root);
54
+ assert(tsconfig, "Expected tsconfig to be in project");
55
+ await generateTypeDeclarationFiles(project, tsconfig, ctx);
56
+ }
57
+
58
+ const ignore = [...TEST_GLOBS];
59
+ if (options.includeStories) {
60
+ logger.debug("Including stories in the build");
61
+ } else {
62
+ ignore.push(...STORIES_GLOBS);
18
63
  }
19
- script = "babel";
20
- async run() {
21
- const { argv, flags } = this.parse(Build);
22
- try {
23
- await this.exec("rimraf", ["dist"]);
24
- const project = resolveProject();
25
- const babelArgs = [
26
- "--config-file",
27
- path.join(__dirname, "babel.config.js"),
28
- project.src,
29
- "--extensions",
30
- ".tsx,.ts,.js,.jsx",
31
- "--copy-files",
32
- "--out-dir",
33
- ];
34
- const distDir = path.resolve(project.root, project.distDir);
35
- const basename = path.basename(project.root);
64
+ const filesToBuild = await glob(path.join(project.root, SRC_GLOB), {
65
+ ignore,
66
+ });
67
+ logger.debug("Bundling ESM and CJS...");
68
+ await Promise.all([
69
+ buildFormat({
70
+ files: filesToBuild,
71
+ tsconfig: tsconfig,
72
+ format: "cjs",
73
+ outdir: project.distDir + "/cjs",
74
+ }),
75
+ buildFormat({
76
+ files: filesToBuild,
77
+ tsconfig,
78
+ format: "esm",
79
+ outdir: project.distDir,
80
+ }),
81
+ ]);
82
+ logger.debug("Bundling done.");
36
83
 
37
- if (flags.subpackages) {
38
- if (argv.includes("--watch") || argv.includes("-w")) {
39
- throw new Error("--watch cannot be combined with --subpackages");
40
- }
41
- const args = argv.filter((a) => a !== "--subpackages");
42
- if (project.isTs) {
43
- const tsconfigProduction = path.join(
44
- project.root,
45
- "tsconfig.production.json",
46
- );
47
- const tsArgs = [];
48
- if (fs.existsSync(tsconfigProduction)) {
49
- tsArgs.push("--project", tsconfigProduction);
50
- }
51
- await this.exec("tsc", [
52
- "--emitDeclarationOnly",
53
- "--outDir",
54
- "dist",
55
- ...tsArgs,
56
- ]);
57
- if (fs.existsSync(path.join(distDir, basename))) {
58
- const typesIncluded = fs.readdirSync(path.join(distDir));
59
- const paths = fs.readdirSync(
60
- path.join(distDir, basename, project.src),
61
- );
62
- paths.forEach((p) => {
63
- fs.renameSync(
64
- path.join(distDir, basename, project.src, p),
65
- path.join(distDir, p),
66
- );
67
- });
68
- typesIncluded.forEach((typesDir) => {
69
- fs.rmSync(path.join(distDir, typesDir), { recursive: true });
70
- });
71
- }
72
- }
73
- await this.exec(this.script, [...babelArgs, "dist", ...args], {
74
- env: {
75
- BABEL_ENV: "esm",
76
- BABEL_PUBLISH: "true",
77
- },
78
- stdio: "inherit",
79
- });
80
- const proc = await this.exec(
81
- this.script,
82
- [...babelArgs, "dist/cjs", ...argv],
83
- {
84
- env: {
85
- BABEL_ENV: "cjs",
86
- BABEL_PUBLISH: "true",
87
- },
88
- stdio: "inherit",
89
- },
90
- );
91
- await execa("node", [path.join(__dirname, "copy-files.js")], {
92
- env: {},
93
- stdio: "inherit",
94
- });
95
- return proc;
96
- } else {
97
- return this.exec(this.script, [...babelArgs, "", ...argv], {
98
- env: {
99
- BABEL_ENV: "cjs",
100
- BABEL_PUBLISH: "true",
101
- },
102
- stdio: "inherit",
103
- });
104
- }
105
- } catch (err) {
106
- console.log(err);
107
- }
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");
108
101
  }
109
- };
102
+
103
+ logger.debug("Copying files to build directory...");
104
+ copyFiles();
105
+ logger.debug("Files copied.");
106
+ }
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@digigov/cli-build",
3
- "version": "1.1.1",
3
+ "version": "2.0.0-07ee8440",
4
4
  "description": "Build plugin for Digigov CLI",
5
5
  "main": "./index.js",
6
+ "type": "module",
6
7
  "author": "GRNET Devs <devs@lists.grnet.gr>",
7
8
  "license": "BSD-2-Clause",
8
9
  "private": false,
9
10
  "dependencies": {
10
11
  "@babel/cli": "7.12.1",
11
12
  "@babel/compat-data": "7.12.5",
12
- "@babel/core": "7.12.13",
13
+ "@babel/core": "7.26.0",
13
14
  "@babel/helper-validator-identifier": "7.9.5",
14
15
  "@babel/plugin-proposal-class-properties": "7.12.1",
15
16
  "@babel/plugin-proposal-object-rest-spread": "7.12.1",
@@ -26,20 +27,30 @@
26
27
  "babel-plugin-transform-react-constant-elements": "6.23.0",
27
28
  "babel-plugin-transform-react-remove-prop-types": "0.4.24",
28
29
  "fs-extra": "11.2.0",
29
- "glob": "7.1.6",
30
- "typescript": "5.3.2",
31
- "@digigov/babel-ts-to-proptypes": "1.1.0",
32
- "@types/node": "18.19.0",
33
- "babel-plugin-istanbul": "6.0.0",
34
- "publint": "0.1.8"
30
+ "globby": "11.0.0",
31
+ "babel-plugin-istanbul": "7.0.0",
32
+ "publint": "0.1.8",
33
+ "rimraf": "3.0.2",
34
+ "esbuild": "0.23.0",
35
+ "commander": "12.1.0",
36
+ "ts-morph": "25.0.0"
35
37
  },
36
38
  "devDependencies": {
37
- "publint": "0.1.8"
39
+ "publint": "0.1.8",
40
+ "vitest": "2.1.3",
41
+ "@digigov/cli-test": "2.0.0-07ee8440",
42
+ "@types/fs-extra": "11.0.4",
43
+ "@types/node": "18.19.0",
44
+ "typescript": "5.6.2"
38
45
  },
39
46
  "peerDependencies": {
40
- "@digigov/cli": "1.1.0",
41
- "rimraf": "3.0.2",
42
- "next": "10.0.9"
47
+ "@digigov/cli": "2.0.0-07ee8440",
48
+ "next": "13.1.1"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "next": {
52
+ "optional": true
53
+ }
43
54
  },
44
55
  "scripts": {
45
56
  "publint": "publint"
@@ -12,9 +12,6 @@
12
12
  "@digigov/auth/*": ["./auth/src/*"],
13
13
  "@digigov/auth/": ["./auth/src"],
14
14
  "@digigov/auth": ["./auth/src"],
15
- "@digigov/benchmark/*": ["./benchmark/src/*"],
16
- "@digigov/benchmark/": ["./benchmark/src"],
17
- "@digigov/benchmark": ["./benchmark/src"],
18
15
  "@digigov/text-search/*": ["./text-search/src/*"],
19
16
  "@digigov/text-search/": ["./text-search/src"],
20
17
  "@digigov/text-search": ["./text-search/src"],
@@ -36,14 +33,15 @@
36
33
  "@digigov/react-experimental/*": ["../libs-ui/react-experimental/src/*"],
37
34
  "@digigov/react-experimental/": ["../libs-ui/react-experimental/src"],
38
35
  "@digigov/react-experimental": ["../libs-ui/react-experimental/src"],
39
- "@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"]
40
40
  }
41
41
  },
42
42
  "include": [
43
43
  "../../libs/auth/src/**/*.tsx",
44
44
  "../../libs/auth/src/*.tsx",
45
- "../../libs/benchmark/src/**/*.tsx",
46
- "../../libs/benchmark/src/*.tsx",
47
45
  "../../libs/text-search/src/**/*.tsx",
48
46
  "../../libs/text-search/src/*.tsx",
49
47
  "../../libs/text-search/src/**/*.ts",
package/tsconfig.json CHANGED
@@ -1,45 +1,12 @@
1
1
  {
2
- "extends": "./tsconfig.base.json",
2
+ "extends": "@digigov/cli/tsconfig.cli",
3
3
  "compilerOptions": {
4
4
  "types": [
5
- "node"
6
- ],
7
- "outDir": "dist",
8
- "paths": {
9
- "@digigov/babel-ts-to-proptypes": [
10
- "node_modules/@digigov/babel-ts-to-proptypes/src"
11
- ],
12
- "@digigov/babel-ts-to-proptypes/": [
13
- "node_modules/@digigov/babel-ts-to-proptypes/src/"
14
- ],
15
- "@digigov/babel-ts-to-proptypes/*": [
16
- "node_modules/@digigov/babel-ts-to-proptypes/src/*"
17
- ],
18
- "@digigov/cli": [
19
- "node_modules/@digigov/cli/src"
20
- ],
21
- "@digigov/cli/": [
22
- "node_modules/@digigov/cli/src/"
23
- ],
24
- "@digigov/cli/*": [
25
- "node_modules/@digigov/cli/src/*"
26
- ],
27
- "@digigov/cli-build": [
28
- "./src"
29
- ],
30
- "@digigov/cli-build/": [
31
- "./src/"
32
- ],
33
- "@digigov/cli-build/*": [
34
- "./src/*"
35
- ]
36
- },
37
- "baseUrl": "./"
5
+ "vitest/globals"
6
+ ]
38
7
  },
39
8
  "include": [
40
- "index.js"
41
- ],
42
- "exclude": [
43
- "node_modules"
9
+ "./*.js",
10
+ "__tests__"
44
11
  ]
45
12
  }
@@ -1,16 +0,0 @@
1
- {
2
- "files": {
3
- "tooling/cli-build/CHANGELOG.json": "2ef133cf1382408c12a9a50394458ce636db41da",
4
- "tooling/cli-build/CHANGELOG.md": "e33f581bbe6df47d0a268214b2b36b466982382e",
5
- "tooling/cli-build/babel.common.js": "90eb10de028180d36629ed9eb6ae766533fa2fb7",
6
- "tooling/cli-build/babel.config.js": "429fbd41ed59647228513cb014d79ef7f1bc43b3",
7
- "tooling/cli-build/copy-files.js": "4cc6276d2978b40bc3afd591b1a92272b01b77dc",
8
- "tooling/cli-build/index.js": "8fbe904275720b2f09b60a78b4dcc0a2cab4b5da",
9
- "tooling/cli-build/package.json": "bdcb47af72bfd9eeebb53bdc776bae9b9366eae0",
10
- "tooling/cli-build/tsconfig.base.json": "bc11bf86f0eeec9612369323883285bb019233f6",
11
- "tooling/cli-build/tsconfig.common.json": "17a9be8e2967aa47ab21e98cfa075505f9d1823f",
12
- "tooling/cli-build/tsconfig.json": "dd8ed0b326b53d74d31dbc49a8628065f02691de",
13
- "tooling/cli-build/.rush/temp/shrinkwrap-deps.json": "7ab9dd99f20c9f4f35a3b1d3f1666e0854600af6"
14
- },
15
- "arguments": "publint "
16
- }
package/babel.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./babel.common').config
@@ -1,3 +0,0 @@
1
- Invoking: publint
2
- @digigov/cli-build lint results:
3
- All good!