@common-stack/rollup-vite-utils 6.0.8-alpha.52 → 6.0.8-alpha.53
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/tools/codegen/performCopyOperations.cjs +127 -38
- package/lib/tools/codegen/performCopyOperations.cjs.map +1 -1
- package/lib/tools/codegen/performCopyOperations.d.ts +32 -5
- package/lib/tools/codegen/performCopyOperations.js +127 -38
- package/lib/tools/codegen/performCopyOperations.js.map +1 -1
- package/lib/tools/codegen/performCopyOperations.test.d.ts +1 -0
- package/package.json +2 -2
|
@@ -1,65 +1,154 @@
|
|
|
1
|
-
'use strict';var child_process=require('child_process'),fs=require('fs'),path=require('path'),commonPaths=require('./commonPaths.cjs')
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
'use strict';var child_process=require('child_process'),fs=require('fs'),path=require('path'),commonPaths=require('./commonPaths.cjs');/* eslint-disable no-continue */
|
|
2
|
+
/* eslint-disable default-param-last */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
/* eslint-disable guard-for-in */
|
|
5
|
+
/**
|
|
6
|
+
* For each discovered module, if "cdecode.common" is defined in its package.json,
|
|
7
|
+
* copy the files specified under the keys "modules", "services", "repository", and "enums"
|
|
8
|
+
* from the package's template folder into the common package.
|
|
4
9
|
*
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
10
|
+
* For files with the .ts.template extension, the ".template" suffix is removed
|
|
11
|
+
* upon copy so that the destination file is a plain .ts file.
|
|
12
|
+
*
|
|
13
|
+
* Each of these keys is processed into its own destination folder:
|
|
14
|
+
* • common/src/modules/<pkgName>
|
|
15
|
+
* • common/src/services/<pkgName>
|
|
16
|
+
* • common/src/repository/<pkgName>
|
|
17
|
+
* • common/src/enums/<pkgName>
|
|
18
|
+
*
|
|
19
|
+
* An index.ts file is created in each subfolder to re-export the files,
|
|
20
|
+
* and a top-level index file is updated so that the common code (for example,
|
|
21
|
+
* the ApolloContext file) can import the services, repository types, or enums.
|
|
22
|
+
*
|
|
23
|
+
* For folder type "enums", after copying the files per package, an aggregation step
|
|
24
|
+
* groups files by their base file name (e.g. ErrorMessage.ts) and then generates a merged file.
|
|
25
|
+
* The merged file will be created in common/src/enums/ and wrap all enum members in a single
|
|
26
|
+
* export—for example:
|
|
27
|
+
*
|
|
28
|
+
* export enum ErrorMessage {
|
|
29
|
+
* // contents from package1
|
|
30
|
+
* // contents from package2
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* The `options.commandRunner` allows injecting a custom command runner for testability.
|
|
7
34
|
*/
|
|
8
|
-
function performCopyOperations(modules, cdecodePaths = {}) {
|
|
35
|
+
function performCopyOperations(modules, cdecodePaths = {}, options) {
|
|
9
36
|
let { repoRoot, commonPackagePath } = cdecodePaths;
|
|
10
|
-
// Fallback to internal pathsConfig if not provided by user
|
|
11
37
|
if (!repoRoot) {
|
|
12
38
|
repoRoot = commonPaths.pathsConfig.repoRoot;
|
|
13
39
|
}
|
|
14
40
|
if (!commonPackagePath) {
|
|
15
|
-
//
|
|
41
|
+
// For example, "packages/common"
|
|
16
42
|
commonPackagePath = path.join(commonPaths.pathsConfig.repoRoot, 'packages/common');
|
|
17
43
|
}
|
|
18
|
-
|
|
44
|
+
// Use the provided commandRunner or default to execSync.
|
|
45
|
+
const commandRunner = options?.commandRunner || ((cmd) => child_process.execSync(cmd));
|
|
46
|
+
// Define the folder types we want to process.
|
|
47
|
+
const folderTypes = ['modules', 'services', 'repository', 'enums'];
|
|
48
|
+
// Track whether we have added any export for each folder type.
|
|
49
|
+
const shouldAddExportFlag = {
|
|
50
|
+
modules: false,
|
|
51
|
+
services: false,
|
|
52
|
+
repository: false,
|
|
53
|
+
enums: false,
|
|
54
|
+
};
|
|
55
|
+
// For enums we want to merge files across packages.
|
|
56
|
+
// We'll accumulate a list of destination file paths (already renamed to .ts)
|
|
57
|
+
// keyed by their base file name (e.g. "ErrorMessage.ts").
|
|
58
|
+
const enumAggregation = {};
|
|
59
|
+
// Helper: compute final destination file name.
|
|
60
|
+
const getDestinationFileName = (file) => {
|
|
61
|
+
if (file.endsWith('.ts.template')) {
|
|
62
|
+
return file.replace(/\.ts\.template$/, '.ts');
|
|
63
|
+
}
|
|
64
|
+
return file;
|
|
65
|
+
};
|
|
66
|
+
// Helper: compute export name for index generation.
|
|
67
|
+
const getExportName = (file) => {
|
|
68
|
+
const destFileName = getDestinationFileName(file);
|
|
69
|
+
// Remove the .ts extension from the file name.
|
|
70
|
+
return path.basename(destFileName, '.ts');
|
|
71
|
+
};
|
|
19
72
|
for (const modulesObj of modules) {
|
|
20
|
-
// modulesObj
|
|
73
|
+
// modulesObj is expected to be an object like { server, client, etc. }
|
|
21
74
|
for (const moduleName of Object.values(modulesObj)) {
|
|
22
75
|
try {
|
|
23
|
-
|
|
24
|
-
const pkgJsonFilePath = path.join(
|
|
76
|
+
// Read package.json from the package directory.
|
|
77
|
+
const pkgJsonFilePath = path.join(repoRoot, moduleName, 'package.json');
|
|
25
78
|
if (!fs.existsSync(pkgJsonFilePath)) {
|
|
26
79
|
continue;
|
|
27
80
|
}
|
|
28
81
|
const pkgJsonBuffer = fs.readFileSync(pkgJsonFilePath, 'utf-8');
|
|
29
82
|
const pkgJson = JSON.parse(pkgJsonBuffer);
|
|
30
|
-
// If cdecode.common
|
|
83
|
+
// If the package uses cdecode.common then process for each folder type.
|
|
31
84
|
if (pkgJson.cdecode?.common) {
|
|
85
|
+
// Use the package name (falling back to the whole name if expected format is not met)
|
|
32
86
|
const pkgName = (pkgJson.name || '').split('/')[1] || pkgJson.name;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
87
|
+
// Compute the source base for template files.
|
|
88
|
+
// (Assumes that the template files live one directory above the package folder.)
|
|
89
|
+
const sourceBase = path.join(repoRoot, moduleName, '../');
|
|
90
|
+
for (const folderType of folderTypes) {
|
|
91
|
+
const resourceList = pkgJson.cdecode.common[folderType];
|
|
92
|
+
if (!resourceList)
|
|
93
|
+
continue;
|
|
94
|
+
// Destination folder (for example, common/src/modules/dummy-package)
|
|
95
|
+
const directoryPath = path.join(commonPackagePath, 'src', folderType, pkgName);
|
|
96
|
+
commandRunner(`mkdir -p ${directoryPath}`);
|
|
97
|
+
// Copy and rename (if needed) each file.
|
|
98
|
+
resourceList.forEach((file) => {
|
|
99
|
+
const sourceFile = path.join(sourceBase, file);
|
|
100
|
+
const destFileName = getDestinationFileName(file);
|
|
101
|
+
const destination = path.join(directoryPath, destFileName);
|
|
102
|
+
commandRunner(`cp -r ${sourceFile} ${destination}`);
|
|
103
|
+
// For enums, accumulate the destination file for aggregation.
|
|
104
|
+
if (folderType === 'enums') {
|
|
105
|
+
if (!enumAggregation[destFileName]) {
|
|
106
|
+
enumAggregation[destFileName] = [];
|
|
107
|
+
}
|
|
108
|
+
enumAggregation[destFileName].push(destination);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
// Generate index.ts in the destination folder that re-exports each file.
|
|
112
|
+
const exportsContent = resourceList
|
|
113
|
+
.map((file) => `export * from './${getExportName(file)}';`)
|
|
114
|
+
.join('\n');
|
|
115
|
+
commandRunner(`echo "${exportsContent.replace(/"/g, '\\"')}" > ${path.join(directoryPath, 'index.ts')}`);
|
|
116
|
+
// Create (or overwrite) an index.ts in the parent folder of the destination;
|
|
117
|
+
// this index re-exports the package folder so that later an aggregator can import all packages.
|
|
118
|
+
commandRunner(`echo "export * from './${pkgName}';" > ${path.join(directoryPath, '../', 'index.ts')}`);
|
|
119
|
+
shouldAddExportFlag[folderType] = true;
|
|
120
|
+
}
|
|
53
121
|
}
|
|
54
122
|
}
|
|
55
123
|
catch (e) {
|
|
56
|
-
console.error(`Error
|
|
57
|
-
// you can decide to continue or break
|
|
124
|
+
console.error(`Error processing module: ${moduleName}`, e);
|
|
58
125
|
}
|
|
59
126
|
}
|
|
60
127
|
}
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
128
|
+
// For each folder type where any export was added, update the top-level index.
|
|
129
|
+
// For example, append "export * from './modules';" to common/src/index.ts.
|
|
130
|
+
for (const folderType of folderTypes) {
|
|
131
|
+
if (shouldAddExportFlag[folderType]) {
|
|
132
|
+
commandRunner(`echo "export * from './${folderType}';" >> ${path.join(commonPackagePath, 'src', 'index.ts')}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// ----- Enum Aggregation Step -----
|
|
136
|
+
// For enums, we want to merge definitions from all packages into a single file per enum type.
|
|
137
|
+
// The aggregated file will be placed in common/src/enums/<EnumFileName>.
|
|
138
|
+
if (Object.keys(enumAggregation).length > 0) {
|
|
139
|
+
const enumsTargetDir = path.join(commonPackagePath, 'src', 'enums');
|
|
140
|
+
commandRunner(`mkdir -p ${enumsTargetDir}`);
|
|
141
|
+
for (const destFileName in enumAggregation) {
|
|
142
|
+
const baseName = path.basename(destFileName, '.ts'); // e.g., "ErrorMessage"
|
|
143
|
+
const aggregatedFile = path.join(enumsTargetDir, destFileName);
|
|
144
|
+
// Begin the aggregated file with the enum header.
|
|
145
|
+
commandRunner(`echo "export enum ${baseName} {" > ${aggregatedFile}`);
|
|
146
|
+
// Append the contents (enum members) from each package's file.
|
|
147
|
+
enumAggregation[destFileName].forEach((filePath) => {
|
|
148
|
+
commandRunner(`cat ${filePath} >> ${aggregatedFile}`);
|
|
149
|
+
});
|
|
150
|
+
// Close the enum definition.
|
|
151
|
+
commandRunner(`echo "}" >> ${aggregatedFile}`);
|
|
152
|
+
}
|
|
64
153
|
}
|
|
65
154
|
}exports.performCopyOperations=performCopyOperations;//# sourceMappingURL=performCopyOperations.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performCopyOperations.cjs","sources":["../../../src/tools/codegen/performCopyOperations.ts"],"sourcesContent":[null],"names":["pathsConfig","execSync"],"mappings":"
|
|
1
|
+
{"version":3,"file":"performCopyOperations.cjs","sources":["../../../src/tools/codegen/performCopyOperations.ts"],"sourcesContent":[null],"names":["pathsConfig","execSync"],"mappings":"uIAAA;AACA;AACA;AACA;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AACG,SAAU,qBAAqB,CAAC,OAAY,EAAE,YAAe,GAAA,EAAS,EAAE,OAAqB,EAAA;AAC/F,IAAA,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,YAAY,CAAC;IAEnD,IAAI,CAAC,QAAQ,EAAE;AACX,QAAA,QAAQ,GAAGA,uBAAW,CAAC,QAAQ,CAAC;KACnC;IACD,IAAI,CAAC,iBAAiB,EAAE;;QAEpB,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAACA,uBAAW,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;KAC1E;;AAGD,IAAA,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,KAAK,CAAC,GAAW,KAAKC,sBAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;;IAGjF,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;;AAEnE,IAAA,MAAM,mBAAmB,GAA4B;AACjD,QAAA,OAAO,EAAE,KAAK;AACd,QAAA,QAAQ,EAAE,KAAK;AACf,QAAA,UAAU,EAAE,KAAK;AACjB,QAAA,KAAK,EAAE,KAAK;KACf,CAAC;;;;IAKF,MAAM,eAAe,GAA6B,EAAE,CAAC;;AAGrD,IAAA,MAAM,sBAAsB,GAAG,CAAC,IAAY,KAAY;AACpD,QAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE;YAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;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C,CAAC;AAC1D,aAAC,CAAC,CAAC;;AAEH,YAAA,aAAa,CAAC,CAAA,YAAA,EAAe,cAAc,CAAA,CAAE,CAAC,CAAC;SAClD;KACJ;AACL"}
|
|
@@ -1,8 +1,35 @@
|
|
|
1
|
+
export interface CopyOptions {
|
|
2
|
+
/** Overrides the default execSync command runner */
|
|
3
|
+
commandRunner?: (command: string) => void;
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
|
-
* For each discovered module, if "cdecode.common" is
|
|
3
|
-
* the
|
|
6
|
+
* For each discovered module, if "cdecode.common" is defined in its package.json,
|
|
7
|
+
* copy the files specified under the keys "modules", "services", "repository", and "enums"
|
|
8
|
+
* from the package's template folder into the common package.
|
|
4
9
|
*
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
10
|
+
* For files with the .ts.template extension, the ".template" suffix is removed
|
|
11
|
+
* upon copy so that the destination file is a plain .ts file.
|
|
12
|
+
*
|
|
13
|
+
* Each of these keys is processed into its own destination folder:
|
|
14
|
+
* • common/src/modules/<pkgName>
|
|
15
|
+
* • common/src/services/<pkgName>
|
|
16
|
+
* • common/src/repository/<pkgName>
|
|
17
|
+
* • common/src/enums/<pkgName>
|
|
18
|
+
*
|
|
19
|
+
* An index.ts file is created in each subfolder to re-export the files,
|
|
20
|
+
* and a top-level index file is updated so that the common code (for example,
|
|
21
|
+
* the ApolloContext file) can import the services, repository types, or enums.
|
|
22
|
+
*
|
|
23
|
+
* For folder type "enums", after copying the files per package, an aggregation step
|
|
24
|
+
* groups files by their base file name (e.g. ErrorMessage.ts) and then generates a merged file.
|
|
25
|
+
* The merged file will be created in common/src/enums/ and wrap all enum members in a single
|
|
26
|
+
* export—for example:
|
|
27
|
+
*
|
|
28
|
+
* export enum ErrorMessage {
|
|
29
|
+
* // contents from package1
|
|
30
|
+
* // contents from package2
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* The `options.commandRunner` allows injecting a custom command runner for testability.
|
|
7
34
|
*/
|
|
8
|
-
export declare function performCopyOperations(modules: any, cdecodePaths?: any): void;
|
|
35
|
+
export declare function performCopyOperations(modules: any, cdecodePaths?: any, options?: CopyOptions): void;
|
|
@@ -1,65 +1,154 @@
|
|
|
1
|
-
import {execSync}from'child_process';import fs__default from'fs';import path__default from'path';import {pathsConfig}from'./commonPaths.js'
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {execSync}from'child_process';import fs__default from'fs';import path__default from'path';import {pathsConfig}from'./commonPaths.js';/* eslint-disable no-continue */
|
|
2
|
+
/* eslint-disable default-param-last */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
/* eslint-disable guard-for-in */
|
|
5
|
+
/**
|
|
6
|
+
* For each discovered module, if "cdecode.common" is defined in its package.json,
|
|
7
|
+
* copy the files specified under the keys "modules", "services", "repository", and "enums"
|
|
8
|
+
* from the package's template folder into the common package.
|
|
4
9
|
*
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
10
|
+
* For files with the .ts.template extension, the ".template" suffix is removed
|
|
11
|
+
* upon copy so that the destination file is a plain .ts file.
|
|
12
|
+
*
|
|
13
|
+
* Each of these keys is processed into its own destination folder:
|
|
14
|
+
* • common/src/modules/<pkgName>
|
|
15
|
+
* • common/src/services/<pkgName>
|
|
16
|
+
* • common/src/repository/<pkgName>
|
|
17
|
+
* • common/src/enums/<pkgName>
|
|
18
|
+
*
|
|
19
|
+
* An index.ts file is created in each subfolder to re-export the files,
|
|
20
|
+
* and a top-level index file is updated so that the common code (for example,
|
|
21
|
+
* the ApolloContext file) can import the services, repository types, or enums.
|
|
22
|
+
*
|
|
23
|
+
* For folder type "enums", after copying the files per package, an aggregation step
|
|
24
|
+
* groups files by their base file name (e.g. ErrorMessage.ts) and then generates a merged file.
|
|
25
|
+
* The merged file will be created in common/src/enums/ and wrap all enum members in a single
|
|
26
|
+
* export—for example:
|
|
27
|
+
*
|
|
28
|
+
* export enum ErrorMessage {
|
|
29
|
+
* // contents from package1
|
|
30
|
+
* // contents from package2
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* The `options.commandRunner` allows injecting a custom command runner for testability.
|
|
7
34
|
*/
|
|
8
|
-
function performCopyOperations(modules, cdecodePaths = {}) {
|
|
35
|
+
function performCopyOperations(modules, cdecodePaths = {}, options) {
|
|
9
36
|
let { repoRoot, commonPackagePath } = cdecodePaths;
|
|
10
|
-
// Fallback to internal pathsConfig if not provided by user
|
|
11
37
|
if (!repoRoot) {
|
|
12
38
|
repoRoot = pathsConfig.repoRoot;
|
|
13
39
|
}
|
|
14
40
|
if (!commonPackagePath) {
|
|
15
|
-
//
|
|
41
|
+
// For example, "packages/common"
|
|
16
42
|
commonPackagePath = path__default.join(pathsConfig.repoRoot, 'packages/common');
|
|
17
43
|
}
|
|
18
|
-
|
|
44
|
+
// Use the provided commandRunner or default to execSync.
|
|
45
|
+
const commandRunner = options?.commandRunner || ((cmd) => execSync(cmd));
|
|
46
|
+
// Define the folder types we want to process.
|
|
47
|
+
const folderTypes = ['modules', 'services', 'repository', 'enums'];
|
|
48
|
+
// Track whether we have added any export for each folder type.
|
|
49
|
+
const shouldAddExportFlag = {
|
|
50
|
+
modules: false,
|
|
51
|
+
services: false,
|
|
52
|
+
repository: false,
|
|
53
|
+
enums: false,
|
|
54
|
+
};
|
|
55
|
+
// For enums we want to merge files across packages.
|
|
56
|
+
// We'll accumulate a list of destination file paths (already renamed to .ts)
|
|
57
|
+
// keyed by their base file name (e.g. "ErrorMessage.ts").
|
|
58
|
+
const enumAggregation = {};
|
|
59
|
+
// Helper: compute final destination file name.
|
|
60
|
+
const getDestinationFileName = (file) => {
|
|
61
|
+
if (file.endsWith('.ts.template')) {
|
|
62
|
+
return file.replace(/\.ts\.template$/, '.ts');
|
|
63
|
+
}
|
|
64
|
+
return file;
|
|
65
|
+
};
|
|
66
|
+
// Helper: compute export name for index generation.
|
|
67
|
+
const getExportName = (file) => {
|
|
68
|
+
const destFileName = getDestinationFileName(file);
|
|
69
|
+
// Remove the .ts extension from the file name.
|
|
70
|
+
return path__default.basename(destFileName, '.ts');
|
|
71
|
+
};
|
|
19
72
|
for (const modulesObj of modules) {
|
|
20
|
-
// modulesObj
|
|
73
|
+
// modulesObj is expected to be an object like { server, client, etc. }
|
|
21
74
|
for (const moduleName of Object.values(modulesObj)) {
|
|
22
75
|
try {
|
|
23
|
-
|
|
24
|
-
const pkgJsonFilePath = path__default.join(
|
|
76
|
+
// Read package.json from the package directory.
|
|
77
|
+
const pkgJsonFilePath = path__default.join(repoRoot, moduleName, 'package.json');
|
|
25
78
|
if (!fs__default.existsSync(pkgJsonFilePath)) {
|
|
26
79
|
continue;
|
|
27
80
|
}
|
|
28
81
|
const pkgJsonBuffer = fs__default.readFileSync(pkgJsonFilePath, 'utf-8');
|
|
29
82
|
const pkgJson = JSON.parse(pkgJsonBuffer);
|
|
30
|
-
// If cdecode.common
|
|
83
|
+
// If the package uses cdecode.common then process for each folder type.
|
|
31
84
|
if (pkgJson.cdecode?.common) {
|
|
85
|
+
// Use the package name (falling back to the whole name if expected format is not met)
|
|
32
86
|
const pkgName = (pkgJson.name || '').split('/')[1] || pkgJson.name;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
87
|
+
// Compute the source base for template files.
|
|
88
|
+
// (Assumes that the template files live one directory above the package folder.)
|
|
89
|
+
const sourceBase = path__default.join(repoRoot, moduleName, '../');
|
|
90
|
+
for (const folderType of folderTypes) {
|
|
91
|
+
const resourceList = pkgJson.cdecode.common[folderType];
|
|
92
|
+
if (!resourceList)
|
|
93
|
+
continue;
|
|
94
|
+
// Destination folder (for example, common/src/modules/dummy-package)
|
|
95
|
+
const directoryPath = path__default.join(commonPackagePath, 'src', folderType, pkgName);
|
|
96
|
+
commandRunner(`mkdir -p ${directoryPath}`);
|
|
97
|
+
// Copy and rename (if needed) each file.
|
|
98
|
+
resourceList.forEach((file) => {
|
|
99
|
+
const sourceFile = path__default.join(sourceBase, file);
|
|
100
|
+
const destFileName = getDestinationFileName(file);
|
|
101
|
+
const destination = path__default.join(directoryPath, destFileName);
|
|
102
|
+
commandRunner(`cp -r ${sourceFile} ${destination}`);
|
|
103
|
+
// For enums, accumulate the destination file for aggregation.
|
|
104
|
+
if (folderType === 'enums') {
|
|
105
|
+
if (!enumAggregation[destFileName]) {
|
|
106
|
+
enumAggregation[destFileName] = [];
|
|
107
|
+
}
|
|
108
|
+
enumAggregation[destFileName].push(destination);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
// Generate index.ts in the destination folder that re-exports each file.
|
|
112
|
+
const exportsContent = resourceList
|
|
113
|
+
.map((file) => `export * from './${getExportName(file)}';`)
|
|
114
|
+
.join('\n');
|
|
115
|
+
commandRunner(`echo "${exportsContent.replace(/"/g, '\\"')}" > ${path__default.join(directoryPath, 'index.ts')}`);
|
|
116
|
+
// Create (or overwrite) an index.ts in the parent folder of the destination;
|
|
117
|
+
// this index re-exports the package folder so that later an aggregator can import all packages.
|
|
118
|
+
commandRunner(`echo "export * from './${pkgName}';" > ${path__default.join(directoryPath, '../', 'index.ts')}`);
|
|
119
|
+
shouldAddExportFlag[folderType] = true;
|
|
120
|
+
}
|
|
53
121
|
}
|
|
54
122
|
}
|
|
55
123
|
catch (e) {
|
|
56
|
-
console.error(`Error
|
|
57
|
-
// you can decide to continue or break
|
|
124
|
+
console.error(`Error processing module: ${moduleName}`, e);
|
|
58
125
|
}
|
|
59
126
|
}
|
|
60
127
|
}
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
128
|
+
// For each folder type where any export was added, update the top-level index.
|
|
129
|
+
// For example, append "export * from './modules';" to common/src/index.ts.
|
|
130
|
+
for (const folderType of folderTypes) {
|
|
131
|
+
if (shouldAddExportFlag[folderType]) {
|
|
132
|
+
commandRunner(`echo "export * from './${folderType}';" >> ${path__default.join(commonPackagePath, 'src', 'index.ts')}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// ----- Enum Aggregation Step -----
|
|
136
|
+
// For enums, we want to merge definitions from all packages into a single file per enum type.
|
|
137
|
+
// The aggregated file will be placed in common/src/enums/<EnumFileName>.
|
|
138
|
+
if (Object.keys(enumAggregation).length > 0) {
|
|
139
|
+
const enumsTargetDir = path__default.join(commonPackagePath, 'src', 'enums');
|
|
140
|
+
commandRunner(`mkdir -p ${enumsTargetDir}`);
|
|
141
|
+
for (const destFileName in enumAggregation) {
|
|
142
|
+
const baseName = path__default.basename(destFileName, '.ts'); // e.g., "ErrorMessage"
|
|
143
|
+
const aggregatedFile = path__default.join(enumsTargetDir, destFileName);
|
|
144
|
+
// Begin the aggregated file with the enum header.
|
|
145
|
+
commandRunner(`echo "export enum ${baseName} {" > ${aggregatedFile}`);
|
|
146
|
+
// Append the contents (enum members) from each package's file.
|
|
147
|
+
enumAggregation[destFileName].forEach((filePath) => {
|
|
148
|
+
commandRunner(`cat ${filePath} >> ${aggregatedFile}`);
|
|
149
|
+
});
|
|
150
|
+
// Close the enum definition.
|
|
151
|
+
commandRunner(`echo "}" >> ${aggregatedFile}`);
|
|
152
|
+
}
|
|
64
153
|
}
|
|
65
154
|
}export{performCopyOperations};//# sourceMappingURL=performCopyOperations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performCopyOperations.js","sources":["../../../src/tools/codegen/performCopyOperations.ts"],"sourcesContent":[null],"names":["path","fs"],"mappings":"
|
|
1
|
+
{"version":3,"file":"performCopyOperations.js","sources":["../../../src/tools/codegen/performCopyOperations.ts"],"sourcesContent":[null],"names":["path","fs"],"mappings":"4IAAA;AACA;AACA;AACA;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AACG,SAAU,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version": "6.0.8-alpha.
|
|
3
|
+
"version": "6.0.8-alpha.53",
|
|
4
4
|
"description": "Client Module for react app",
|
|
5
5
|
"homepage": "https://github.com/cdmbase/fullstack-pro#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "96cdaea57d3640f35908dbc138dde2a57635614e",
|
|
61
61
|
"typescript": {
|
|
62
62
|
"definition": "lib/index.d.ts"
|
|
63
63
|
}
|