@digigov/cli-build 2.0.0-18c66302 → 2.0.0-2271444d
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/.prettierrc.cjs +1 -0
- package/.rush/temp/shrinkwrap-deps.json +427 -32
- package/common.js +3 -3
- package/copy-files.js +39 -79
- package/eslint.config.js +3 -0
- package/generate-registry.js +26 -25
- package/index.js +148 -90
- package/package.json +14 -27
- package/transform-imports-plugin.js +263 -0
- package/tsconfig.base.json +21 -59
- package/tsconfig.json +3 -7
- package/babel.common.cjs +0 -119
- package/babel.config.cjs +0 -1
- package/build.js +0 -93
- package/tsconfig.common.json +0 -27
package/copy-files.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { logger, resolveProject } from
|
|
2
|
-
import fs from
|
|
3
|
-
import path from
|
|
4
|
-
import glob from "globby";
|
|
1
|
+
import { logger, resolveProject } from '@digigov/cli/lib';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
5
4
|
|
|
6
5
|
const packagePath = process.cwd();
|
|
7
6
|
const project = resolveProject();
|
|
@@ -19,69 +18,47 @@ function includeFileInBuild(file) {
|
|
|
19
18
|
logger.debug(`Copied ${sourcePath} to build directory`);
|
|
20
19
|
}
|
|
21
20
|
|
|
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"));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
21
|
/**
|
|
34
22
|
* Create a package.json file in the build directory
|
|
35
23
|
*/
|
|
36
24
|
function createRootPackageFile() {
|
|
37
25
|
const packageData = fs.readFileSync(
|
|
38
|
-
path.resolve(packagePath,
|
|
39
|
-
|
|
26
|
+
path.resolve(packagePath, './package.json'),
|
|
27
|
+
'utf8'
|
|
40
28
|
);
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
41
31
|
const { nyc, scripts, devDependencies, workspaces, ...packageDataOther } =
|
|
42
32
|
JSON.parse(packageData);
|
|
43
33
|
const newPackageData = {
|
|
44
34
|
...packageDataOther,
|
|
35
|
+
main: undefined,
|
|
45
36
|
private: false,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
type: 'module', // ESM only
|
|
38
|
+
exports: {
|
|
39
|
+
'.': {
|
|
40
|
+
types: './index.d.ts',
|
|
41
|
+
import: './index.js',
|
|
42
|
+
},
|
|
43
|
+
'./src/*': './src/*',
|
|
44
|
+
'./*': {
|
|
45
|
+
types: ['./*.d.ts', './*/index.d.ts'],
|
|
46
|
+
import: ['./*', './*/index.js'],
|
|
47
|
+
},
|
|
48
|
+
'./*.js': {
|
|
49
|
+
types: './*.d.ts',
|
|
50
|
+
import: './*.js',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
49
53
|
};
|
|
50
|
-
const targetPath = path.resolve(buildPath,
|
|
54
|
+
const targetPath = path.resolve(buildPath, './package.json');
|
|
51
55
|
|
|
52
|
-
fs.writeFileSync(targetPath, JSON.stringify(newPackageData, null, 2),
|
|
56
|
+
fs.writeFileSync(targetPath, JSON.stringify(newPackageData, null, 2), 'utf8');
|
|
53
57
|
logger.debug(`Created package.json in build directory`);
|
|
54
58
|
|
|
55
59
|
return newPackageData;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
/**
|
|
59
|
-
* Create nested package.json files in the build directory
|
|
60
|
-
*
|
|
61
|
-
*/
|
|
62
|
-
function createNestedPackageFiles() {
|
|
63
|
-
const indexPaths = glob.sync(path.join(buildPath, "**/index.js"), {
|
|
64
|
-
ignore: [path.join(buildPath, "cjs/**")],
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
indexPaths.forEach((indexPath) => {
|
|
68
|
-
if (indexPath === path.join(buildPath, "index.js")) return;
|
|
69
|
-
const packageData = {
|
|
70
|
-
sideEffects: false,
|
|
71
|
-
module: "./index.js",
|
|
72
|
-
types: "./index.d.ts",
|
|
73
|
-
main: path.relative(
|
|
74
|
-
path.dirname(indexPath),
|
|
75
|
-
indexPath.replace(buildPath, path.join(buildPath, "/cjs")),
|
|
76
|
-
),
|
|
77
|
-
};
|
|
78
|
-
fs.writeFileSync(
|
|
79
|
-
path.join(path.dirname(indexPath), "package.json"),
|
|
80
|
-
JSON.stringify(packageData, null, 2),
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
62
|
/**
|
|
86
63
|
* Prepend a string to a file
|
|
87
64
|
*
|
|
@@ -89,8 +66,8 @@ function createNestedPackageFiles() {
|
|
|
89
66
|
* @param {string} string - The string to prepend
|
|
90
67
|
*/
|
|
91
68
|
function prepend(file, string) {
|
|
92
|
-
const data = fs.readFileSync(file,
|
|
93
|
-
fs.writeFileSync(file, string + data,
|
|
69
|
+
const data = fs.readFileSync(file, 'utf8');
|
|
70
|
+
fs.writeFileSync(file, string + data, 'utf8');
|
|
94
71
|
logger.debug(`Prepended license to ${file}`);
|
|
95
72
|
}
|
|
96
73
|
|
|
@@ -100,21 +77,21 @@ function prepend(file, string) {
|
|
|
100
77
|
* @param {object} packageData - The package data
|
|
101
78
|
*/
|
|
102
79
|
function addLicense(packageData) {
|
|
103
|
-
const license = `/** @license Digigov v${packageData[
|
|
80
|
+
const license = `/** @license Digigov v${packageData['version']}
|
|
104
81
|
*
|
|
105
82
|
* This source code is licensed under the BSD-2-Clause license found in the
|
|
106
83
|
* LICENSE file in the root directory of this source tree.
|
|
107
84
|
*/
|
|
108
85
|
`;
|
|
109
|
-
[
|
|
86
|
+
['./index.js', './index.mjs'].map(async (file) => {
|
|
110
87
|
try {
|
|
111
88
|
prepend(path.resolve(buildPath, file), license);
|
|
112
89
|
} catch (err) {
|
|
113
90
|
if (
|
|
114
|
-
typeof err ===
|
|
91
|
+
typeof err === 'object' &&
|
|
115
92
|
err &&
|
|
116
|
-
|
|
117
|
-
err.code ===
|
|
93
|
+
'code' in err &&
|
|
94
|
+
err.code === 'ENOENT'
|
|
118
95
|
) {
|
|
119
96
|
logger.debug(`Skipped license for ${file}`);
|
|
120
97
|
} else {
|
|
@@ -124,36 +101,19 @@ function addLicense(packageData) {
|
|
|
124
101
|
});
|
|
125
102
|
}
|
|
126
103
|
|
|
127
|
-
/**
|
|
128
|
-
* Create separate index modules for each directory
|
|
129
|
-
*/
|
|
130
|
-
function createSeparateIndexModules() {
|
|
131
|
-
const files = glob.sync(path.join(buildPath, "**/*.js"), {
|
|
132
|
-
ignore: [path.join(buildPath, "**/index.js")],
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
files.forEach((file) => {
|
|
136
|
-
fs.mkdirSync(file.replace(/\.js$/, ""));
|
|
137
|
-
fs.renameSync(file, file.replace(/\.js$/, "/index.js"));
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
104
|
/**
|
|
142
105
|
* Run the copy files script
|
|
143
106
|
*/
|
|
144
107
|
export default function run() {
|
|
145
108
|
const packageData = createRootPackageFile();
|
|
146
|
-
createSeparateIndexModules();
|
|
147
|
-
createNestedPackageFiles();
|
|
148
|
-
copyRegistryFilesToSrc();
|
|
149
109
|
|
|
150
110
|
[
|
|
151
111
|
// use enhanced readme from workspace root for `@digigov/ui`
|
|
152
112
|
// packageData.name === '@digigov/ui' ? '../../README.md' : './README.md',
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
].map((file) => includeFileInBuild(file))
|
|
158
|
-
|
|
113
|
+
'./src',
|
|
114
|
+
'./README.md',
|
|
115
|
+
'./CHANGELOG.md',
|
|
116
|
+
'../../LICENSE',
|
|
117
|
+
].map((file) => includeFileInBuild(file));
|
|
118
|
+
addLicense(packageData);
|
|
159
119
|
}
|
package/eslint.config.js
ADDED
package/generate-registry.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { logger } from
|
|
2
|
-
import path from
|
|
3
|
-
import fs from
|
|
4
|
-
import { SyntaxKind, Project as TsMorphProject } from
|
|
5
|
-
import assert from
|
|
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
6
|
|
|
7
|
-
import { getProjectTsconfig } from
|
|
7
|
+
import { getProjectTsconfig } from './common.js';
|
|
8
8
|
|
|
9
9
|
/** @typedef {Object} Project - Represents the project to be built
|
|
10
10
|
* @property {string} root - The project root directory
|
|
11
11
|
* @property {string} name - The project name as in package.json
|
|
12
|
+
* @property {string} src - The project src directory
|
|
12
13
|
* @property {string} distDir - The project build directory
|
|
13
14
|
*/
|
|
14
15
|
|
|
@@ -23,17 +24,17 @@ import { getProjectTsconfig } from "./common.js";
|
|
|
23
24
|
export async function generateRegistry(
|
|
24
25
|
project,
|
|
25
26
|
absoluteFilePaths,
|
|
26
|
-
registryFilename =
|
|
27
|
+
registryFilename = 'registry.js'
|
|
27
28
|
) {
|
|
28
29
|
const registryPath = ensureRegistryPath(project, registryFilename);
|
|
29
30
|
|
|
30
31
|
const relativePaths = absoluteFilePaths.map((path) => {
|
|
31
32
|
assert(
|
|
32
33
|
path.startsWith(project.root),
|
|
33
|
-
|
|
34
|
+
'Expected path to be in project root'
|
|
34
35
|
);
|
|
35
36
|
return toNodeResolvablePath(
|
|
36
|
-
path.replace(`${project.root}/src/`, `${project.name}/`)
|
|
37
|
+
path.replace(`${project.root}/src/`, `${project.name}/`)
|
|
37
38
|
);
|
|
38
39
|
});
|
|
39
40
|
let registryPaths = relativePaths.map((path) => ({
|
|
@@ -43,22 +44,22 @@ export async function generateRegistry(
|
|
|
43
44
|
|
|
44
45
|
if (registryPaths.length === 0)
|
|
45
46
|
throw new Error(
|
|
46
|
-
|
|
47
|
+
'Could not generate registry. No exportable modules found.'
|
|
47
48
|
);
|
|
48
49
|
|
|
49
50
|
const importStatements = registryPaths.map(
|
|
50
|
-
(file) => `import * as ${file.uid} from "${file.path}"
|
|
51
|
+
(file) => `import * as ${file.uid} from "${file.path}";`
|
|
51
52
|
);
|
|
52
53
|
const componentsToExport = registryPaths.map(
|
|
53
|
-
(file) => ` '${file.path}': lazyImport(${file.uid})
|
|
54
|
+
(file) => ` '${file.path}': lazyImport(${file.uid})`
|
|
54
55
|
);
|
|
55
56
|
|
|
56
57
|
logger.debug(
|
|
57
|
-
`Including ${componentsToExport.length} items in ${registryPath}
|
|
58
|
+
`Including ${componentsToExport.length} items in ${registryPath}`
|
|
58
59
|
);
|
|
59
60
|
|
|
60
61
|
let registryFileContent = `
|
|
61
|
-
${importStatements.join(
|
|
62
|
+
${importStatements.join('\n')}
|
|
62
63
|
function lazyImport(pkgImport) {
|
|
63
64
|
return new Proxy(
|
|
64
65
|
{},
|
|
@@ -78,7 +79,7 @@ function lazyImport(pkgImport) {
|
|
|
78
79
|
)
|
|
79
80
|
}
|
|
80
81
|
export default {
|
|
81
|
-
${componentsToExport.join(
|
|
82
|
+
${componentsToExport.join(',\n')}
|
|
82
83
|
};
|
|
83
84
|
`;
|
|
84
85
|
await fs.writeFile(registryPath, registryFileContent);
|
|
@@ -97,7 +98,7 @@ ${componentsToExport.join(",\n")}
|
|
|
97
98
|
export async function generateLazyRegistry(
|
|
98
99
|
project,
|
|
99
100
|
filePaths,
|
|
100
|
-
lazyFilename =
|
|
101
|
+
lazyFilename = 'lazy.js'
|
|
101
102
|
) {
|
|
102
103
|
const lazyPath = ensureRegistryPath(project, lazyFilename);
|
|
103
104
|
|
|
@@ -117,15 +118,15 @@ export async function generateLazyRegistry(
|
|
|
117
118
|
|
|
118
119
|
for (const exportedComponent of exports) {
|
|
119
120
|
if (
|
|
120
|
-
exportedComponent !==
|
|
121
|
-
exportedComponent.match(/^[A-Z]
|
|
121
|
+
exportedComponent !== 'default' &&
|
|
122
|
+
exportedComponent.match(/^[A-Z][a-z]+/)
|
|
122
123
|
) {
|
|
123
124
|
if (
|
|
124
125
|
!allComponents[exportedComponent] ||
|
|
125
126
|
allComponents[exportedComponent].length < filePath.length // Make import path more specific
|
|
126
127
|
) {
|
|
127
128
|
allComponents[exportedComponent] = toNodeResolvablePath(
|
|
128
|
-
filePath.replace(`${project.root}/src/`, `${project.name}/`)
|
|
129
|
+
filePath.replace(`${project.root}/src/`, `${project.name}/`)
|
|
129
130
|
);
|
|
130
131
|
}
|
|
131
132
|
}
|
|
@@ -136,7 +137,7 @@ export async function generateLazyRegistry(
|
|
|
136
137
|
|
|
137
138
|
if (componentCount === 0)
|
|
138
139
|
throw new Error(
|
|
139
|
-
|
|
140
|
+
'Could not generate lazy registry. No exportable components found.'
|
|
140
141
|
);
|
|
141
142
|
|
|
142
143
|
logger.debug(`Including ${componentCount} components in ${lazyPath}`);
|
|
@@ -144,9 +145,9 @@ export async function generateLazyRegistry(
|
|
|
144
145
|
const componentsToExport = Object.entries(allComponents)
|
|
145
146
|
.map(
|
|
146
147
|
([component, filePath]) =>
|
|
147
|
-
` '${component}': lazy(() => import('${filePath}').then((module) => ({ default: module['${component}'] })))
|
|
148
|
+
` '${component}': lazy(() => import('${filePath}').then((module) => ({ default: module['${component}'] })))`
|
|
148
149
|
)
|
|
149
|
-
.join(
|
|
150
|
+
.join(',\n');
|
|
150
151
|
|
|
151
152
|
const lazyFileContent = `import { lazy } from 'react';
|
|
152
153
|
export default {
|
|
@@ -166,7 +167,7 @@ ${componentsToExport}
|
|
|
166
167
|
* @param {string} fileName - The name of the registry file
|
|
167
168
|
*/
|
|
168
169
|
function ensureRegistryPath(project, fileName) {
|
|
169
|
-
const registryPath = path.join(project.root, project.
|
|
170
|
+
const registryPath = path.join(project.root, project.src, fileName);
|
|
170
171
|
if (fs.existsSync(registryPath))
|
|
171
172
|
throw new Error(`A "${fileName}" file already exists at ${registryPath}.`);
|
|
172
173
|
return registryPath;
|
|
@@ -182,7 +183,7 @@ function toNodeResolvablePath(inputPath) {
|
|
|
182
183
|
const dir = path.dirname(inputPath);
|
|
183
184
|
const base = path.basename(inputPath, path.extname(inputPath));
|
|
184
185
|
|
|
185
|
-
return base ===
|
|
186
|
+
return base === 'index' ? dir : path.join(dir, base);
|
|
186
187
|
}
|
|
187
188
|
|
|
188
189
|
/**
|
|
@@ -192,7 +193,7 @@ function toNodeResolvablePath(inputPath) {
|
|
|
192
193
|
* @returns {string} - The UID
|
|
193
194
|
*/
|
|
194
195
|
function createUid(inputPath) {
|
|
195
|
-
return inputPath.replace(/[
|
|
196
|
+
return inputPath.replace(/[/@\-.]/g, '_');
|
|
196
197
|
}
|
|
197
198
|
|
|
198
199
|
/**
|
package/index.js
CHANGED
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
import { DigigovCommand, resolveProject, logger } from
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { DigigovCommand, resolveProject, logger } from '@digigov/cli/lib';
|
|
2
|
+
import { build } from '@rslib/core';
|
|
3
|
+
import copyFiles from './copy-files.js';
|
|
4
|
+
|
|
5
|
+
import { Option } from 'commander';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import glob from 'globby';
|
|
8
|
+
import assert from 'assert';
|
|
9
|
+
import { getProjectTsconfig } from './common.js';
|
|
10
|
+
import { generateLazyRegistry, generateRegistry } from './generate-registry.js';
|
|
11
|
+
import transformImportsPlugin from './transform-imports-plugin.js';
|
|
12
|
+
|
|
13
|
+
const command = new DigigovCommand('build', import.meta.url)
|
|
13
14
|
.option(
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
'--generate-registry',
|
|
16
|
+
'Generate a registry file for the build output'
|
|
16
17
|
)
|
|
17
18
|
.addOption(
|
|
18
|
-
new Option(
|
|
19
|
+
new Option('--include-stories', 'Include stories in the output').implies({
|
|
19
20
|
generateRegistry: true,
|
|
20
|
-
})
|
|
21
|
+
})
|
|
21
22
|
)
|
|
22
23
|
.action(main);
|
|
23
24
|
export default command;
|
|
24
25
|
|
|
25
|
-
const SRC_GLOB =
|
|
26
|
+
const SRC_GLOB = 'src/**/*.{tsx,ts,js,jsx}';
|
|
26
27
|
const TEST_GLOBS = [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
'**/*.test.{js,jsx,ts,tsx}',
|
|
29
|
+
'**/*.spec.{js,jsx,ts,tsx}',
|
|
30
|
+
'**/__tests__/**/*.{js,jsx,ts,tsx}',
|
|
30
31
|
];
|
|
31
32
|
const STORIES_GLOBS = [
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
'**/*.stories.{js,jsx,ts,tsx}',
|
|
34
|
+
'**/__stories__/**/*.{js,jsx,ts,tsx}',
|
|
35
|
+
'**/__stories__/*.{js,jsx,ts,tsx}',
|
|
34
36
|
];
|
|
35
37
|
|
|
36
38
|
/**
|
|
@@ -40,79 +42,135 @@ const STORIES_GLOBS = [
|
|
|
40
42
|
* @param {DigigovCommand} ctx
|
|
41
43
|
*/
|
|
42
44
|
async function main(options, ctx) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
45
|
+
/** @type {string[]} */
|
|
46
|
+
let filesToDelete = [];
|
|
47
|
+
let isCleaningUp = false;
|
|
48
|
+
let signalHandlersRegistered = false;
|
|
49
|
+
|
|
50
|
+
const cleanup = async () => {
|
|
51
|
+
if (isCleaningUp) return;
|
|
52
|
+
isCleaningUp = true;
|
|
53
|
+
|
|
54
|
+
if (options.generateRegistry && filesToDelete.length > 0) {
|
|
55
|
+
logger.debug('Deleting temporary registry files...');
|
|
56
|
+
try {
|
|
57
|
+
await ctx.exec('rimraf', filesToDelete, {}, true);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
logger.error('Error during cleanup:', error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Remove signal handlers after cleanup
|
|
64
|
+
if (signalHandlersRegistered) {
|
|
65
|
+
process.off('SIGINT', handleSignal);
|
|
66
|
+
process.off('SIGTERM', handleSignal);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** @param {string} signal */
|
|
71
|
+
const handleSignal = async (signal) => {
|
|
72
|
+
logger.log(`\nReceived ${signal}, cleaning up...`);
|
|
73
|
+
await cleanup();
|
|
74
|
+
process.exit(signal === 'SIGINT' ? 130 : 143);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Register signal handlers
|
|
78
|
+
process.on('SIGINT', handleSignal);
|
|
79
|
+
process.on('SIGTERM', handleSignal);
|
|
80
|
+
signalHandlersRegistered = true;
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const project = resolveProject();
|
|
84
|
+
|
|
85
|
+
await ctx.exec('rimraf', [project.distDir]);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The project tsconfig, or undefined if the project is not using TypeScript
|
|
89
|
+
* @type {string | undefined}
|
|
90
|
+
*/
|
|
91
|
+
let tsconfig;
|
|
92
|
+
if (project.isTs) {
|
|
93
|
+
tsconfig = getProjectTsconfig(project.root);
|
|
94
|
+
assert(tsconfig, 'Expected tsconfig to be in project');
|
|
95
|
+
}
|
|
57
96
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
97
|
+
if (options.generateRegistry) {
|
|
98
|
+
logger.debug('Generating registry files...');
|
|
99
|
+
|
|
100
|
+
const initialFiles = await glob(path.join(project.root, SRC_GLOB), {
|
|
101
|
+
ignore: [...TEST_GLOBS, ...STORIES_GLOBS],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const filesToIncludeInRegistry = initialFiles.filter(
|
|
105
|
+
(file) => !(file.includes('native') || file.endsWith('.d.ts'))
|
|
106
|
+
);
|
|
107
|
+
let storiesFiles = null;
|
|
108
|
+
if (options.includeStories) {
|
|
109
|
+
logger.debug('Including stories in the registry...');
|
|
110
|
+
|
|
111
|
+
storiesFiles = await glob(
|
|
112
|
+
STORIES_GLOBS.map((glob) =>
|
|
113
|
+
path.join(project.root, project.src, glob)
|
|
114
|
+
),
|
|
115
|
+
{
|
|
116
|
+
ignore: ['**/*.native.*, **/*.d.ts'],
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
filesToDelete = await Promise.all([
|
|
122
|
+
storiesFiles
|
|
123
|
+
? generateRegistry(project, storiesFiles, 'stories-registry.ts')
|
|
124
|
+
: null,
|
|
125
|
+
generateRegistry(project, filesToIncludeInRegistry, 'registry.ts'),
|
|
126
|
+
generateLazyRegistry(project, filesToIncludeInRegistry, 'lazy.ts'),
|
|
127
|
+
]).then((paths) => paths.filter((p) => p !== null));
|
|
128
|
+
|
|
129
|
+
logger.log('Generated registry files');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const IGNORE_BLOBS = [...TEST_GLOBS, ...STORIES_GLOBS].map(
|
|
133
|
+
(path) => `!${project.root}/${path}`
|
|
84
134
|
);
|
|
85
|
-
let storiesFiles = null;
|
|
86
|
-
if (options.includeStories) {
|
|
87
|
-
logger.debug("Including stories in the registry...");
|
|
88
135
|
|
|
89
|
-
|
|
90
|
-
|
|
136
|
+
logger.debug('Building...');
|
|
137
|
+
await build({
|
|
138
|
+
source: {
|
|
139
|
+
tsconfigPath: tsconfig,
|
|
140
|
+
entry: {
|
|
141
|
+
index: [`${project.root}/${SRC_GLOB}`, ...IGNORE_BLOBS],
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
output: {
|
|
145
|
+
distPath: {
|
|
146
|
+
root: project.distDir,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
lib: [
|
|
91
150
|
{
|
|
92
|
-
|
|
151
|
+
redirect: {
|
|
152
|
+
dts: {
|
|
153
|
+
extension: true,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
bundle: false,
|
|
157
|
+
dts: {
|
|
158
|
+
bundle: false,
|
|
159
|
+
autoExtension: true,
|
|
160
|
+
},
|
|
161
|
+
format: 'esm',
|
|
162
|
+
plugins: [
|
|
163
|
+
transformImportsPlugin(project, ['@uides/react-qr-reader']),
|
|
164
|
+
],
|
|
93
165
|
},
|
|
94
|
-
|
|
95
|
-
}
|
|
166
|
+
],
|
|
167
|
+
});
|
|
168
|
+
logger.debug('Building done.');
|
|
96
169
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
generateLazyRegistry(project, filesToIncludeInRegistry),
|
|
103
|
-
]);
|
|
104
|
-
|
|
105
|
-
buildFormat({
|
|
106
|
-
files: registryFilePaths,
|
|
107
|
-
tsconfig: tsconfig,
|
|
108
|
-
format: "cjs",
|
|
109
|
-
outdir: project.distDir + "/cjs",
|
|
110
|
-
noLogs: true,
|
|
111
|
-
}),
|
|
112
|
-
logger.log("Generated registry files");
|
|
170
|
+
logger.debug('Copying files to build directory...');
|
|
171
|
+
copyFiles();
|
|
172
|
+
logger.debug('Files copied.');
|
|
173
|
+
} finally {
|
|
174
|
+
await cleanup();
|
|
113
175
|
}
|
|
114
|
-
|
|
115
|
-
logger.debug("Copying files to build directory...");
|
|
116
|
-
copyFiles();
|
|
117
|
-
logger.debug("Files copied.");
|
|
118
176
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digigov/cli-build",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-2271444d",
|
|
4
4
|
"description": "Build plugin for Digigov CLI",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -8,43 +8,28 @@
|
|
|
8
8
|
"license": "BSD-2-Clause",
|
|
9
9
|
"private": false,
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@babel/cli": "7.12.1",
|
|
12
|
-
"@babel/compat-data": "7.12.5",
|
|
13
|
-
"@babel/core": "7.26.0",
|
|
14
|
-
"@babel/helper-validator-identifier": "7.9.5",
|
|
15
|
-
"@babel/plugin-proposal-class-properties": "7.12.1",
|
|
16
|
-
"@babel/plugin-proposal-object-rest-spread": "7.12.1",
|
|
17
|
-
"@babel/plugin-transform-object-assign": "7.12.1",
|
|
18
|
-
"@babel/plugin-transform-runtime": "7.12.1",
|
|
19
|
-
"@babel/preset-env": "7.12.13",
|
|
20
|
-
"@babel/preset-react": "7.12.13",
|
|
21
|
-
"@babel/preset-typescript": "7.12.1",
|
|
22
|
-
"babel-plugin-inline-import-data-uri": "1.0.1",
|
|
23
|
-
"babel-plugin-module-resolver": "4.0.0",
|
|
24
|
-
"babel-plugin-optimize-clsx": "1.1.1",
|
|
25
|
-
"babel-plugin-react-remove-properties": "0.3.0",
|
|
26
|
-
"babel-plugin-transform-dev-warning": "0.1.1",
|
|
27
|
-
"babel-plugin-transform-react-constant-elements": "6.23.0",
|
|
28
|
-
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
|
|
29
11
|
"fs-extra": "11.2.0",
|
|
30
12
|
"globby": "11.0.0",
|
|
31
|
-
"babel-plugin-istanbul": "7.0.0",
|
|
32
13
|
"publint": "0.1.8",
|
|
33
14
|
"rimraf": "3.0.2",
|
|
34
|
-
"esbuild": "0.23.0",
|
|
35
15
|
"commander": "12.1.0",
|
|
36
|
-
"ts-morph": "25.0.0"
|
|
16
|
+
"ts-morph": "25.0.0",
|
|
17
|
+
"@rslib/core": "0.15.1"
|
|
37
18
|
},
|
|
38
19
|
"devDependencies": {
|
|
20
|
+
"@digigov/cli": "2.0.0-2271444d",
|
|
21
|
+
"@digigov/cli-lint": "2.0.0-2271444d",
|
|
39
22
|
"publint": "0.1.8",
|
|
40
23
|
"vitest": "2.1.3",
|
|
41
|
-
"@digigov/cli-test": "2.0.0-
|
|
24
|
+
"@digigov/cli-test": "2.0.0-2271444d",
|
|
42
25
|
"@types/fs-extra": "11.0.4",
|
|
43
|
-
"@types/node": "
|
|
44
|
-
"typescript": "5.6.2"
|
|
26
|
+
"@types/node": "20.17.24",
|
|
27
|
+
"typescript": "5.6.2",
|
|
28
|
+
"eslint": "9.16.0",
|
|
29
|
+
"prettier": "3.4.2"
|
|
45
30
|
},
|
|
46
31
|
"peerDependencies": {
|
|
47
|
-
"@digigov/cli": "2.0.0-
|
|
32
|
+
"@digigov/cli": "2.0.0-2271444d",
|
|
48
33
|
"next": "13.1.1"
|
|
49
34
|
},
|
|
50
35
|
"peerDependenciesMeta": {
|
|
@@ -53,6 +38,8 @@
|
|
|
53
38
|
}
|
|
54
39
|
},
|
|
55
40
|
"scripts": {
|
|
56
|
-
"publint": "publint"
|
|
41
|
+
"publint": "publint",
|
|
42
|
+
"lint": "digigov lint",
|
|
43
|
+
"typecheck": "tsc"
|
|
57
44
|
}
|
|
58
45
|
}
|