@digigov/cli-build 2.0.0-0c4be34e → 2.0.0-107d908d
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 +413 -26
- package/build.js +93 -0
- package/common.js +20 -0
- package/copy-files.js +56 -49
- package/eslint.config.js +3 -0
- package/generate-registry.js +214 -0
- package/index.js +99 -66
- package/package.json +18 -25
- package/tsconfig.base.json +4 -1
- package/tsconfig.json +8 -0
- package/babel.common.cjs +0 -119
- package/babel.config.cjs +0 -1
package/copy-files.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { logger, resolveProject } from
|
|
2
|
-
import fs from
|
|
3
|
-
import path from
|
|
4
|
-
import glob from
|
|
1
|
+
import { logger, resolveProject } from '@digigov/cli/lib';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import glob from 'globby';
|
|
5
5
|
|
|
6
6
|
const packagePath = process.cwd();
|
|
7
|
-
|
|
8
|
-
|
|
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.
|
|
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
|
/**
|
|
@@ -28,23 +35,24 @@ function includeFileInBuild(file) {
|
|
|
28
35
|
*/
|
|
29
36
|
function createRootPackageFile() {
|
|
30
37
|
const packageData = fs.readFileSync(
|
|
31
|
-
path.resolve(packagePath,
|
|
32
|
-
|
|
38
|
+
path.resolve(packagePath, './package.json'),
|
|
39
|
+
'utf8'
|
|
33
40
|
);
|
|
41
|
+
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
43
|
const { nyc, scripts, devDependencies, workspaces, ...packageDataOther } =
|
|
35
44
|
JSON.parse(packageData);
|
|
36
45
|
const newPackageData = {
|
|
37
46
|
...packageDataOther,
|
|
38
47
|
private: false,
|
|
39
|
-
main:
|
|
40
|
-
module:
|
|
41
|
-
typings:
|
|
48
|
+
main: './cjs/index.js',
|
|
49
|
+
module: './index.js',
|
|
50
|
+
typings: './index.d.ts',
|
|
42
51
|
};
|
|
43
|
-
const
|
|
44
|
-
const targetPath = path.resolve(buildPath, "./package.json");
|
|
52
|
+
const targetPath = path.resolve(buildPath, './package.json');
|
|
45
53
|
|
|
46
|
-
fs.writeFileSync(targetPath, JSON.stringify(newPackageData, null, 2),
|
|
47
|
-
logger.
|
|
54
|
+
fs.writeFileSync(targetPath, JSON.stringify(newPackageData, null, 2), 'utf8');
|
|
55
|
+
logger.debug(`Created package.json in build directory`);
|
|
48
56
|
|
|
49
57
|
return newPackageData;
|
|
50
58
|
}
|
|
@@ -54,25 +62,24 @@ function createRootPackageFile() {
|
|
|
54
62
|
*
|
|
55
63
|
*/
|
|
56
64
|
function createNestedPackageFiles() {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
ignore: [path.join(buildPath, "cjs/**")],
|
|
65
|
+
const indexPaths = glob.sync(path.join(buildPath, '**/index.js'), {
|
|
66
|
+
ignore: [path.join(buildPath, 'cjs/**')],
|
|
60
67
|
});
|
|
61
68
|
|
|
62
69
|
indexPaths.forEach((indexPath) => {
|
|
63
|
-
if (indexPath === path.join(buildPath,
|
|
70
|
+
if (indexPath === path.join(buildPath, 'index.js')) return;
|
|
64
71
|
const packageData = {
|
|
65
72
|
sideEffects: false,
|
|
66
|
-
module:
|
|
67
|
-
types:
|
|
73
|
+
module: './index.js',
|
|
74
|
+
types: './index.d.ts',
|
|
68
75
|
main: path.relative(
|
|
69
76
|
path.dirname(indexPath),
|
|
70
|
-
indexPath.replace(buildPath, path.join(buildPath,
|
|
77
|
+
indexPath.replace(buildPath, path.join(buildPath, '/cjs'))
|
|
71
78
|
),
|
|
72
79
|
};
|
|
73
80
|
fs.writeFileSync(
|
|
74
|
-
path.join(path.dirname(indexPath),
|
|
75
|
-
JSON.stringify(packageData, null, 2)
|
|
81
|
+
path.join(path.dirname(indexPath), 'package.json'),
|
|
82
|
+
JSON.stringify(packageData, null, 2)
|
|
76
83
|
);
|
|
77
84
|
});
|
|
78
85
|
}
|
|
@@ -84,8 +91,9 @@ function createNestedPackageFiles() {
|
|
|
84
91
|
* @param {string} string - The string to prepend
|
|
85
92
|
*/
|
|
86
93
|
function prepend(file, string) {
|
|
87
|
-
const data = fs.readFileSync(file,
|
|
88
|
-
fs.writeFileSync(file, string + data,
|
|
94
|
+
const data = fs.readFileSync(file, 'utf8');
|
|
95
|
+
fs.writeFileSync(file, string + data, 'utf8');
|
|
96
|
+
logger.debug(`Prepended license to ${file}`);
|
|
89
97
|
}
|
|
90
98
|
|
|
91
99
|
/**
|
|
@@ -94,24 +102,23 @@ function prepend(file, string) {
|
|
|
94
102
|
* @param {object} packageData - The package data
|
|
95
103
|
*/
|
|
96
104
|
function addLicense(packageData) {
|
|
97
|
-
const
|
|
98
|
-
const license = `/** @license Digigov v${packageData["version"]}
|
|
105
|
+
const license = `/** @license Digigov v${packageData['version']}
|
|
99
106
|
*
|
|
100
107
|
* This source code is licensed under the BSD-2-Clause license found in the
|
|
101
108
|
* LICENSE file in the root directory of this source tree.
|
|
102
109
|
*/
|
|
103
110
|
`;
|
|
104
|
-
[
|
|
111
|
+
['./index.js', './index.mjs'].map(async (file) => {
|
|
105
112
|
try {
|
|
106
113
|
prepend(path.resolve(buildPath, file), license);
|
|
107
114
|
} catch (err) {
|
|
108
115
|
if (
|
|
109
|
-
typeof err ===
|
|
116
|
+
typeof err === 'object' &&
|
|
110
117
|
err &&
|
|
111
|
-
|
|
112
|
-
err.code ===
|
|
118
|
+
'code' in err &&
|
|
119
|
+
err.code === 'ENOENT'
|
|
113
120
|
) {
|
|
114
|
-
logger.
|
|
121
|
+
logger.debug(`Skipped license for ${file}`);
|
|
115
122
|
} else {
|
|
116
123
|
throw err;
|
|
117
124
|
}
|
|
@@ -123,14 +130,13 @@ function addLicense(packageData) {
|
|
|
123
130
|
* Create separate index modules for each directory
|
|
124
131
|
*/
|
|
125
132
|
function createSeparateIndexModules() {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
ignore: [path.join(buildPath, "**/index.js")],
|
|
133
|
+
const files = glob.sync(path.join(buildPath, '**/*.js'), {
|
|
134
|
+
ignore: [path.join(buildPath, '**/index.js')],
|
|
129
135
|
});
|
|
130
136
|
|
|
131
137
|
files.forEach((file) => {
|
|
132
|
-
fs.mkdirSync(file.replace(/\.js$/,
|
|
133
|
-
fs.renameSync(file, file.replace(/\.js$/,
|
|
138
|
+
fs.mkdirSync(file.replace(/\.js$/, ''));
|
|
139
|
+
fs.renameSync(file, file.replace(/\.js$/, '/index.js'));
|
|
134
140
|
});
|
|
135
141
|
}
|
|
136
142
|
|
|
@@ -141,14 +147,15 @@ export default function run() {
|
|
|
141
147
|
const packageData = createRootPackageFile();
|
|
142
148
|
createSeparateIndexModules();
|
|
143
149
|
createNestedPackageFiles();
|
|
150
|
+
copyRegistryFilesToSrc();
|
|
144
151
|
|
|
145
152
|
[
|
|
146
153
|
// use enhanced readme from workspace root for `@digigov/ui`
|
|
147
154
|
// packageData.name === '@digigov/ui' ? '../../README.md' : './README.md',
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
].map((file) => includeFileInBuild(file))
|
|
153
|
-
|
|
155
|
+
'./src',
|
|
156
|
+
'./README.md',
|
|
157
|
+
'./CHANGELOG.md',
|
|
158
|
+
'../../LICENSE',
|
|
159
|
+
].map((file) => includeFileInBuild(file));
|
|
160
|
+
addLicense(packageData);
|
|
154
161
|
}
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
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
|
+
/** @typedef {Object} Project - Represents the project to be built
|
|
10
|
+
* @property {string} root - The project root directory
|
|
11
|
+
* @property {string} name - The project name as in package.json
|
|
12
|
+
* @property {string} distDir - The project build directory
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Generate registry file for the given project
|
|
17
|
+
*
|
|
18
|
+
* @param {Project} project - The project object
|
|
19
|
+
* @param {string} [registryFilename="registry.js"] - The name of the registry file
|
|
20
|
+
* @param {string[]} absoluteFilePaths - The absolute paths of the files to include in the registry
|
|
21
|
+
* @returns {Promise<string>} - The path to the generated registry file
|
|
22
|
+
*/
|
|
23
|
+
export async function generateRegistry(
|
|
24
|
+
project,
|
|
25
|
+
absoluteFilePaths,
|
|
26
|
+
registryFilename = 'registry.js'
|
|
27
|
+
) {
|
|
28
|
+
const registryPath = ensureRegistryPath(project, registryFilename);
|
|
29
|
+
|
|
30
|
+
const relativePaths = absoluteFilePaths.map((path) => {
|
|
31
|
+
assert(
|
|
32
|
+
path.startsWith(project.root),
|
|
33
|
+
'Expected path to be in project root'
|
|
34
|
+
);
|
|
35
|
+
return toNodeResolvablePath(
|
|
36
|
+
path.replace(`${project.root}/src/`, `${project.name}/`)
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
let registryPaths = relativePaths.map((path) => ({
|
|
40
|
+
path,
|
|
41
|
+
uid: createUid(path),
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
if (registryPaths.length === 0)
|
|
45
|
+
throw new Error(
|
|
46
|
+
'Could not generate registry. No exportable modules found.'
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const importStatements = registryPaths.map(
|
|
50
|
+
(file) => `import * as ${file.uid} from "${file.path}";`
|
|
51
|
+
);
|
|
52
|
+
const componentsToExport = registryPaths.map(
|
|
53
|
+
(file) => ` '${file.path}': lazyImport(${file.uid})`
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
logger.debug(
|
|
57
|
+
`Including ${componentsToExport.length} items in ${registryPath}`
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
let registryFileContent = `
|
|
61
|
+
${importStatements.join('\n')}
|
|
62
|
+
function lazyImport(pkgImport) {
|
|
63
|
+
return new Proxy(
|
|
64
|
+
{},
|
|
65
|
+
{
|
|
66
|
+
get: (_target, name) => {
|
|
67
|
+
if (name === '__esModule' || name === 'default') {
|
|
68
|
+
return pkgImport.default;
|
|
69
|
+
} else if(
|
|
70
|
+
name === '*'
|
|
71
|
+
) {
|
|
72
|
+
return pkgImport;
|
|
73
|
+
} else {
|
|
74
|
+
return pkgImport[name];
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
export default {
|
|
81
|
+
${componentsToExport.join(',\n')}
|
|
82
|
+
};
|
|
83
|
+
`;
|
|
84
|
+
await fs.writeFile(registryPath, registryFileContent);
|
|
85
|
+
|
|
86
|
+
return registryPath;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Generate a lazy registry file for the given project
|
|
91
|
+
*
|
|
92
|
+
* @param {Project} project - The project object
|
|
93
|
+
* @param {string[]} filePaths - The files whose exports will be included in the lazy registry
|
|
94
|
+
* @param {string} [lazyFilename="lazy.js"] - The name of the registry file
|
|
95
|
+
* @returns {Promise<string>} - The path to the generated lazy registry file
|
|
96
|
+
*/
|
|
97
|
+
export async function generateLazyRegistry(
|
|
98
|
+
project,
|
|
99
|
+
filePaths,
|
|
100
|
+
lazyFilename = 'lazy.js'
|
|
101
|
+
) {
|
|
102
|
+
const lazyPath = ensureRegistryPath(project, lazyFilename);
|
|
103
|
+
|
|
104
|
+
const tsMorphProject = new TsMorphProject({
|
|
105
|
+
tsConfigFilePath: getProjectTsconfig(project.root),
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/** @type {Record<string, string>} */
|
|
109
|
+
let allComponents = {};
|
|
110
|
+
|
|
111
|
+
for (const filePath of filePaths) {
|
|
112
|
+
const sourceFile = tsMorphProject.addSourceFileAtPath(filePath);
|
|
113
|
+
const exports = sourceFile
|
|
114
|
+
.getExportSymbols()
|
|
115
|
+
.filter(isJsExport)
|
|
116
|
+
.map((symbol) => symbol.getName());
|
|
117
|
+
|
|
118
|
+
for (const exportedComponent of exports) {
|
|
119
|
+
if (
|
|
120
|
+
exportedComponent !== 'default' &&
|
|
121
|
+
exportedComponent.match(/^[A-Z]/)
|
|
122
|
+
) {
|
|
123
|
+
if (
|
|
124
|
+
!allComponents[exportedComponent] ||
|
|
125
|
+
allComponents[exportedComponent].length < filePath.length // Make import path more specific
|
|
126
|
+
) {
|
|
127
|
+
allComponents[exportedComponent] = toNodeResolvablePath(
|
|
128
|
+
filePath.replace(`${project.root}/src/`, `${project.name}/`)
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const componentCount = Object.keys(allComponents).length;
|
|
136
|
+
|
|
137
|
+
if (componentCount === 0)
|
|
138
|
+
throw new Error(
|
|
139
|
+
'Could not generate lazy registry. No exportable components found.'
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
logger.debug(`Including ${componentCount} components in ${lazyPath}`);
|
|
143
|
+
|
|
144
|
+
const componentsToExport = Object.entries(allComponents)
|
|
145
|
+
.map(
|
|
146
|
+
([component, filePath]) =>
|
|
147
|
+
` '${component}': lazy(() => import('${filePath}').then((module) => ({ default: module['${component}'] })))`
|
|
148
|
+
)
|
|
149
|
+
.join(',\n');
|
|
150
|
+
|
|
151
|
+
const lazyFileContent = `import { lazy } from 'react';
|
|
152
|
+
export default {
|
|
153
|
+
${componentsToExport}
|
|
154
|
+
};
|
|
155
|
+
`;
|
|
156
|
+
|
|
157
|
+
await fs.writeFile(lazyPath, lazyFileContent);
|
|
158
|
+
|
|
159
|
+
return lazyPath;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Ensure that the registry file does not already exist at the given path
|
|
164
|
+
*
|
|
165
|
+
* @param {Project} project - The project object
|
|
166
|
+
* @param {string} fileName - The name of the registry file
|
|
167
|
+
*/
|
|
168
|
+
function ensureRegistryPath(project, fileName) {
|
|
169
|
+
const registryPath = path.join(project.root, project.distDir, fileName);
|
|
170
|
+
if (fs.existsSync(registryPath))
|
|
171
|
+
throw new Error(`A "${fileName}" file already exists at ${registryPath}.`);
|
|
172
|
+
return registryPath;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Extract a node-resolvable path
|
|
177
|
+
*
|
|
178
|
+
* @param {string} inputPath - The file path
|
|
179
|
+
* @returns {string} - The node-resolvable path
|
|
180
|
+
*/
|
|
181
|
+
function toNodeResolvablePath(inputPath) {
|
|
182
|
+
const dir = path.dirname(inputPath);
|
|
183
|
+
const base = path.basename(inputPath, path.extname(inputPath));
|
|
184
|
+
|
|
185
|
+
return base === 'index' ? dir : path.join(dir, base);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Create a UID from a path
|
|
190
|
+
*
|
|
191
|
+
* @param {string} inputPath - The path
|
|
192
|
+
* @returns {string} - The UID
|
|
193
|
+
*/
|
|
194
|
+
function createUid(inputPath) {
|
|
195
|
+
return inputPath.replace(/[/@\-.]/g, '_');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Check if a symbol is a JS export
|
|
200
|
+
*
|
|
201
|
+
* @param {import("ts-morph").Symbol} symbol - The symbol to check
|
|
202
|
+
*/
|
|
203
|
+
function isJsExport(symbol) {
|
|
204
|
+
const declarations = symbol.getDeclarations();
|
|
205
|
+
return declarations.some((declaration) => {
|
|
206
|
+
const kind = declaration.getKind();
|
|
207
|
+
return (
|
|
208
|
+
kind === SyntaxKind.FunctionDeclaration ||
|
|
209
|
+
kind === SyntaxKind.ClassDeclaration ||
|
|
210
|
+
kind === SyntaxKind.VariableDeclaration ||
|
|
211
|
+
kind === SyntaxKind.ExportSpecifier
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
}
|
package/index.js
CHANGED
|
@@ -1,85 +1,118 @@
|
|
|
1
|
-
import { DigigovCommand, resolveProject } from
|
|
2
|
-
import
|
|
1
|
+
import { DigigovCommand, resolveProject, logger } from '@digigov/cli/lib';
|
|
2
|
+
import { buildFormat, generateTypeDeclarationFiles } from './build.js';
|
|
3
|
+
import { generateLazyRegistry, generateRegistry } from './generate-registry.js';
|
|
4
|
+
import copyFiles from './copy-files.js';
|
|
3
5
|
|
|
4
|
-
import
|
|
5
|
-
import path from
|
|
6
|
-
import
|
|
7
|
-
import
|
|
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';
|
|
8
11
|
|
|
9
|
-
const command = new DigigovCommand(
|
|
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
|
|
16
|
-
await ctx.exec("rimraf", ["dist"]);
|
|
42
|
+
async function main(options, ctx) {
|
|
17
43
|
const project = resolveProject();
|
|
18
44
|
|
|
19
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
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";
|
|
53
|
+
tsconfig = getProjectTsconfig(project.root);
|
|
54
|
+
assert(tsconfig, 'Expected tsconfig to be in project');
|
|
55
|
+
await generateTypeDeclarationFiles(project, tsconfig, ctx);
|
|
70
56
|
}
|
|
71
57
|
|
|
58
|
+
const ignore = [...TEST_GLOBS, ...STORIES_GLOBS];
|
|
59
|
+
const filesToBuild = await glob(path.join(project.root, SRC_GLOB), {
|
|
60
|
+
ignore,
|
|
61
|
+
});
|
|
62
|
+
logger.debug('Bundling ESM and CJS...');
|
|
72
63
|
await Promise.all([
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
buildFormat({
|
|
65
|
+
files: filesToBuild,
|
|
66
|
+
tsconfig: tsconfig,
|
|
67
|
+
format: 'cjs',
|
|
68
|
+
outdir: project.distDir + '/cjs',
|
|
77
69
|
}),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
70
|
+
buildFormat({
|
|
71
|
+
files: filesToBuild,
|
|
72
|
+
tsconfig,
|
|
73
|
+
format: 'esm',
|
|
74
|
+
outdir: project.distDir,
|
|
82
75
|
}),
|
|
83
76
|
]);
|
|
77
|
+
logger.debug('Bundling done.');
|
|
78
|
+
|
|
79
|
+
if (options.generateRegistry) {
|
|
80
|
+
logger.debug('Generating registry files...');
|
|
81
|
+
|
|
82
|
+
const filesToIncludeInRegistry = filesToBuild.filter(
|
|
83
|
+
(file) => !(file.includes('native') || file.endsWith('.d.ts'))
|
|
84
|
+
);
|
|
85
|
+
let storiesFiles = null;
|
|
86
|
+
if (options.includeStories) {
|
|
87
|
+
logger.debug('Including stories in the registry...');
|
|
88
|
+
|
|
89
|
+
storiesFiles = await glob(
|
|
90
|
+
STORIES_GLOBS.map((glob) => path.join(project.root, project.src, glob)),
|
|
91
|
+
{
|
|
92
|
+
ignore: ['**/*.native.*, **/*.d.ts'],
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const [, ...registryFilePaths] = await Promise.all([
|
|
98
|
+
storiesFiles
|
|
99
|
+
? generateRegistry(project, storiesFiles, 'stories-registry.js')
|
|
100
|
+
: null,
|
|
101
|
+
generateRegistry(project, filesToIncludeInRegistry),
|
|
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');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
logger.debug('Copying files to build directory...');
|
|
84
116
|
copyFiles();
|
|
117
|
+
logger.debug('Files copied.');
|
|
85
118
|
}
|
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-107d908d",
|
|
4
4
|
"description": "Build plugin for Digigov CLI",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -8,37 +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
|
-
"@digigov/babel-ts-to-proptypes": "1.1.0-rc.23",
|
|
32
|
-
"babel-plugin-istanbul": "7.0.0",
|
|
33
13
|
"publint": "0.1.8",
|
|
34
14
|
"rimraf": "3.0.2",
|
|
35
|
-
"esbuild": "0.23.0"
|
|
15
|
+
"esbuild": "0.23.0",
|
|
16
|
+
"commander": "12.1.0",
|
|
17
|
+
"ts-morph": "25.0.0"
|
|
36
18
|
},
|
|
37
19
|
"devDependencies": {
|
|
38
|
-
"
|
|
20
|
+
"@digigov/cli": "2.0.0-107d908d",
|
|
21
|
+
"@digigov/cli-lint": "2.0.0-107d908d",
|
|
22
|
+
"publint": "0.1.8",
|
|
23
|
+
"vitest": "2.1.3",
|
|
24
|
+
"@digigov/cli-test": "2.0.0-107d908d",
|
|
25
|
+
"@types/fs-extra": "11.0.4",
|
|
26
|
+
"@types/node": "20.17.24",
|
|
27
|
+
"typescript": "5.6.2",
|
|
28
|
+
"eslint": "9.16.0",
|
|
29
|
+
"prettier": "3.4.2"
|
|
39
30
|
},
|
|
40
31
|
"peerDependencies": {
|
|
41
|
-
"@digigov/cli": "2.0.0-
|
|
32
|
+
"@digigov/cli": "2.0.0-107d908d",
|
|
42
33
|
"next": "13.1.1"
|
|
43
34
|
},
|
|
44
35
|
"peerDependenciesMeta": {
|
|
@@ -47,6 +38,8 @@
|
|
|
47
38
|
}
|
|
48
39
|
},
|
|
49
40
|
"scripts": {
|
|
50
|
-
"publint": "publint"
|
|
41
|
+
"publint": "publint",
|
|
42
|
+
"lint": "digigov lint",
|
|
43
|
+
"typecheck": "tsc"
|
|
51
44
|
}
|
|
52
45
|
}
|
package/tsconfig.base.json
CHANGED
|
@@ -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": [
|