@common-stack/rollup-vite-utils 6.0.8-alpha.7 → 7.0.2-alpha.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.
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -1
- package/lib/preStartup/configLoader/envLoader.cjs +1 -1
- package/lib/preStartup/configLoader/envLoader.cjs.map +1 -1
- package/lib/preStartup/configLoader/envLoader.js +1 -1
- package/lib/preStartup/configLoader/envLoader.js.map +1 -1
- package/lib/rollup/index.d.ts +1 -0
- package/lib/rollup/rollupPluginCamelcaseSvg.cjs +24 -0
- package/lib/rollup/rollupPluginCamelcaseSvg.cjs.map +1 -0
- package/lib/rollup/rollupPluginCamelcaseSvg.d.ts +8 -0
- package/lib/rollup/rollupPluginCamelcaseSvg.js +24 -0
- package/lib/rollup/rollupPluginCamelcaseSvg.js.map +1 -0
- package/lib/tools/codegen/commonPaths.cjs +20 -0
- package/lib/tools/codegen/commonPaths.cjs.map +1 -0
- package/lib/tools/codegen/commonPaths.d.ts +19 -0
- package/lib/tools/codegen/commonPaths.js +20 -0
- package/lib/tools/codegen/commonPaths.js.map +1 -0
- package/lib/tools/codegen/computeModules.cjs +47 -0
- package/lib/tools/codegen/computeModules.cjs.map +1 -0
- package/lib/tools/codegen/computeModules.d.ts +10 -0
- package/lib/tools/codegen/computeModules.js +47 -0
- package/lib/tools/codegen/computeModules.js.map +1 -0
- package/lib/tools/codegen/generateCodegenConfig.cjs +96 -0
- package/lib/tools/codegen/generateCodegenConfig.cjs.map +1 -0
- package/lib/tools/codegen/generateCodegenConfig.d.ts +16 -0
- package/lib/tools/codegen/generateCodegenConfig.js +96 -0
- package/lib/tools/codegen/generateCodegenConfig.js.map +1 -0
- package/lib/tools/codegen/generateCodegenConfig.test.d.ts +1 -0
- package/lib/tools/codegen/index.cjs +14 -0
- package/lib/tools/codegen/index.cjs.map +1 -0
- package/lib/tools/codegen/index.d.ts +5 -0
- package/lib/tools/codegen/index.js +14 -0
- package/lib/tools/codegen/index.js.map +1 -0
- package/lib/tools/codegen/modulePathParser.d.ts +56 -0
- package/lib/tools/codegen/performCopyOperations.cjs +236 -0
- package/lib/tools/codegen/performCopyOperations.cjs.map +1 -0
- package/lib/tools/codegen/performCopyOperations.d.ts +27 -0
- package/lib/tools/codegen/performCopyOperations.js +236 -0
- package/lib/tools/codegen/performCopyOperations.js.map +1 -0
- package/lib/tools/codegen/performCopyOperations.test.d.ts +1 -0
- package/lib/tools/codegen/readModules.cjs +249 -0
- package/lib/tools/codegen/readModules.cjs.map +1 -0
- package/lib/tools/codegen/readModules.d.ts +33 -0
- package/lib/tools/codegen/readModules.js +249 -0
- package/lib/tools/codegen/readModules.js.map +1 -0
- package/lib/tools/codegen/readModules.test.d.ts +1 -0
- package/lib/tools/codegen/setupCommonPackage.cjs +61 -0
- package/lib/tools/codegen/setupCommonPackage.cjs.map +1 -0
- package/lib/tools/codegen/setupCommonPackage.d.ts +12 -0
- package/lib/tools/codegen/setupCommonPackage.js +61 -0
- package/lib/tools/codegen/setupCommonPackage.js.map +1 -0
- package/lib/tools/codegen/templates/common/.npmignore.template +2 -0
- package/lib/tools/codegen/templates/common/package.json.template +25 -0
- package/lib/tools/codegen/templates/common/rollup.config.mjs.template +34 -0
- package/lib/tools/codegen/templates/common/src/apollo-context.ts.template +64 -0
- package/lib/tools/codegen/templates/common/src/configuration.ts.template +37 -0
- package/lib/tools/codegen/templates/common/src/generated/generated-models.ts.template +1 -0
- package/lib/tools/codegen/templates/common/src/index.ts.template +5 -0
- package/lib/tools/codegen/templates/common/src/permissions.ts.template +5 -0
- package/lib/tools/codegen/templates/common/src/types.ts.template +42 -0
- package/lib/tools/codegen/templates/common/tsconfig.json.template +16 -0
- package/lib/tools/index.d.ts +1 -0
- package/lib/utils/utils.cjs +21 -14
- package/lib/utils/utils.cjs.map +1 -1
- package/lib/utils/utils.d.ts +9 -3
- package/lib/utils/utils.js +21 -14
- package/lib/utils/utils.js.map +1 -1
- package/lib/vite-wrappers/generators/serverQueryLoaderGenerator.cjs +1 -1
- package/lib/vite-wrappers/generators/serverQueryLoaderGenerator.js +1 -1
- package/lib/vite-wrappers/json-wrappers.cjs +1 -0
- package/lib/vite-wrappers/json-wrappers.cjs.map +1 -1
- package/lib/vite-wrappers/json-wrappers.js +1 -0
- package/lib/vite-wrappers/json-wrappers.js.map +1 -1
- package/lib/vite-wrappers/wrapperComponent.cjs +9 -2
- package/lib/vite-wrappers/wrapperComponent.cjs.map +1 -1
- package/lib/vite-wrappers/wrapperComponent.js +9 -2
- package/lib/vite-wrappers/wrapperComponent.js.map +1 -1
- package/package.json +8 -6
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
'use strict';var fs=require('fs'),path=require('path'),module$1=require('module'),commonPaths=require('./commonPaths.cjs');var_documentCurrentScript=typeofdocument!=='undefined'?document.currentScript:null;// ESM-compatible require
|
|
2
|
+
const esmRequire = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('tools/codegen/readModules.cjs', document.baseURI).href)));
|
|
3
|
+
/**
|
|
4
|
+
* For local modules, if the relative path ends with "lib",
|
|
5
|
+
* remove that segment so that the package root is used.
|
|
6
|
+
*/
|
|
7
|
+
function normalizeLocalBase(modulePath) {
|
|
8
|
+
const parts = modulePath.split(path.sep);
|
|
9
|
+
if (parts[parts.length - 1] === 'lib') {
|
|
10
|
+
parts.pop();
|
|
11
|
+
}
|
|
12
|
+
return parts.join(path.sep);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* For variant local modules, strip off a trailing role folder (if present)
|
|
16
|
+
* so that the group name equals the package base.
|
|
17
|
+
* E.g. "packages-modules/mail-campaign/browser" becomes "packages-modules/mail-campaign".
|
|
18
|
+
*/
|
|
19
|
+
function getInternalGroupName(modName) {
|
|
20
|
+
const segments = modName.split(path.sep);
|
|
21
|
+
const variants = ['server', 'client', 'browser', 'core'];
|
|
22
|
+
if (segments.length && variants.includes(segments[segments.length - 1])) {
|
|
23
|
+
segments.pop();
|
|
24
|
+
}
|
|
25
|
+
return segments.join(path.sep);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Determines if a module is external by checking if its computed name starts with "node_modules".
|
|
29
|
+
* (This approach does not rely on any hard-coded vendor-specific package name prefixes.)
|
|
30
|
+
*/
|
|
31
|
+
function isExternalModule(mod) {
|
|
32
|
+
return mod.name.split(path.sep)[0] === 'node_modules';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Transforms the collected module definitions into the desired final output format.
|
|
36
|
+
*
|
|
37
|
+
* - External modules:
|
|
38
|
+
* • If the module name contains "-browser", output an object with keys "browser", "client" and "core".
|
|
39
|
+
* The client and core are computed by replacing the "-browser" suffix with "-client" and "-core" respectively.
|
|
40
|
+
* • Else if the name ends with "-server", output an object with key "server".
|
|
41
|
+
* • Otherwise, output an object with key "independent".
|
|
42
|
+
*
|
|
43
|
+
* - Internal (local) modules:
|
|
44
|
+
* • If the module is flagged as independent (flat, no variant indicated), output an object with key "independent"
|
|
45
|
+
* that points to `<baseModule>/src`.
|
|
46
|
+
* • Otherwise (when flagged as variant) group them by their normalized base and output a single object containing
|
|
47
|
+
* four keys: client, core, browser, and server (e.g. `<groupName>/client/src`, etc.).
|
|
48
|
+
*/
|
|
49
|
+
function transformModules(modules) {
|
|
50
|
+
const finalOutput = [];
|
|
51
|
+
const variantGroups = new Map();
|
|
52
|
+
modules.forEach((mod) => {
|
|
53
|
+
if (isExternalModule(mod)) {
|
|
54
|
+
// External modules: check if the computed name indicates a browser variant.
|
|
55
|
+
if (mod.name.includes('-browser')) {
|
|
56
|
+
// Remove only the trailing "-browser" occurrence to compute client/core names.
|
|
57
|
+
const base = mod.name.replace(/-browser$/, '');
|
|
58
|
+
finalOutput.push({
|
|
59
|
+
client: `${base}-client/lib`,
|
|
60
|
+
core: `${base}-core/lib`,
|
|
61
|
+
browser: `${base}-browser/lib`,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else if (mod.name.endsWith('-server')) {
|
|
65
|
+
finalOutput.push({ server: `${mod.name}/lib` });
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
finalOutput.push({ independent: `${mod.name}/lib` });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Internal (local) modules.
|
|
73
|
+
if (mod.isIndependentLocal) {
|
|
74
|
+
finalOutput.push({ independent: `${mod.name}/src` });
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const groupName = getInternalGroupName(mod.name);
|
|
78
|
+
if (!variantGroups.has(groupName)) {
|
|
79
|
+
variantGroups.set(groupName, {
|
|
80
|
+
client: `${groupName}/client/src`,
|
|
81
|
+
core: `${groupName}/core/src`,
|
|
82
|
+
browser: `${groupName}/browser/src`,
|
|
83
|
+
server: `${groupName}/server/src`,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return [...finalOutput, ...Array.from(variantGroups.values())];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Reads modules from one or more JSON config files (e.g., cdecode-config.json) and returns an array,
|
|
93
|
+
* transformed into the final desired output format of module objects.
|
|
94
|
+
*
|
|
95
|
+
* The processing steps are:
|
|
96
|
+
* 1. Load module names (from keys such as modules, externalModules, devModules) from each config.
|
|
97
|
+
* 2. Deduplicate the raw module names.
|
|
98
|
+
* 3. For each raw module string, attempt to resolve it using esmRequire.resolve (with fallback).
|
|
99
|
+
* 4. Compute the module's base folder relative to the repository root.
|
|
100
|
+
* 5. Determine if the module is local (i.e. does not live in node_modules).
|
|
101
|
+
* 6. For local modules, decide whether it is "variant" (if the raw config string indicates "-browser" or "-server")
|
|
102
|
+
* or independent (if not).
|
|
103
|
+
* 7. Optionally, if a package.json exists, adjust the server path using its "main" field.
|
|
104
|
+
* 8. Finally, transform the processed definitions into the desired output format.
|
|
105
|
+
*
|
|
106
|
+
* @param {string[]} configPaths - Array of configuration file paths.
|
|
107
|
+
* @returns {any[]} Final processed module objects.
|
|
108
|
+
*/
|
|
109
|
+
function readModules(configPaths = []) {
|
|
110
|
+
const rawModuleSet = new Set();
|
|
111
|
+
// Collect raw module names from all config files.
|
|
112
|
+
configPaths.forEach((configFile) => {
|
|
113
|
+
if (!fs.existsSync(configFile)) {
|
|
114
|
+
console.error(`Config file not found: ${configFile}`);
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
const configData = JSON.parse(fs.readFileSync(configFile, 'utf-8'));
|
|
118
|
+
(configData.modules || []).forEach((mod) => rawModuleSet.add(mod));
|
|
119
|
+
(configData.externalModules || []).forEach((mod) => rawModuleSet.add(mod));
|
|
120
|
+
(configData.devModules || []).forEach((mod) => rawModuleSet.add(mod));
|
|
121
|
+
});
|
|
122
|
+
const collectedModules = [];
|
|
123
|
+
// Process each unique raw module.
|
|
124
|
+
rawModuleSet.forEach((rawStr) => {
|
|
125
|
+
try {
|
|
126
|
+
// Determine if the raw config string suggests a variant module.
|
|
127
|
+
const isVariant = rawStr.includes('-browser') || rawStr.endsWith('-server');
|
|
128
|
+
let resolvedFile;
|
|
129
|
+
try {
|
|
130
|
+
// Primary resolution: try to resolve directly to package.json.
|
|
131
|
+
resolvedFile = esmRequire.resolve(path.join(rawStr, 'package.json'));
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
// If resolution fails, try to use error file details.
|
|
135
|
+
if (err && typeof err === 'object' && 'path' in err && typeof err.path === 'string') {
|
|
136
|
+
let filePath = err.path;
|
|
137
|
+
// Check if the file path includes a "/lib/" segment.
|
|
138
|
+
const libSegment = `${path.sep}lib${path.sep}`;
|
|
139
|
+
const libIndex = filePath.indexOf(libSegment);
|
|
140
|
+
if (libIndex !== -1) {
|
|
141
|
+
// Remove the lib folder and what follows, then append package.json.
|
|
142
|
+
filePath = filePath.slice(0, libIndex);
|
|
143
|
+
filePath = path.join(filePath, 'package.json');
|
|
144
|
+
}
|
|
145
|
+
if (fs.existsSync(filePath)) {
|
|
146
|
+
resolvedFile = filePath;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
// Fallback: if the error-derived path fails, remove "/lib" from the raw string.
|
|
150
|
+
const fallbackModule = rawStr.includes('/lib') ? rawStr.replace(/\/lib.*$/, '') : rawStr;
|
|
151
|
+
try {
|
|
152
|
+
resolvedFile = esmRequire.resolve(path.join(fallbackModule, 'package.json'));
|
|
153
|
+
}
|
|
154
|
+
catch (err2) {
|
|
155
|
+
console.warn(`Could not resolve module ${rawStr} even with fallback ${fallbackModule}. Skipping.`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
// Fallback resolution if error object doesn't contain a path.
|
|
162
|
+
const fallbackModule = rawStr.includes('/lib') ? rawStr.replace(/\/lib.*$/, '') : rawStr;
|
|
163
|
+
try {
|
|
164
|
+
resolvedFile = esmRequire.resolve(path.join(fallbackModule, 'package.json'));
|
|
165
|
+
}
|
|
166
|
+
catch (err2) {
|
|
167
|
+
console.warn(`Could not resolve module ${rawStr} even with fallback ${fallbackModule}. Skipping.`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const dirName = path.dirname(resolvedFile);
|
|
173
|
+
// Compute the folder path relative to the repository root.
|
|
174
|
+
const modulePathRaw = path.relative(commonPaths.pathsConfig.repoRoot, dirName);
|
|
175
|
+
const isLocal = !modulePathRaw.split(path.sep).includes('node_modules');
|
|
176
|
+
const baseModule = isLocal ? normalizeLocalBase(modulePathRaw) : modulePathRaw.replace(/\/lib.*/, '');
|
|
177
|
+
// Avoid duplicates based on the computed base.
|
|
178
|
+
if (collectedModules.find((m) => m.name === baseModule))
|
|
179
|
+
return;
|
|
180
|
+
const srcOrLib = isLocal ? 'src' : 'lib';
|
|
181
|
+
// Start a module definition.
|
|
182
|
+
const moduleDef = { raw: rawStr, name: baseModule };
|
|
183
|
+
if (!isLocal) {
|
|
184
|
+
// External modules.
|
|
185
|
+
if (rawStr.includes('-browser')) {
|
|
186
|
+
// For external variants, look for client and core as well.
|
|
187
|
+
moduleDef.browser = `${baseModule}/${srcOrLib}`;
|
|
188
|
+
// Replace only the trailing "-browser" for client/core.
|
|
189
|
+
moduleDef.client = `${baseModule.replace(/-browser$/, '-client')}/${srcOrLib}`;
|
|
190
|
+
moduleDef.core = `${baseModule.replace(/-browser$/, '-core')}/${srcOrLib}`;
|
|
191
|
+
}
|
|
192
|
+
else if (rawStr.endsWith('-server')) {
|
|
193
|
+
moduleDef.server = `${baseModule}/${srcOrLib}`;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
moduleDef.server = `${baseModule}/${srcOrLib}`;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
// Local (internal) modules.
|
|
201
|
+
if (isVariant) {
|
|
202
|
+
if (rawStr.includes('-browser')) {
|
|
203
|
+
// For variant local modules with -browser, expect subfolders for browser, client, core and server.
|
|
204
|
+
moduleDef.browser = `${baseModule}/browser/${srcOrLib}`;
|
|
205
|
+
moduleDef.client = `${baseModule}/client/${srcOrLib}`;
|
|
206
|
+
moduleDef.core = `${baseModule}/core/${srcOrLib}`;
|
|
207
|
+
moduleDef.server = `${baseModule}/server/${srcOrLib}`;
|
|
208
|
+
}
|
|
209
|
+
else if (rawStr.endsWith('-server')) {
|
|
210
|
+
moduleDef.server = `${baseModule}/server/${srcOrLib}`;
|
|
211
|
+
}
|
|
212
|
+
moduleDef.isVariant = true;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
// Independent local package with a flat structure.
|
|
216
|
+
moduleDef.server = `${baseModule}/src`;
|
|
217
|
+
moduleDef.isIndependentLocal = true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Optionally, if package.json exists, adjust the server path using its "main" field.
|
|
221
|
+
let packageJsonPath;
|
|
222
|
+
if (isLocal) {
|
|
223
|
+
packageJsonPath = path.join(commonPaths.pathsConfig.repoRoot, baseModule, 'package.json');
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
packageJsonPath = path.join('node_modules', baseModule, 'package.json');
|
|
227
|
+
}
|
|
228
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
229
|
+
try {
|
|
230
|
+
const pkgContent = fs.readFileSync(packageJsonPath, 'utf-8');
|
|
231
|
+
const pkg = JSON.parse(pkgContent);
|
|
232
|
+
if (pkg.main) {
|
|
233
|
+
moduleDef.server = pkg.main.replace(/\.js$/, `/${srcOrLib}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
console.error(`Error reading package.json for ${baseModule}:`, error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
collectedModules.push(moduleDef);
|
|
241
|
+
}
|
|
242
|
+
catch (e) {
|
|
243
|
+
console.error('Error while processing module:', rawStr, e);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
// Transform the intermediate definitions into the final output format.
|
|
247
|
+
const finalOutput = transformModules(collectedModules);
|
|
248
|
+
return finalOutput;
|
|
249
|
+
}exports.readModules=readModules;//# sourceMappingURL=readModules.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readModules.cjs","sources":["../../../src/tools/codegen/readModules.ts"],"sourcesContent":[null],"names":["createRequire","pathsConfig"],"mappings":"8MAMA;AACA,MAAM,UAAU,GAAGA,sBAAa,CAAC,+QAAe,CAAC,CAAC;AAkBlD;;;AAGG;AACH,SAAS,kBAAkB,CAAC,UAAkB,EAAA;IAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,KAAK,CAAC,KAAK,CAAC,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AAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;SAC9D;AACL,KAAC,CAAC,CAAC;;AAGH,IAAA,MAAM,WAAW,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;AACvD,IAAA,OAAO,WAAW,CAAC;AACvB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal module definition.
|
|
3
|
+
* Note: The extra properties "raw", "isVariant" and "isIndependentLocal" are used only during processing.
|
|
4
|
+
*/
|
|
5
|
+
export interface ModuleDefinition {
|
|
6
|
+
raw?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
server?: string;
|
|
9
|
+
browser?: string;
|
|
10
|
+
client?: string;
|
|
11
|
+
core?: string;
|
|
12
|
+
isVariant?: boolean;
|
|
13
|
+
isIndependentLocal?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Reads modules from one or more JSON config files (e.g., cdecode-config.json) and returns an array,
|
|
17
|
+
* transformed into the final desired output format of module objects.
|
|
18
|
+
*
|
|
19
|
+
* The processing steps are:
|
|
20
|
+
* 1. Load module names (from keys such as modules, externalModules, devModules) from each config.
|
|
21
|
+
* 2. Deduplicate the raw module names.
|
|
22
|
+
* 3. For each raw module string, attempt to resolve it using esmRequire.resolve (with fallback).
|
|
23
|
+
* 4. Compute the module's base folder relative to the repository root.
|
|
24
|
+
* 5. Determine if the module is local (i.e. does not live in node_modules).
|
|
25
|
+
* 6. For local modules, decide whether it is "variant" (if the raw config string indicates "-browser" or "-server")
|
|
26
|
+
* or independent (if not).
|
|
27
|
+
* 7. Optionally, if a package.json exists, adjust the server path using its "main" field.
|
|
28
|
+
* 8. Finally, transform the processed definitions into the desired output format.
|
|
29
|
+
*
|
|
30
|
+
* @param {string[]} configPaths - Array of configuration file paths.
|
|
31
|
+
* @returns {any[]} Final processed module objects.
|
|
32
|
+
*/
|
|
33
|
+
export declare function readModules(configPaths?: string[]): any[];
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import fs__default from'fs';import path__default from'path';import {createRequire}from'module';import {pathsConfig}from'./commonPaths.js';// ESM-compatible require
|
|
2
|
+
const esmRequire = createRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* For local modules, if the relative path ends with "lib",
|
|
5
|
+
* remove that segment so that the package root is used.
|
|
6
|
+
*/
|
|
7
|
+
function normalizeLocalBase(modulePath) {
|
|
8
|
+
const parts = modulePath.split(path__default.sep);
|
|
9
|
+
if (parts[parts.length - 1] === 'lib') {
|
|
10
|
+
parts.pop();
|
|
11
|
+
}
|
|
12
|
+
return parts.join(path__default.sep);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* For variant local modules, strip off a trailing role folder (if present)
|
|
16
|
+
* so that the group name equals the package base.
|
|
17
|
+
* E.g. "packages-modules/mail-campaign/browser" becomes "packages-modules/mail-campaign".
|
|
18
|
+
*/
|
|
19
|
+
function getInternalGroupName(modName) {
|
|
20
|
+
const segments = modName.split(path__default.sep);
|
|
21
|
+
const variants = ['server', 'client', 'browser', 'core'];
|
|
22
|
+
if (segments.length && variants.includes(segments[segments.length - 1])) {
|
|
23
|
+
segments.pop();
|
|
24
|
+
}
|
|
25
|
+
return segments.join(path__default.sep);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Determines if a module is external by checking if its computed name starts with "node_modules".
|
|
29
|
+
* (This approach does not rely on any hard-coded vendor-specific package name prefixes.)
|
|
30
|
+
*/
|
|
31
|
+
function isExternalModule(mod) {
|
|
32
|
+
return mod.name.split(path__default.sep)[0] === 'node_modules';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Transforms the collected module definitions into the desired final output format.
|
|
36
|
+
*
|
|
37
|
+
* - External modules:
|
|
38
|
+
* • If the module name contains "-browser", output an object with keys "browser", "client" and "core".
|
|
39
|
+
* The client and core are computed by replacing the "-browser" suffix with "-client" and "-core" respectively.
|
|
40
|
+
* • Else if the name ends with "-server", output an object with key "server".
|
|
41
|
+
* • Otherwise, output an object with key "independent".
|
|
42
|
+
*
|
|
43
|
+
* - Internal (local) modules:
|
|
44
|
+
* • If the module is flagged as independent (flat, no variant indicated), output an object with key "independent"
|
|
45
|
+
* that points to `<baseModule>/src`.
|
|
46
|
+
* • Otherwise (when flagged as variant) group them by their normalized base and output a single object containing
|
|
47
|
+
* four keys: client, core, browser, and server (e.g. `<groupName>/client/src`, etc.).
|
|
48
|
+
*/
|
|
49
|
+
function transformModules(modules) {
|
|
50
|
+
const finalOutput = [];
|
|
51
|
+
const variantGroups = new Map();
|
|
52
|
+
modules.forEach((mod) => {
|
|
53
|
+
if (isExternalModule(mod)) {
|
|
54
|
+
// External modules: check if the computed name indicates a browser variant.
|
|
55
|
+
if (mod.name.includes('-browser')) {
|
|
56
|
+
// Remove only the trailing "-browser" occurrence to compute client/core names.
|
|
57
|
+
const base = mod.name.replace(/-browser$/, '');
|
|
58
|
+
finalOutput.push({
|
|
59
|
+
client: `${base}-client/lib`,
|
|
60
|
+
core: `${base}-core/lib`,
|
|
61
|
+
browser: `${base}-browser/lib`,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else if (mod.name.endsWith('-server')) {
|
|
65
|
+
finalOutput.push({ server: `${mod.name}/lib` });
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
finalOutput.push({ independent: `${mod.name}/lib` });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Internal (local) modules.
|
|
73
|
+
if (mod.isIndependentLocal) {
|
|
74
|
+
finalOutput.push({ independent: `${mod.name}/src` });
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const groupName = getInternalGroupName(mod.name);
|
|
78
|
+
if (!variantGroups.has(groupName)) {
|
|
79
|
+
variantGroups.set(groupName, {
|
|
80
|
+
client: `${groupName}/client/src`,
|
|
81
|
+
core: `${groupName}/core/src`,
|
|
82
|
+
browser: `${groupName}/browser/src`,
|
|
83
|
+
server: `${groupName}/server/src`,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return [...finalOutput, ...Array.from(variantGroups.values())];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Reads modules from one or more JSON config files (e.g., cdecode-config.json) and returns an array,
|
|
93
|
+
* transformed into the final desired output format of module objects.
|
|
94
|
+
*
|
|
95
|
+
* The processing steps are:
|
|
96
|
+
* 1. Load module names (from keys such as modules, externalModules, devModules) from each config.
|
|
97
|
+
* 2. Deduplicate the raw module names.
|
|
98
|
+
* 3. For each raw module string, attempt to resolve it using esmRequire.resolve (with fallback).
|
|
99
|
+
* 4. Compute the module's base folder relative to the repository root.
|
|
100
|
+
* 5. Determine if the module is local (i.e. does not live in node_modules).
|
|
101
|
+
* 6. For local modules, decide whether it is "variant" (if the raw config string indicates "-browser" or "-server")
|
|
102
|
+
* or independent (if not).
|
|
103
|
+
* 7. Optionally, if a package.json exists, adjust the server path using its "main" field.
|
|
104
|
+
* 8. Finally, transform the processed definitions into the desired output format.
|
|
105
|
+
*
|
|
106
|
+
* @param {string[]} configPaths - Array of configuration file paths.
|
|
107
|
+
* @returns {any[]} Final processed module objects.
|
|
108
|
+
*/
|
|
109
|
+
function readModules(configPaths = []) {
|
|
110
|
+
const rawModuleSet = new Set();
|
|
111
|
+
// Collect raw module names from all config files.
|
|
112
|
+
configPaths.forEach((configFile) => {
|
|
113
|
+
if (!fs__default.existsSync(configFile)) {
|
|
114
|
+
console.error(`Config file not found: ${configFile}`);
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
const configData = JSON.parse(fs__default.readFileSync(configFile, 'utf-8'));
|
|
118
|
+
(configData.modules || []).forEach((mod) => rawModuleSet.add(mod));
|
|
119
|
+
(configData.externalModules || []).forEach((mod) => rawModuleSet.add(mod));
|
|
120
|
+
(configData.devModules || []).forEach((mod) => rawModuleSet.add(mod));
|
|
121
|
+
});
|
|
122
|
+
const collectedModules = [];
|
|
123
|
+
// Process each unique raw module.
|
|
124
|
+
rawModuleSet.forEach((rawStr) => {
|
|
125
|
+
try {
|
|
126
|
+
// Determine if the raw config string suggests a variant module.
|
|
127
|
+
const isVariant = rawStr.includes('-browser') || rawStr.endsWith('-server');
|
|
128
|
+
let resolvedFile;
|
|
129
|
+
try {
|
|
130
|
+
// Primary resolution: try to resolve directly to package.json.
|
|
131
|
+
resolvedFile = esmRequire.resolve(path__default.join(rawStr, 'package.json'));
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
// If resolution fails, try to use error file details.
|
|
135
|
+
if (err && typeof err === 'object' && 'path' in err && typeof err.path === 'string') {
|
|
136
|
+
let filePath = err.path;
|
|
137
|
+
// Check if the file path includes a "/lib/" segment.
|
|
138
|
+
const libSegment = `${path__default.sep}lib${path__default.sep}`;
|
|
139
|
+
const libIndex = filePath.indexOf(libSegment);
|
|
140
|
+
if (libIndex !== -1) {
|
|
141
|
+
// Remove the lib folder and what follows, then append package.json.
|
|
142
|
+
filePath = filePath.slice(0, libIndex);
|
|
143
|
+
filePath = path__default.join(filePath, 'package.json');
|
|
144
|
+
}
|
|
145
|
+
if (fs__default.existsSync(filePath)) {
|
|
146
|
+
resolvedFile = filePath;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
// Fallback: if the error-derived path fails, remove "/lib" from the raw string.
|
|
150
|
+
const fallbackModule = rawStr.includes('/lib') ? rawStr.replace(/\/lib.*$/, '') : rawStr;
|
|
151
|
+
try {
|
|
152
|
+
resolvedFile = esmRequire.resolve(path__default.join(fallbackModule, 'package.json'));
|
|
153
|
+
}
|
|
154
|
+
catch (err2) {
|
|
155
|
+
console.warn(`Could not resolve module ${rawStr} even with fallback ${fallbackModule}. Skipping.`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
// Fallback resolution if error object doesn't contain a path.
|
|
162
|
+
const fallbackModule = rawStr.includes('/lib') ? rawStr.replace(/\/lib.*$/, '') : rawStr;
|
|
163
|
+
try {
|
|
164
|
+
resolvedFile = esmRequire.resolve(path__default.join(fallbackModule, 'package.json'));
|
|
165
|
+
}
|
|
166
|
+
catch (err2) {
|
|
167
|
+
console.warn(`Could not resolve module ${rawStr} even with fallback ${fallbackModule}. Skipping.`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const dirName = path__default.dirname(resolvedFile);
|
|
173
|
+
// Compute the folder path relative to the repository root.
|
|
174
|
+
const modulePathRaw = path__default.relative(pathsConfig.repoRoot, dirName);
|
|
175
|
+
const isLocal = !modulePathRaw.split(path__default.sep).includes('node_modules');
|
|
176
|
+
const baseModule = isLocal ? normalizeLocalBase(modulePathRaw) : modulePathRaw.replace(/\/lib.*/, '');
|
|
177
|
+
// Avoid duplicates based on the computed base.
|
|
178
|
+
if (collectedModules.find((m) => m.name === baseModule))
|
|
179
|
+
return;
|
|
180
|
+
const srcOrLib = isLocal ? 'src' : 'lib';
|
|
181
|
+
// Start a module definition.
|
|
182
|
+
const moduleDef = { raw: rawStr, name: baseModule };
|
|
183
|
+
if (!isLocal) {
|
|
184
|
+
// External modules.
|
|
185
|
+
if (rawStr.includes('-browser')) {
|
|
186
|
+
// For external variants, look for client and core as well.
|
|
187
|
+
moduleDef.browser = `${baseModule}/${srcOrLib}`;
|
|
188
|
+
// Replace only the trailing "-browser" for client/core.
|
|
189
|
+
moduleDef.client = `${baseModule.replace(/-browser$/, '-client')}/${srcOrLib}`;
|
|
190
|
+
moduleDef.core = `${baseModule.replace(/-browser$/, '-core')}/${srcOrLib}`;
|
|
191
|
+
}
|
|
192
|
+
else if (rawStr.endsWith('-server')) {
|
|
193
|
+
moduleDef.server = `${baseModule}/${srcOrLib}`;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
moduleDef.server = `${baseModule}/${srcOrLib}`;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
// Local (internal) modules.
|
|
201
|
+
if (isVariant) {
|
|
202
|
+
if (rawStr.includes('-browser')) {
|
|
203
|
+
// For variant local modules with -browser, expect subfolders for browser, client, core and server.
|
|
204
|
+
moduleDef.browser = `${baseModule}/browser/${srcOrLib}`;
|
|
205
|
+
moduleDef.client = `${baseModule}/client/${srcOrLib}`;
|
|
206
|
+
moduleDef.core = `${baseModule}/core/${srcOrLib}`;
|
|
207
|
+
moduleDef.server = `${baseModule}/server/${srcOrLib}`;
|
|
208
|
+
}
|
|
209
|
+
else if (rawStr.endsWith('-server')) {
|
|
210
|
+
moduleDef.server = `${baseModule}/server/${srcOrLib}`;
|
|
211
|
+
}
|
|
212
|
+
moduleDef.isVariant = true;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
// Independent local package with a flat structure.
|
|
216
|
+
moduleDef.server = `${baseModule}/src`;
|
|
217
|
+
moduleDef.isIndependentLocal = true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Optionally, if package.json exists, adjust the server path using its "main" field.
|
|
221
|
+
let packageJsonPath;
|
|
222
|
+
if (isLocal) {
|
|
223
|
+
packageJsonPath = path__default.join(pathsConfig.repoRoot, baseModule, 'package.json');
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
packageJsonPath = path__default.join('node_modules', baseModule, 'package.json');
|
|
227
|
+
}
|
|
228
|
+
if (fs__default.existsSync(packageJsonPath)) {
|
|
229
|
+
try {
|
|
230
|
+
const pkgContent = fs__default.readFileSync(packageJsonPath, 'utf-8');
|
|
231
|
+
const pkg = JSON.parse(pkgContent);
|
|
232
|
+
if (pkg.main) {
|
|
233
|
+
moduleDef.server = pkg.main.replace(/\.js$/, `/${srcOrLib}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
console.error(`Error reading package.json for ${baseModule}:`, error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
collectedModules.push(moduleDef);
|
|
241
|
+
}
|
|
242
|
+
catch (e) {
|
|
243
|
+
console.error('Error while processing module:', rawStr, e);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
// Transform the intermediate definitions into the final output format.
|
|
247
|
+
const finalOutput = transformModules(collectedModules);
|
|
248
|
+
return finalOutput;
|
|
249
|
+
}export{readModules};//# sourceMappingURL=readModules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readModules.js","sources":["../../../src/tools/codegen/readModules.ts"],"sourcesContent":[null],"names":["path","fs"],"mappings":"0IAMA;AACA,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAkBlD;;;AAGG;AACH,SAAS,kBAAkB,CAAC,UAAkB,EAAA;IAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAACA,aAAI,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,KAAK,EAAE;QACnC,KAAK,CAAC,GAAG,EAAE,CAAC;KACf;IACD,OAAO,KAAK,CAAC,IAAI,CAACA,aAAI,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC;AAED;;;;AAIG;AACH,SAAS,oBAAoB,CAAC,OAAe,EAAA;IACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAACA,aAAI,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;AACzD,IAAA,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE;QACrE,QAAQ,CAAC,GAAG,EAAE,CAAC;KAClB;IACD,OAAO,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E,cAAc,CAAC,CAAC;aAC3E;AACD,YAAA,IAAIC,WAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;AAChC,gBAAA,IAAI;oBACA,MAAM,UAAU,GAAGA,WAAE,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;oBAC7D,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AACnC,oBAAA,IAAI,GAAG,CAAC,IAAI,EAAE;AACV,wBAAA,SAAS,CAAC,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAE,CAAC,CAAC;qBAChE;iBACJ;gBAAC,OAAO,KAAK,EAAE;oBACZ,OAAO,CAAC,KAAK,CAAC,CAAA,+BAAA,EAAkC,UAAU,CAAG,CAAA,CAAA,EAAE,KAAK,CAAC,CAAC;iBACzE;aACJ;AAED,YAAA,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SACpC;QAAC,OAAO,CAAC,EAAE;YACR,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;SAC9D;AACL,KAAC,CAAC,CAAC;;AAGH,IAAA,MAAM,WAAW,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;AACvD,IAAA,OAAO,WAAW,CAAC;AACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';var fs=require('fs-extra'),path=require('path'),url=require('url');var_documentCurrentScript=typeofdocument!=='undefined'?document.currentScript:null;const currentFilename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('tools/codegen/setupCommonPackage.cjs', document.baseURI).href)));
|
|
2
|
+
const currentDirname = path.dirname(currentFilename);
|
|
3
|
+
/**
|
|
4
|
+
* Strips template extension from filename
|
|
5
|
+
* @param filename Original filename like 'index.ts.template' or 'package.json.tpl'
|
|
6
|
+
* @returns Filename without template extension
|
|
7
|
+
*/
|
|
8
|
+
function stripTemplateExtension(filename) {
|
|
9
|
+
return filename.replace(/\.(template|tpl)$/, '');
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Recursively rename ".template" or ".tpl" files to their stripped names.
|
|
13
|
+
*/
|
|
14
|
+
function renameTemplateFilesSync(dirPath) {
|
|
15
|
+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
16
|
+
for (const entry of entries) {
|
|
17
|
+
const entryPath = path.join(dirPath, entry.name);
|
|
18
|
+
if (entry.isDirectory()) {
|
|
19
|
+
renameTemplateFilesSync(entryPath);
|
|
20
|
+
}
|
|
21
|
+
else if (entry.name.endsWith('.template') || entry.name.endsWith('.tpl')) {
|
|
22
|
+
const newPath = path.join(dirPath, stripTemplateExtension(entry.name));
|
|
23
|
+
fs.moveSync(entryPath, newPath, { overwrite: true });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Clears and re-creates the "common" package directory,
|
|
29
|
+
* then copies the template content there.
|
|
30
|
+
*
|
|
31
|
+
* Provide optional projectPaths to override defaults.
|
|
32
|
+
*/
|
|
33
|
+
function setupCommonPackage(projectPaths = {}) {
|
|
34
|
+
// Default template path, if none provided in projectPaths
|
|
35
|
+
const templatePath = projectPaths.templateCommonDir
|
|
36
|
+
? path.resolve(projectPaths.templateCommonDir)
|
|
37
|
+
: path.join(currentDirname, 'templates/common');
|
|
38
|
+
// Default "common" package output, if none provided
|
|
39
|
+
const commonPackagePath = projectPaths.commonPackageDir
|
|
40
|
+
? path.resolve(projectPaths.commonPackageDir)
|
|
41
|
+
: path.join(process.cwd(), 'packages/common');
|
|
42
|
+
console.log('--- Debug Info (setupCommonPackage) ---');
|
|
43
|
+
console.log('templatePath:', templatePath);
|
|
44
|
+
console.log('commonPackagePath:', commonPackagePath);
|
|
45
|
+
// 1) Remove existing directory
|
|
46
|
+
fs.removeSync(commonPackagePath);
|
|
47
|
+
// 2) Recreate it
|
|
48
|
+
fs.ensureDirSync(commonPackagePath);
|
|
49
|
+
// 3) Copy template into it
|
|
50
|
+
if (!fs.existsSync(templatePath)) {
|
|
51
|
+
console.error(`Template path not found: ${templatePath}`);
|
|
52
|
+
console.error('Check your config or directory layout.');
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
fs.copySync(templatePath, commonPackagePath, {
|
|
56
|
+
overwrite: true,
|
|
57
|
+
});
|
|
58
|
+
// 4) Recursively rename all ".template" or ".tpl" files
|
|
59
|
+
renameTemplateFilesSync(commonPackagePath);
|
|
60
|
+
console.log('Module generated from template!');
|
|
61
|
+
}exports.setupCommonPackage=setupCommonPackage;//# sourceMappingURL=setupCommonPackage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupCommonPackage.cjs","sources":["../../../src/tools/codegen/setupCommonPackage.ts"],"sourcesContent":[null],"names":["fileURLToPath"],"mappings":"mKAUA,MAAM,eAAe,GAAGA,iBAAa,CAAC,sRAAe,CAAC,CAAC;AACvD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;AAErD;;;;AAIG;AACH,SAAS,sBAAsB,CAAC,QAAgB,EAAA;IAC5C,OAAO,QAAQ,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;AACrD,CAAC;AAED;;AAEG;AACH,SAAS,uBAAuB,CAAC,OAAe,EAAA;AAC5C,IAAA,MAAM,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;AACjE,IAAA,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE;AACzB,QAAA,MAAM,SAAS,GAAG,IAAI,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,EAAE,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;;IAGpC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;AAC9B,QAAA,OAAO,CAAC,KAAK,CAAC,4BAA4B,YAAY,CAAA,CAAE,CAAC,CAAC;AAC1D,QAAA,OAAO,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;AACxD,QAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;AAED,IAAA,EAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,iBAAiB,EAAE;AACzC,QAAA,SAAS,EAAE,IAAI;AAClB,KAAA,CAAC,CAAC;;IAGH,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;AAE3C,IAAA,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AACnD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface ProjectPaths {
|
|
2
|
+
templateCommonDir?: string;
|
|
3
|
+
commonPackageDir?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Clears and re-creates the "common" package directory,
|
|
7
|
+
* then copies the template content there.
|
|
8
|
+
*
|
|
9
|
+
* Provide optional projectPaths to override defaults.
|
|
10
|
+
*/
|
|
11
|
+
export declare function setupCommonPackage(projectPaths?: ProjectPaths): void;
|
|
12
|
+
export {};
|