@common-stack/rollup-vite-utils 6.0.8-alpha.24 → 6.0.8-alpha.26
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/tools/codegen/commonPaths.cjs +20 -0
- package/lib/tools/codegen/commonPaths.cjs.map +1 -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.js +47 -0
- package/lib/tools/codegen/computeModules.js.map +1 -0
- package/lib/tools/codegen/generateCodegenConfig.cjs +81 -0
- package/lib/tools/codegen/generateCodegenConfig.cjs.map +1 -0
- package/lib/tools/codegen/generateCodegenConfig.js +81 -0
- package/lib/tools/codegen/generateCodegenConfig.js.map +1 -0
- package/lib/tools/codegen/index.cjs +14 -0
- package/lib/tools/codegen/index.cjs.map +1 -0
- package/lib/tools/codegen/index.js +14 -0
- package/lib/tools/codegen/index.js.map +1 -0
- package/lib/tools/codegen/performCopyOperations.cjs +65 -0
- package/lib/tools/codegen/performCopyOperations.cjs.map +1 -0
- package/lib/tools/codegen/performCopyOperations.js +65 -0
- package/lib/tools/codegen/performCopyOperations.js.map +1 -0
- package/lib/tools/codegen/readModules.cjs +106 -0
- package/lib/tools/codegen/readModules.cjs.map +1 -0
- package/lib/tools/codegen/readModules.js +106 -0
- package/lib/tools/codegen/readModules.js.map +1 -0
- package/lib/tools/codegen/setupCommonPackage.cjs +73 -0
- package/lib/tools/codegen/setupCommonPackage.cjs.map +1 -0
- package/lib/tools/codegen/setupCommonPackage.d.ts +7 -2
- package/lib/tools/codegen/setupCommonPackage.js +73 -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 +32 -0
- package/lib/tools/codegen/templates/common/src/{apollo-context.d.ts → apollo-context.ts.template} +8 -9
- package/lib/tools/codegen/templates/common/src/{configuration.d.ts → configuration.ts.template} +9 -9
- package/lib/tools/codegen/templates/common/src/generated/generated-models.ts.template +1 -0
- package/lib/tools/codegen/templates/common/tsconfig.json.template +18 -0
- package/package.json +2 -2
- package/lib/tools/codegen/templates/common/src/generated/generated-models.d.ts +0 -1
- /package/lib/tools/codegen/templates/common/src/{index.d.ts → index.ts.template} +0 -0
package/lib/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var wrapperComponent=require('./vite-wrappers/wrapperComponent.cjs'),jsonWrappers=require('./vite-wrappers/json-wrappers.cjs'),customRoutes=require('./vite-wrappers/custom-routes.cjs'),resourceParams=require('./vite-wrappers/generators/utils/resourceParams.cjs'),pickConfig=require('./vite-wrappers/generators/utils/pickConfig.cjs'),rollupPluginGenerateJson=require('./rollup/rollupPluginGenerateJson.cjs'),rollupPluginModifyLibFiles=require('./rollup/rollupPluginModifyLibFiles.cjs'),rollupPluginAddJsExtension=require('./rollup/rollupPluginAddJsExtension.cjs'),pluginIgnore=require('./rollup/pluginIgnore.cjs'),rollupPluginUpdateFromConfig=require('./rollup/rollupPluginUpdateFromConfig.cjs'),rollupPluginCamelcaseSvg=require('./rollup/rollupPluginCamelcaseSvg.cjs'),copyIfVersionChanged=require('./preStartup/copyIfVersionChanged.cjs');require('./preStartup/configLoader/index.cjs');var i18nInternationalizationPlugin=require('./vite-plugins/i18n-internationalization-plugin.cjs'),vitePluginVirutalImports=require('./vite-plugins/vite-plugin-virutal-imports.cjs'),utils=require('./utils/utils.cjs'),withErrorHandleUtil=require('./utils/withErrorHandleUtil.cjs'),setupConfig=require('./utils/setupConfig.cjs'),verifyConfig=require('./utils/verifyConfig.cjs'),configLoader=require('./preStartup/configLoader/configLoader.cjs'),envLoader=require('./preStartup/configLoader/envLoader.cjs');exports.getRootPath=wrapperComponent.getRootPath;exports.wrapRouteComponent=wrapperComponent.wrapRouteComponent;exports.defineRoutesConfig=jsonWrappers.defineRoutesConfig;exports.getHash=jsonWrappers.getHash;exports.loadRoutesConfig=jsonWrappers.loadRoutesConfig;exports.resolvePathsUsingPackages=jsonWrappers.resolvePathsUsingPackages;exports.createDummyFile=customRoutes.createDummyFile;exports.generateRoute=customRoutes.generateRoute;exports.resolveResourceParamsPlaceholders=resourceParams.resolveResourceParamsPlaceholders;exports.pickValues=pickConfig.pickValues;exports.d=rollupPluginGenerateJson;exports.k=rollupPluginModifyLibFiles;exports.l=rollupPluginAddJsExtension;exports.m=pluginIgnore;exports.updateFromConfig=rollupPluginUpdateFromConfig.updateFromConfig;exports.c=rollupPluginCamelcaseSvg;exports.copyIfVersionChanged=copyIfVersionChanged.copyIfVersionChanged;exports.i18nInternationalizationPlugin=i18nInternationalizationPlugin.i18nInternationalizationPlugin;exports.virtualImportsPlugin=vitePluginVirutalImports.virtualImportsPlugin;exports.findPackageDir=utils.findPackageDir;exports.generateBackendModulesFile=utils.generateBackendModulesFile;exports.generateModulesFile=utils.generateModulesFile;exports.getMetadata=utils.getMetadata;exports.getPackageVersion=utils.getPackageVersion;exports.resolveModulesPath=utils.resolveModulesPath;exports.updateMetadata=utils.updateMetadata;exports.writeBackendModuleFile=utils.writeBackendModuleFile;exports.writeModuleFile=utils.writeModuleFile;exports.withErrorHandler=withErrorHandleUtil.withErrorHandler;exports.setupConfig=setupConfig.setupConfig;exports.verifyConfigSchema=verifyConfig.verifyConfigSchema;exports.performCopyOperations=configLoader.performCopyOperations;exports.resolveConfigPaths=configLoader.resolveConfigPaths;exports.loadEnvConfig=envLoader.loadEnvConfig;//# sourceMappingURL=index.cjs.map
|
|
1
|
+
'use strict';var wrapperComponent=require('./vite-wrappers/wrapperComponent.cjs'),jsonWrappers=require('./vite-wrappers/json-wrappers.cjs'),customRoutes=require('./vite-wrappers/custom-routes.cjs'),resourceParams=require('./vite-wrappers/generators/utils/resourceParams.cjs'),pickConfig=require('./vite-wrappers/generators/utils/pickConfig.cjs'),rollupPluginGenerateJson=require('./rollup/rollupPluginGenerateJson.cjs'),rollupPluginModifyLibFiles=require('./rollup/rollupPluginModifyLibFiles.cjs'),rollupPluginAddJsExtension=require('./rollup/rollupPluginAddJsExtension.cjs'),pluginIgnore=require('./rollup/pluginIgnore.cjs'),rollupPluginUpdateFromConfig=require('./rollup/rollupPluginUpdateFromConfig.cjs'),rollupPluginCamelcaseSvg=require('./rollup/rollupPluginCamelcaseSvg.cjs'),copyIfVersionChanged=require('./preStartup/copyIfVersionChanged.cjs');require('./preStartup/configLoader/index.cjs');var i18nInternationalizationPlugin=require('./vite-plugins/i18n-internationalization-plugin.cjs'),vitePluginVirutalImports=require('./vite-plugins/vite-plugin-virutal-imports.cjs'),utils=require('./utils/utils.cjs'),withErrorHandleUtil=require('./utils/withErrorHandleUtil.cjs'),setupConfig=require('./utils/setupConfig.cjs'),verifyConfig=require('./utils/verifyConfig.cjs'),index=require('./tools/codegen/index.cjs'),configLoader=require('./preStartup/configLoader/configLoader.cjs'),envLoader=require('./preStartup/configLoader/envLoader.cjs');exports.getRootPath=wrapperComponent.getRootPath;exports.wrapRouteComponent=wrapperComponent.wrapRouteComponent;exports.defineRoutesConfig=jsonWrappers.defineRoutesConfig;exports.getHash=jsonWrappers.getHash;exports.loadRoutesConfig=jsonWrappers.loadRoutesConfig;exports.resolvePathsUsingPackages=jsonWrappers.resolvePathsUsingPackages;exports.createDummyFile=customRoutes.createDummyFile;exports.generateRoute=customRoutes.generateRoute;exports.resolveResourceParamsPlaceholders=resourceParams.resolveResourceParamsPlaceholders;exports.pickValues=pickConfig.pickValues;exports.d=rollupPluginGenerateJson;exports.k=rollupPluginModifyLibFiles;exports.l=rollupPluginAddJsExtension;exports.m=pluginIgnore;exports.updateFromConfig=rollupPluginUpdateFromConfig.updateFromConfig;exports.c=rollupPluginCamelcaseSvg;exports.copyIfVersionChanged=copyIfVersionChanged.copyIfVersionChanged;exports.i18nInternationalizationPlugin=i18nInternationalizationPlugin.i18nInternationalizationPlugin;exports.virtualImportsPlugin=vitePluginVirutalImports.virtualImportsPlugin;exports.findPackageDir=utils.findPackageDir;exports.generateBackendModulesFile=utils.generateBackendModulesFile;exports.generateModulesFile=utils.generateModulesFile;exports.getMetadata=utils.getMetadata;exports.getPackageVersion=utils.getPackageVersion;exports.resolveModulesPath=utils.resolveModulesPath;exports.updateMetadata=utils.updateMetadata;exports.writeBackendModuleFile=utils.writeBackendModuleFile;exports.writeModuleFile=utils.writeModuleFile;exports.withErrorHandler=withErrorHandleUtil.withErrorHandler;exports.setupConfig=setupConfig.setupConfig;exports.verifyConfigSchema=verifyConfig.verifyConfigSchema;exports.runCodegenTasks=index.runCodegenTasks;exports.performCopyOperations=configLoader.performCopyOperations;exports.resolveConfigPaths=configLoader.resolveConfigPaths;exports.loadEnvConfig=envLoader.loadEnvConfig;//# sourceMappingURL=index.cjs.map
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{getRootPath,wrapRouteComponent}from'./vite-wrappers/wrapperComponent.js';export{defineRoutesConfig,getHash,loadRoutesConfig,resolvePathsUsingPackages}from'./vite-wrappers/json-wrappers.js';export{createDummyFile,generateRoute}from'./vite-wrappers/custom-routes.js';export{resolveResourceParamsPlaceholders}from'./vite-wrappers/generators/utils/resourceParams.js';export{pickValues}from'./vite-wrappers/generators/utils/pickConfig.js';import*as rollupPluginGenerateJson from'./rollup/rollupPluginGenerateJson.js';export{rollupPluginGenerateJson as d };import*as rollupPluginModifyLibFiles from'./rollup/rollupPluginModifyLibFiles.js';export{rollupPluginModifyLibFiles as k };import*as rollupPluginAddJsExtension from'./rollup/rollupPluginAddJsExtension.js';export{rollupPluginAddJsExtension as l };import*as pluginIgnore from'./rollup/pluginIgnore.js';export{pluginIgnore as m };export{updateFromConfig}from'./rollup/rollupPluginUpdateFromConfig.js';import*as rollupPluginCamelcaseSvg from'./rollup/rollupPluginCamelcaseSvg.js';export{rollupPluginCamelcaseSvg as c };export{copyIfVersionChanged}from'./preStartup/copyIfVersionChanged.js';import'./preStartup/configLoader/index.js';export{i18nInternationalizationPlugin}from'./vite-plugins/i18n-internationalization-plugin.js';export{virtualImportsPlugin}from'./vite-plugins/vite-plugin-virutal-imports.js';export{findPackageDir,generateBackendModulesFile,generateModulesFile,getMetadata,getPackageVersion,resolveModulesPath,updateMetadata,writeBackendModuleFile,writeModuleFile}from'./utils/utils.js';export{withErrorHandler}from'./utils/withErrorHandleUtil.js';export{setupConfig}from'./utils/setupConfig.js';export{verifyConfigSchema}from'./utils/verifyConfig.js';export{performCopyOperations,resolveConfigPaths}from'./preStartup/configLoader/configLoader.js';export{loadEnvConfig}from'./preStartup/configLoader/envLoader.js';//# sourceMappingURL=index.js.map
|
|
1
|
+
export{getRootPath,wrapRouteComponent}from'./vite-wrappers/wrapperComponent.js';export{defineRoutesConfig,getHash,loadRoutesConfig,resolvePathsUsingPackages}from'./vite-wrappers/json-wrappers.js';export{createDummyFile,generateRoute}from'./vite-wrappers/custom-routes.js';export{resolveResourceParamsPlaceholders}from'./vite-wrappers/generators/utils/resourceParams.js';export{pickValues}from'./vite-wrappers/generators/utils/pickConfig.js';import*as rollupPluginGenerateJson from'./rollup/rollupPluginGenerateJson.js';export{rollupPluginGenerateJson as d };import*as rollupPluginModifyLibFiles from'./rollup/rollupPluginModifyLibFiles.js';export{rollupPluginModifyLibFiles as k };import*as rollupPluginAddJsExtension from'./rollup/rollupPluginAddJsExtension.js';export{rollupPluginAddJsExtension as l };import*as pluginIgnore from'./rollup/pluginIgnore.js';export{pluginIgnore as m };export{updateFromConfig}from'./rollup/rollupPluginUpdateFromConfig.js';import*as rollupPluginCamelcaseSvg from'./rollup/rollupPluginCamelcaseSvg.js';export{rollupPluginCamelcaseSvg as c };export{copyIfVersionChanged}from'./preStartup/copyIfVersionChanged.js';import'./preStartup/configLoader/index.js';export{i18nInternationalizationPlugin}from'./vite-plugins/i18n-internationalization-plugin.js';export{virtualImportsPlugin}from'./vite-plugins/vite-plugin-virutal-imports.js';export{findPackageDir,generateBackendModulesFile,generateModulesFile,getMetadata,getPackageVersion,resolveModulesPath,updateMetadata,writeBackendModuleFile,writeModuleFile}from'./utils/utils.js';export{withErrorHandler}from'./utils/withErrorHandleUtil.js';export{setupConfig}from'./utils/setupConfig.js';export{verifyConfigSchema}from'./utils/verifyConfig.js';export{runCodegenTasks}from'./tools/codegen/index.js';export{performCopyOperations,resolveConfigPaths}from'./preStartup/configLoader/configLoader.js';export{loadEnvConfig}from'./preStartup/configLoader/envLoader.js';//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';var path=require('path');require('fs');var url=require('url');var_documentCurrentScript=typeofdocument!=='undefined'?document.currentScript:null;const __filename_ = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('tools/codegen/commonPaths.cjs', document.baseURI).href)));
|
|
2
|
+
const __dirname_ = path.dirname(__filename_);
|
|
3
|
+
/**
|
|
4
|
+
* If your folder structure is:
|
|
5
|
+
* adminIde-stack/
|
|
6
|
+
* └── tools/
|
|
7
|
+
* └── codegen/
|
|
8
|
+
* └── commonPaths.mjs
|
|
9
|
+
*
|
|
10
|
+
* Going two levels up from codegen => adminIde-stack/
|
|
11
|
+
*/
|
|
12
|
+
const pathsConfig = {
|
|
13
|
+
// The location of this file
|
|
14
|
+
__filename: __filename_,
|
|
15
|
+
__dirname: __dirname_,
|
|
16
|
+
// Points to adminIde-stack. Adjust if needed (e.g., ../.. vs ../../..)
|
|
17
|
+
repoRoot: path.join(__dirname_, '../..'),
|
|
18
|
+
// Typically adminIde-stack/packages/common
|
|
19
|
+
commonPackagePath: path.join(__dirname_, '../../packages/common'),
|
|
20
|
+
};exports.pathsConfig=pathsConfig;//# sourceMappingURL=commonPaths.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commonPaths.cjs","sources":["../../../src/tools/codegen/commonPaths.ts"],"sourcesContent":[null],"names":["fileURLToPath"],"mappings":"8JAIA,MAAM,WAAW,GAAGA,iBAAa,CAAC,+QAAe,CAAC,CAAC;AACnD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AAE7C;;;;;;;;AAQG;AACU,MAAA,WAAW,GAAG;;AAEvB,IAAA,UAAU,EAAE,WAAW;AACvB,IAAA,SAAS,EAAE,UAAU;;IAGrB,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC;;IAGxC,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,uBAAuB,CAAC;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import path__default from'path';import'fs';import {fileURLToPath}from'url';const __filename_ = fileURLToPath(import.meta.url);
|
|
2
|
+
const __dirname_ = path__default.dirname(__filename_);
|
|
3
|
+
/**
|
|
4
|
+
* If your folder structure is:
|
|
5
|
+
* adminIde-stack/
|
|
6
|
+
* └── tools/
|
|
7
|
+
* └── codegen/
|
|
8
|
+
* └── commonPaths.mjs
|
|
9
|
+
*
|
|
10
|
+
* Going two levels up from codegen => adminIde-stack/
|
|
11
|
+
*/
|
|
12
|
+
const pathsConfig = {
|
|
13
|
+
// The location of this file
|
|
14
|
+
__filename: __filename_,
|
|
15
|
+
__dirname: __dirname_,
|
|
16
|
+
// Points to adminIde-stack. Adjust if needed (e.g., ../.. vs ../../..)
|
|
17
|
+
repoRoot: path__default.join(__dirname_, '../..'),
|
|
18
|
+
// Typically adminIde-stack/packages/common
|
|
19
|
+
commonPackagePath: path__default.join(__dirname_, '../../packages/common'),
|
|
20
|
+
};export{pathsConfig};//# sourceMappingURL=commonPaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commonPaths.js","sources":["../../../src/tools/codegen/commonPaths.ts"],"sourcesContent":[null],"names":["path"],"mappings":"2EAIA,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnD,MAAM,UAAU,GAAGA,aAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AAE7C;;;;;;;;AAQG;AACU,MAAA,WAAW,GAAG;;AAEvB,IAAA,UAAU,EAAE,WAAW;AACvB,IAAA,SAAS,EAAE,UAAU;;IAGrB,QAAQ,EAAEA,aAAI,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC;;IAGxC,iBAAiB,EAAEA,aAAI,CAAC,IAAI,CAAC,UAAU,EAAE,uBAAuB,CAAC;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';var path=require('path'),commonPaths=require('./commonPaths.cjs');/**
|
|
2
|
+
* Given a list of modules objects (e.g. {client, core, browser, server, independent}),
|
|
3
|
+
* build a list of GraphQL schemas and documents for codegen.
|
|
4
|
+
*
|
|
5
|
+
* Provide optional cdecodePaths = { repoRoot } if you want to override defaults.
|
|
6
|
+
*/
|
|
7
|
+
function computeModules(modules, cdecodePaths = {}) {
|
|
8
|
+
let { repoRoot } = cdecodePaths;
|
|
9
|
+
if (!repoRoot) {
|
|
10
|
+
repoRoot = commonPaths.pathsConfig.repoRoot;
|
|
11
|
+
}
|
|
12
|
+
const result = { schemas: [], documents: [] };
|
|
13
|
+
for (const modObj of modules) {
|
|
14
|
+
try {
|
|
15
|
+
const { core, client, browser, server, independent } = modObj;
|
|
16
|
+
const corePath = core ? path.join(repoRoot, core) : null;
|
|
17
|
+
const clientPath = client ? path.join(repoRoot, client) : null;
|
|
18
|
+
const browserPath = browser ? path.join(repoRoot, browser) : null;
|
|
19
|
+
const serverPath = server ? path.join(repoRoot, server) : null;
|
|
20
|
+
const independentPath = independent ? path.join(repoRoot, independent) : null;
|
|
21
|
+
// .gql documents
|
|
22
|
+
if (clientPath)
|
|
23
|
+
result.documents.push(`${clientPath}/**/*.gql`);
|
|
24
|
+
if (corePath)
|
|
25
|
+
result.documents.push(`${corePath}/**/*.gql`);
|
|
26
|
+
if (browserPath)
|
|
27
|
+
result.documents.push(`${browserPath}/**/*.gql`);
|
|
28
|
+
if (serverPath)
|
|
29
|
+
result.documents.push(`${serverPath}/**/*.gql`);
|
|
30
|
+
if (independentPath)
|
|
31
|
+
result.documents.push(`${independentPath}/**/*.gql`);
|
|
32
|
+
// .graphql schemas
|
|
33
|
+
if (serverPath)
|
|
34
|
+
result.schemas.push(`${serverPath}/**/*.graphql`);
|
|
35
|
+
if (clientPath)
|
|
36
|
+
result.schemas.push(`${clientPath}/**/*.graphql`);
|
|
37
|
+
if (browserPath)
|
|
38
|
+
result.schemas.push(`${browserPath}/**/*.graphql`);
|
|
39
|
+
if (independentPath)
|
|
40
|
+
result.schemas.push(`${independentPath}/**/*.graphql`);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
console.error(`Could not compute paths for module: ${JSON.stringify(modObj)}`, err);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}exports.computeModules=computeModules;//# sourceMappingURL=computeModules.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computeModules.cjs","sources":["../../../src/tools/codegen/computeModules.ts"],"sourcesContent":[null],"names":["pathsConfig"],"mappings":"+EAGA;;;;;AAKG;SACa,cAAc,CAAC,OAAO,EAAE,eAAe,EAAS,EAAA;AAC5D,IAAA,IAAI,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC;IAChC,IAAI,CAAC,QAAQ,EAAE;AACX,QAAA,QAAQ,GAAGA,uBAAW,CAAC,QAAQ,CAAC;KACnC;IAED,MAAM,MAAM,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;AAE9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S,CAAC,IAAI,CAAC,CAAG,EAAA,eAAe,CAAW,SAAA,CAAA,CAAC,CAAC;;AAG1E,YAAA,IAAI,UAAU;gBAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAG,EAAA,UAAU,CAAe,aAAA,CAAA,CAAC,CAAC;AAClE,YAAA,IAAI,UAAU;gBAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAG,EAAA,UAAU,CAAe,aAAA,CAAA,CAAC,CAAC;AAClE,YAAA,IAAI,WAAW;gBAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAG,EAAA,WAAW,CAAe,aAAA,CAAA,CAAC,CAAC;AACpE,YAAA,IAAI,eAAe;gBAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAG,EAAA,eAAe,CAAe,aAAA,CAAA,CAAC,CAAC;SAC/E;QAAC,OAAO,GAAG,EAAE;AACV,YAAA,OAAO,CAAC,KAAK,CAAC,CAAA,oCAAA,EAAuC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA,CAAE,EAAE,GAAG,CAAC,CAAC;SACvF;KACJ;AAED,IAAA,OAAO,MAAM,CAAC;AAClB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path__default from'path';import {pathsConfig}from'./commonPaths.js';/**
|
|
2
|
+
* Given a list of modules objects (e.g. {client, core, browser, server, independent}),
|
|
3
|
+
* build a list of GraphQL schemas and documents for codegen.
|
|
4
|
+
*
|
|
5
|
+
* Provide optional cdecodePaths = { repoRoot } if you want to override defaults.
|
|
6
|
+
*/
|
|
7
|
+
function computeModules(modules, cdecodePaths = {}) {
|
|
8
|
+
let { repoRoot } = cdecodePaths;
|
|
9
|
+
if (!repoRoot) {
|
|
10
|
+
repoRoot = pathsConfig.repoRoot;
|
|
11
|
+
}
|
|
12
|
+
const result = { schemas: [], documents: [] };
|
|
13
|
+
for (const modObj of modules) {
|
|
14
|
+
try {
|
|
15
|
+
const { core, client, browser, server, independent } = modObj;
|
|
16
|
+
const corePath = core ? path__default.join(repoRoot, core) : null;
|
|
17
|
+
const clientPath = client ? path__default.join(repoRoot, client) : null;
|
|
18
|
+
const browserPath = browser ? path__default.join(repoRoot, browser) : null;
|
|
19
|
+
const serverPath = server ? path__default.join(repoRoot, server) : null;
|
|
20
|
+
const independentPath = independent ? path__default.join(repoRoot, independent) : null;
|
|
21
|
+
// .gql documents
|
|
22
|
+
if (clientPath)
|
|
23
|
+
result.documents.push(`${clientPath}/**/*.gql`);
|
|
24
|
+
if (corePath)
|
|
25
|
+
result.documents.push(`${corePath}/**/*.gql`);
|
|
26
|
+
if (browserPath)
|
|
27
|
+
result.documents.push(`${browserPath}/**/*.gql`);
|
|
28
|
+
if (serverPath)
|
|
29
|
+
result.documents.push(`${serverPath}/**/*.gql`);
|
|
30
|
+
if (independentPath)
|
|
31
|
+
result.documents.push(`${independentPath}/**/*.gql`);
|
|
32
|
+
// .graphql schemas
|
|
33
|
+
if (serverPath)
|
|
34
|
+
result.schemas.push(`${serverPath}/**/*.graphql`);
|
|
35
|
+
if (clientPath)
|
|
36
|
+
result.schemas.push(`${clientPath}/**/*.graphql`);
|
|
37
|
+
if (browserPath)
|
|
38
|
+
result.schemas.push(`${browserPath}/**/*.graphql`);
|
|
39
|
+
if (independentPath)
|
|
40
|
+
result.schemas.push(`${independentPath}/**/*.graphql`);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
console.error(`Could not compute paths for module: ${JSON.stringify(modObj)}`, err);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}export{computeModules};//# sourceMappingURL=computeModules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computeModules.js","sources":["../../../src/tools/codegen/computeModules.ts"],"sourcesContent":[null],"names":["path"],"mappings":"2EAGA;;;;;AAKG;SACa,cAAc,CAAC,OAAO,EAAE,eAAe,EAAS,EAAA;AAC5D,IAAA,IAAI,EA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AAC,CAAG,EAAA,WAAW,CAAW,SAAA,CAAA,CAAC,CAAC;AAClE,YAAA,IAAI,UAAU;gBAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAG,EAAA,UAAU,CAAW,SAAA,CAAA,CAAC,CAAC;AAChE,YAAA,IAAI,eAAe;gBAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAG,EAAA,eAAe,CAAW,SAAA,CAAA,CAAC,CAAC;;AAG1E,YAAA,IAAI,UAAU;gBAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAG,EAAA,UAAU,CAAe,aAAA,CAAA,CAAC,CAAC;AAClE,YAAA,IAAI,UAAU;gBAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAG,EAAA,UAAU,CAAe,aAAA,CAAA,CAAC,CAAC;AAClE,YAAA,IAAI,WAAW;gBAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAG,EAAA,WAAW,CAAe,aAAA,CAAA,CAAC,CAAC;AACpE,YAAA,IAAI,eAAe;gBAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAG,EAAA,eAAe,CAAe,aAAA,CAAA,CAAC,CAAC;SAC/E;QAAC,OAAO,GAAG,EAAE;AACV,YAAA,OAAO,CAAC,KAAK,CAAC,CAAA,oCAAA,EAAuC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA,CAAE,EAAE,GAAG,CAAC,CAAC;SACvF;KACJ;AAED,IAAA,OAAO,MAAM,CAAC;AAClB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';var fs=require('fs'),path=require('path'),commonPaths=require('./commonPaths.cjs'),computeModules=require('./computeModules.cjs');/**
|
|
2
|
+
* Recursively traverse an object (or array), replacing string placeholders
|
|
3
|
+
* based on the replacements map. Returns a new object/array with substitutions.
|
|
4
|
+
*/
|
|
5
|
+
function fillPlaceholders(input, placeholders) {
|
|
6
|
+
if (Array.isArray(input)) {
|
|
7
|
+
return input.map((el) => fillPlaceholders(el, placeholders));
|
|
8
|
+
}
|
|
9
|
+
if (input && typeof input === 'object') {
|
|
10
|
+
const resultObj = {};
|
|
11
|
+
for (const [key, val] of Object.entries(input)) {
|
|
12
|
+
resultObj[key] = fillPlaceholders(val, placeholders);
|
|
13
|
+
}
|
|
14
|
+
return resultObj;
|
|
15
|
+
}
|
|
16
|
+
if (typeof input === 'string') {
|
|
17
|
+
// If input is %discoveredSchemas%, replace with an actual array
|
|
18
|
+
if (input === '%discoveredSchemas%') {
|
|
19
|
+
return placeholders.discoveredSchemas;
|
|
20
|
+
}
|
|
21
|
+
// If input is %discoveredDocuments%, replace with an actual array
|
|
22
|
+
if (input === '%discoveredDocuments%') {
|
|
23
|
+
return placeholders.discoveredDocuments;
|
|
24
|
+
}
|
|
25
|
+
// If input is $PRIMARY_SCHEMA_PLACEHOLDER$, replace with a string
|
|
26
|
+
if (input === '$PRIMARY_SCHEMA_PLACEHOLDER$') {
|
|
27
|
+
return placeholders.primarySchema;
|
|
28
|
+
}
|
|
29
|
+
// Otherwise return the same string
|
|
30
|
+
return input;
|
|
31
|
+
}
|
|
32
|
+
return input; // For numbers, booleans, etc.
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generates the "codegen.ts" file based on discovered modules.
|
|
36
|
+
* We read placeholders (%discoveredSchemas%, %discoveredDocuments%, etc.)
|
|
37
|
+
* from cdecodeConfig.codegen.fullConfig and substitute them with real paths.
|
|
38
|
+
*/
|
|
39
|
+
function generateCodegenConfig(allModules, codegenOptions = {}, cdecodePaths = {}) {
|
|
40
|
+
const { schemas: schemaPaths, documents: documentPaths } = computeModules.computeModules(allModules, cdecodePaths);
|
|
41
|
+
let { repoRoot } = cdecodePaths;
|
|
42
|
+
if (!repoRoot) {
|
|
43
|
+
repoRoot = commonPaths.pathsConfig.repoRoot;
|
|
44
|
+
}
|
|
45
|
+
// Where will we write the file?
|
|
46
|
+
const OUTPUT_FILE = codegenOptions.outputFile
|
|
47
|
+
? path.join(repoRoot, codegenOptions.outputFile)
|
|
48
|
+
: path.join(repoRoot, 'codegen.ts');
|
|
49
|
+
// Resolve all discovered paths relative to the folder of OUTPUT_FILE
|
|
50
|
+
const outputDir = path.dirname(OUTPUT_FILE);
|
|
51
|
+
const relativeSchemas = schemaPaths.map((absPath) => path.relative(outputDir, absPath).replace(/\\/g, '/'));
|
|
52
|
+
const relativeDocs = documentPaths.map((absPath) => path.relative(outputDir, absPath).replace(/\\/g, '/'));
|
|
53
|
+
// Warn if empty
|
|
54
|
+
if (!relativeSchemas.length || !relativeDocs.length) {
|
|
55
|
+
console.warn('No schemas or documents found. Please verify your modules configuration.');
|
|
56
|
+
}
|
|
57
|
+
// We'll read the entire codegen config from cdecodeConfig (the user JSON)
|
|
58
|
+
// Then we'll fill placeholders like %discoveredSchemas% with the actual arrays
|
|
59
|
+
const userConfig = codegenOptions.fullConfig || {};
|
|
60
|
+
// Prepare the placeholders
|
|
61
|
+
const placeholdersObj = {
|
|
62
|
+
discoveredSchemas: relativeSchemas,
|
|
63
|
+
discoveredDocuments: relativeDocs,
|
|
64
|
+
primarySchema: codegenOptions.rootSchema || 'servers/backend-server/src/api/root-schema.graphqls',
|
|
65
|
+
};
|
|
66
|
+
// Recursively fill placeholders
|
|
67
|
+
const finalConfig = fillPlaceholders(userConfig, placeholdersObj);
|
|
68
|
+
// finalConfig now has the replaced arrays (though they are strings if we used JSON.stringify).
|
|
69
|
+
// For many codegen configs, having an array in the JSON is correct.
|
|
70
|
+
// If your placeholders are inserted as raw text, you may need to parse them back to arrays.
|
|
71
|
+
// But if your codegen CLI can handle JSON arrays directly, this works fine.
|
|
72
|
+
// Convert finalConfig to actual JSON text
|
|
73
|
+
const codegenFileContents = `
|
|
74
|
+
// This file is auto-generated. Do not edit manually.
|
|
75
|
+
const config = ${JSON.stringify(finalConfig, null, 2)};
|
|
76
|
+
|
|
77
|
+
export default config;
|
|
78
|
+
`.trimStart();
|
|
79
|
+
fs.writeFileSync(OUTPUT_FILE, codegenFileContents);
|
|
80
|
+
console.log(`Generated codegen config at: ${OUTPUT_FILE}`);
|
|
81
|
+
}exports.generateCodegenConfig=generateCodegenConfig;//# sourceMappingURL=generateCodegenConfig.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateCodegenConfig.cjs","sources":["../../../src/tools/codegen/generateCodegenConfig.ts"],"sourcesContent":[null],"names":["computeModules","pathsConfig"],"mappings":"+IAMA;;;AAGG;AACH,SAAS,gBAAgB,CAAC,KAAK,EAAE,YAAY,EAAA;AACzC,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AACtB,QAAA,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,gBAAgB,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;KAChE;AACD,IAAA,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,QAAA,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC5C,SAAS,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;SACxD;AACD,QAAA,OAAO,SAAS,CAAC;KACpB;AACD,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;;AAE3B,QAAA,IAAI,KAAK,KAAK,qBAAqB,EAAE;YACjC,OAAO,YAAY,CAAC,iBAAiB,CAAC;SACzC;;AAED,QAAA,IAAI,KAAK,KAAK,uBAAuB,EAAE;YACnC,OAAO,YAAY,CAAC,mBAAmB,CAAC;SAC3C;;AAED,QAAA,IAAI,KAAK,KAAK,8BAA8B,EAAE;YAC1C,OAAO,YAAY,CAAC,aAAa,CAAC;SACrC;;AAED,QAAA,OAAO,KAAK,CAAC;KAChB;IACD,OAAO,KAAK,CAAC;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AE,eAAe;AAClC,QAAA,mBAAmB,EAAE,YAAY;AACjC,QAAA,aAAa,EAAE,cAAc,CAAC,UAAU,IAAI,qDAAqD;KACpG,CAAC;;IAGF,MAAM,WAAW,GAAG,gBAAgB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;;;;;;AAQlE,IAAA,MAAM,mBAAmB,GAAG,CAAA;;iBAEf,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;;;CAGpD,CAAC,SAAS,EAAE,CAAC;AAEV,IAAA,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;AACnD,IAAA,OAAO,CAAC,GAAG,CAAC,gCAAgC,WAAW,CAAA,CAAE,CAAC,CAAC;AAC/D"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import fs__default from'fs';import path__default from'path';import {pathsConfig}from'./commonPaths.js';import {computeModules}from'./computeModules.js';/**
|
|
2
|
+
* Recursively traverse an object (or array), replacing string placeholders
|
|
3
|
+
* based on the replacements map. Returns a new object/array with substitutions.
|
|
4
|
+
*/
|
|
5
|
+
function fillPlaceholders(input, placeholders) {
|
|
6
|
+
if (Array.isArray(input)) {
|
|
7
|
+
return input.map((el) => fillPlaceholders(el, placeholders));
|
|
8
|
+
}
|
|
9
|
+
if (input && typeof input === 'object') {
|
|
10
|
+
const resultObj = {};
|
|
11
|
+
for (const [key, val] of Object.entries(input)) {
|
|
12
|
+
resultObj[key] = fillPlaceholders(val, placeholders);
|
|
13
|
+
}
|
|
14
|
+
return resultObj;
|
|
15
|
+
}
|
|
16
|
+
if (typeof input === 'string') {
|
|
17
|
+
// If input is %discoveredSchemas%, replace with an actual array
|
|
18
|
+
if (input === '%discoveredSchemas%') {
|
|
19
|
+
return placeholders.discoveredSchemas;
|
|
20
|
+
}
|
|
21
|
+
// If input is %discoveredDocuments%, replace with an actual array
|
|
22
|
+
if (input === '%discoveredDocuments%') {
|
|
23
|
+
return placeholders.discoveredDocuments;
|
|
24
|
+
}
|
|
25
|
+
// If input is $PRIMARY_SCHEMA_PLACEHOLDER$, replace with a string
|
|
26
|
+
if (input === '$PRIMARY_SCHEMA_PLACEHOLDER$') {
|
|
27
|
+
return placeholders.primarySchema;
|
|
28
|
+
}
|
|
29
|
+
// Otherwise return the same string
|
|
30
|
+
return input;
|
|
31
|
+
}
|
|
32
|
+
return input; // For numbers, booleans, etc.
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generates the "codegen.ts" file based on discovered modules.
|
|
36
|
+
* We read placeholders (%discoveredSchemas%, %discoveredDocuments%, etc.)
|
|
37
|
+
* from cdecodeConfig.codegen.fullConfig and substitute them with real paths.
|
|
38
|
+
*/
|
|
39
|
+
function generateCodegenConfig(allModules, codegenOptions = {}, cdecodePaths = {}) {
|
|
40
|
+
const { schemas: schemaPaths, documents: documentPaths } = computeModules(allModules, cdecodePaths);
|
|
41
|
+
let { repoRoot } = cdecodePaths;
|
|
42
|
+
if (!repoRoot) {
|
|
43
|
+
repoRoot = pathsConfig.repoRoot;
|
|
44
|
+
}
|
|
45
|
+
// Where will we write the file?
|
|
46
|
+
const OUTPUT_FILE = codegenOptions.outputFile
|
|
47
|
+
? path__default.join(repoRoot, codegenOptions.outputFile)
|
|
48
|
+
: path__default.join(repoRoot, 'codegen.ts');
|
|
49
|
+
// Resolve all discovered paths relative to the folder of OUTPUT_FILE
|
|
50
|
+
const outputDir = path__default.dirname(OUTPUT_FILE);
|
|
51
|
+
const relativeSchemas = schemaPaths.map((absPath) => path__default.relative(outputDir, absPath).replace(/\\/g, '/'));
|
|
52
|
+
const relativeDocs = documentPaths.map((absPath) => path__default.relative(outputDir, absPath).replace(/\\/g, '/'));
|
|
53
|
+
// Warn if empty
|
|
54
|
+
if (!relativeSchemas.length || !relativeDocs.length) {
|
|
55
|
+
console.warn('No schemas or documents found. Please verify your modules configuration.');
|
|
56
|
+
}
|
|
57
|
+
// We'll read the entire codegen config from cdecodeConfig (the user JSON)
|
|
58
|
+
// Then we'll fill placeholders like %discoveredSchemas% with the actual arrays
|
|
59
|
+
const userConfig = codegenOptions.fullConfig || {};
|
|
60
|
+
// Prepare the placeholders
|
|
61
|
+
const placeholdersObj = {
|
|
62
|
+
discoveredSchemas: relativeSchemas,
|
|
63
|
+
discoveredDocuments: relativeDocs,
|
|
64
|
+
primarySchema: codegenOptions.rootSchema || 'servers/backend-server/src/api/root-schema.graphqls',
|
|
65
|
+
};
|
|
66
|
+
// Recursively fill placeholders
|
|
67
|
+
const finalConfig = fillPlaceholders(userConfig, placeholdersObj);
|
|
68
|
+
// finalConfig now has the replaced arrays (though they are strings if we used JSON.stringify).
|
|
69
|
+
// For many codegen configs, having an array in the JSON is correct.
|
|
70
|
+
// If your placeholders are inserted as raw text, you may need to parse them back to arrays.
|
|
71
|
+
// But if your codegen CLI can handle JSON arrays directly, this works fine.
|
|
72
|
+
// Convert finalConfig to actual JSON text
|
|
73
|
+
const codegenFileContents = `
|
|
74
|
+
// This file is auto-generated. Do not edit manually.
|
|
75
|
+
const config = ${JSON.stringify(finalConfig, null, 2)};
|
|
76
|
+
|
|
77
|
+
export default config;
|
|
78
|
+
`.trimStart();
|
|
79
|
+
fs__default.writeFileSync(OUTPUT_FILE, codegenFileContents);
|
|
80
|
+
console.log(`Generated codegen config at: ${OUTPUT_FILE}`);
|
|
81
|
+
}export{generateCodegenConfig};//# sourceMappingURL=generateCodegenConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateCodegenConfig.js","sources":["../../../src/tools/codegen/generateCodegenConfig.ts"],"sourcesContent":[null],"names":["path","fs"],"mappings":"wJAMA;;;AAGG;AACH,SAAS,gBAAgB,CAAC,KAAK,EAAE,YAAY,EAAA;AACzC,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AACtB,QAAA,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,gBAAgB,CAAC,EAAE,E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0,0 +1,14 @@
|
|
|
1
|
+
'use strict';var setupCommonPackage=require('./setupCommonPackage.cjs'),readModules=require('./readModules.cjs'),performCopyOperations=require('./performCopyOperations.cjs'),generateCodegenConfig=require('./generateCodegenConfig.cjs');/**
|
|
2
|
+
* Orchestrates the codegen tasks, reading from your cdecodeConfig object.
|
|
3
|
+
* Example usage: runCodegenTasks(cdecodeConfig).
|
|
4
|
+
*/
|
|
5
|
+
async function runCodegenTasks(cdecodeConfig) {
|
|
6
|
+
// 1) Setup "common" package from template
|
|
7
|
+
setupCommonPackage.setupCommonPackage(cdecodeConfig.projectPaths);
|
|
8
|
+
// 2) Read modules from server config files
|
|
9
|
+
const allModules = readModules.readModules(cdecodeConfig.servers);
|
|
10
|
+
// 3) Perform file-copy operations for modules that define cdecode.common
|
|
11
|
+
performCopyOperations.performCopyOperations(allModules, cdecodeConfig.projectPaths);
|
|
12
|
+
// 4) Generate the codegen config
|
|
13
|
+
generateCodegenConfig.generateCodegenConfig(allModules, cdecodeConfig.codegen, cdecodeConfig.projectPaths);
|
|
14
|
+
}exports.runCodegenTasks=runCodegenTasks;//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/tools/codegen/index.ts"],"sourcesContent":[null],"names":["setupCommonPackage","readModules","performCopyOperations","generateCodegenConfig"],"mappings":"2OAKA;;;AAGG;AACI,eAAe,eAAe,CAAC,aAAa,EAAA;;AAE/C,IAAAA,qCAAkB,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;;IAG/C,MAAM,UAAU,GAAGC,uBAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;;AAGtD,IAAAC,2CAAqB,CAAC,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;;IAG9DC,2CAAqB,CAAC,UAAU,EAAE,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;AACzF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {setupCommonPackage}from'./setupCommonPackage.js';import {readModules}from'./readModules.js';import {performCopyOperations}from'./performCopyOperations.js';import {generateCodegenConfig}from'./generateCodegenConfig.js';/**
|
|
2
|
+
* Orchestrates the codegen tasks, reading from your cdecodeConfig object.
|
|
3
|
+
* Example usage: runCodegenTasks(cdecodeConfig).
|
|
4
|
+
*/
|
|
5
|
+
async function runCodegenTasks(cdecodeConfig) {
|
|
6
|
+
// 1) Setup "common" package from template
|
|
7
|
+
setupCommonPackage(cdecodeConfig.projectPaths);
|
|
8
|
+
// 2) Read modules from server config files
|
|
9
|
+
const allModules = readModules(cdecodeConfig.servers);
|
|
10
|
+
// 3) Perform file-copy operations for modules that define cdecode.common
|
|
11
|
+
performCopyOperations(allModules, cdecodeConfig.projectPaths);
|
|
12
|
+
// 4) Generate the codegen config
|
|
13
|
+
generateCodegenConfig(allModules, cdecodeConfig.codegen, cdecodeConfig.projectPaths);
|
|
14
|
+
}export{runCodegenTasks};//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/tools/codegen/index.ts"],"sourcesContent":[null],"names":[],"mappings":"kOAKA;;;AAGG;AACI,eAAe,eAAe,CAAC,aAAa,EAAA;;AAE/C,IAAA,kBAAkB,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;;IAG/C,MAAM,UAAU,GAAG,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;;AAGtD,IAAA,qBAAqB,CAAC,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;;IAG9D,qBAAqB,CAAC,UAAU,EAAE,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;AACzF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';var child_process=require('child_process'),fs=require('fs'),path=require('path'),commonPaths=require('./commonPaths.cjs');/**
|
|
2
|
+
* For each discovered module, if "cdecode.common" is found in
|
|
3
|
+
* the package.json, copy the specified files into the common package.
|
|
4
|
+
*
|
|
5
|
+
* Provide optional cdecodePaths = { repoRoot, commonPackagePath } to override
|
|
6
|
+
* the defaults in commonPaths.mjs.
|
|
7
|
+
*/
|
|
8
|
+
function performCopyOperations(modules, cdecodePaths = {}) {
|
|
9
|
+
let { repoRoot, commonPackagePath } = cdecodePaths;
|
|
10
|
+
// Fallback to internal pathsConfig if not provided by user
|
|
11
|
+
if (!repoRoot) {
|
|
12
|
+
repoRoot = commonPaths.pathsConfig.repoRoot;
|
|
13
|
+
}
|
|
14
|
+
if (!commonPackagePath) {
|
|
15
|
+
// e.g. "packages/common"
|
|
16
|
+
commonPackagePath = path.join(commonPaths.pathsConfig.repoRoot, 'packages/common');
|
|
17
|
+
}
|
|
18
|
+
let shouldAddExport = false;
|
|
19
|
+
for (const modulesObj of modules) {
|
|
20
|
+
// modulesObj = { client, core, browser, server, independent }
|
|
21
|
+
for (const moduleName of Object.values(modulesObj)) {
|
|
22
|
+
try {
|
|
23
|
+
const modulePath = path.join(repoRoot, moduleName, '../');
|
|
24
|
+
const pkgJsonFilePath = path.join(modulePath, 'package.json');
|
|
25
|
+
if (!fs.existsSync(pkgJsonFilePath)) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const pkgJsonBuffer = fs.readFileSync(pkgJsonFilePath, 'utf-8');
|
|
29
|
+
const pkgJson = JSON.parse(pkgJsonBuffer);
|
|
30
|
+
// If cdecode.common is present, copy the specified modules
|
|
31
|
+
if (pkgJson.cdecode?.common) {
|
|
32
|
+
const pkgName = (pkgJson.name || '').split('/')[1] || pkgJson.name;
|
|
33
|
+
const { modules: resourceList } = pkgJson.cdecode.common;
|
|
34
|
+
const directoryPath = path.join(commonPackagePath, `src/modules/${pkgName}`);
|
|
35
|
+
child_process.execSync(`mkdir -p ${directoryPath}`);
|
|
36
|
+
// Copy each file or folder
|
|
37
|
+
resourceList.forEach((moduleFile) => {
|
|
38
|
+
child_process.execSync(`cp -r ${path.join(modulePath, moduleFile)} ${directoryPath}`);
|
|
39
|
+
});
|
|
40
|
+
// Create an index.ts that re-exports each file
|
|
41
|
+
const getFileNameWithoutExt = (filePath) => {
|
|
42
|
+
const justFile = path.basename(filePath);
|
|
43
|
+
return path.basename(justFile, path.extname(justFile));
|
|
44
|
+
};
|
|
45
|
+
const exports = resourceList
|
|
46
|
+
.map((file) => `export * from './${getFileNameWithoutExt(file)}';`)
|
|
47
|
+
.join('\n');
|
|
48
|
+
// Write index.ts
|
|
49
|
+
child_process.execSync(`echo "${exports.replace(/"/g, '\\"')}" > ${path.join(directoryPath, 'index.ts')}`);
|
|
50
|
+
// Write an index.ts in the parent folder, referencing the new module folder
|
|
51
|
+
child_process.execSync(`echo "export * from './${pkgName}';" > ${path.join(directoryPath, '../', 'index.ts')}`);
|
|
52
|
+
shouldAddExport = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.error(`Error copying modules for: ${moduleName}`, e);
|
|
57
|
+
// you can decide to continue or break
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// If we've added at least one module export, update the top-level index
|
|
62
|
+
if (shouldAddExport) {
|
|
63
|
+
child_process.execSync(`echo "export * from './modules';" >> ${path.join(commonPackagePath, 'src', 'index.ts')}`);
|
|
64
|
+
}
|
|
65
|
+
}exports.performCopyOperations=performCopyOperations;//# sourceMappingURL=performCopyOperations.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performCopyOperations.cjs","sources":["../../../src/tools/codegen/performCopyOperations.ts"],"sourcesContent":[null],"names":["pathsConfig","execSync"],"mappings":"uIAKA;;;;;;AAMG;SACa,qBAAqB,CAAC,OAAO,EAAE,eAAe,EAAS,EAAA;AACnE,IAAA,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,YAAY,CAAC;;IAGnD,IAAI,CAAC,QAAQ,EAAE;AACX,QAAA,QAAQ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,EAAwC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA,CAAE,CAAC,CAAC;KACvG;AACL"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {execSync}from'child_process';import fs__default from'fs';import path__default from'path';import {pathsConfig}from'./commonPaths.js';/**
|
|
2
|
+
* For each discovered module, if "cdecode.common" is found in
|
|
3
|
+
* the package.json, copy the specified files into the common package.
|
|
4
|
+
*
|
|
5
|
+
* Provide optional cdecodePaths = { repoRoot, commonPackagePath } to override
|
|
6
|
+
* the defaults in commonPaths.mjs.
|
|
7
|
+
*/
|
|
8
|
+
function performCopyOperations(modules, cdecodePaths = {}) {
|
|
9
|
+
let { repoRoot, commonPackagePath } = cdecodePaths;
|
|
10
|
+
// Fallback to internal pathsConfig if not provided by user
|
|
11
|
+
if (!repoRoot) {
|
|
12
|
+
repoRoot = pathsConfig.repoRoot;
|
|
13
|
+
}
|
|
14
|
+
if (!commonPackagePath) {
|
|
15
|
+
// e.g. "packages/common"
|
|
16
|
+
commonPackagePath = path__default.join(pathsConfig.repoRoot, 'packages/common');
|
|
17
|
+
}
|
|
18
|
+
let shouldAddExport = false;
|
|
19
|
+
for (const modulesObj of modules) {
|
|
20
|
+
// modulesObj = { client, core, browser, server, independent }
|
|
21
|
+
for (const moduleName of Object.values(modulesObj)) {
|
|
22
|
+
try {
|
|
23
|
+
const modulePath = path__default.join(repoRoot, moduleName, '../');
|
|
24
|
+
const pkgJsonFilePath = path__default.join(modulePath, 'package.json');
|
|
25
|
+
if (!fs__default.existsSync(pkgJsonFilePath)) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const pkgJsonBuffer = fs__default.readFileSync(pkgJsonFilePath, 'utf-8');
|
|
29
|
+
const pkgJson = JSON.parse(pkgJsonBuffer);
|
|
30
|
+
// If cdecode.common is present, copy the specified modules
|
|
31
|
+
if (pkgJson.cdecode?.common) {
|
|
32
|
+
const pkgName = (pkgJson.name || '').split('/')[1] || pkgJson.name;
|
|
33
|
+
const { modules: resourceList } = pkgJson.cdecode.common;
|
|
34
|
+
const directoryPath = path__default.join(commonPackagePath, `src/modules/${pkgName}`);
|
|
35
|
+
execSync(`mkdir -p ${directoryPath}`);
|
|
36
|
+
// Copy each file or folder
|
|
37
|
+
resourceList.forEach((moduleFile) => {
|
|
38
|
+
execSync(`cp -r ${path__default.join(modulePath, moduleFile)} ${directoryPath}`);
|
|
39
|
+
});
|
|
40
|
+
// Create an index.ts that re-exports each file
|
|
41
|
+
const getFileNameWithoutExt = (filePath) => {
|
|
42
|
+
const justFile = path__default.basename(filePath);
|
|
43
|
+
return path__default.basename(justFile, path__default.extname(justFile));
|
|
44
|
+
};
|
|
45
|
+
const exports = resourceList
|
|
46
|
+
.map((file) => `export * from './${getFileNameWithoutExt(file)}';`)
|
|
47
|
+
.join('\n');
|
|
48
|
+
// Write index.ts
|
|
49
|
+
execSync(`echo "${exports.replace(/"/g, '\\"')}" > ${path__default.join(directoryPath, 'index.ts')}`);
|
|
50
|
+
// Write an index.ts in the parent folder, referencing the new module folder
|
|
51
|
+
execSync(`echo "export * from './${pkgName}';" > ${path__default.join(directoryPath, '../', 'index.ts')}`);
|
|
52
|
+
shouldAddExport = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.error(`Error copying modules for: ${moduleName}`, e);
|
|
57
|
+
// you can decide to continue or break
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// If we've added at least one module export, update the top-level index
|
|
62
|
+
if (shouldAddExport) {
|
|
63
|
+
execSync(`echo "export * from './modules';" >> ${path__default.join(commonPackagePath, 'src', 'index.ts')}`);
|
|
64
|
+
}
|
|
65
|
+
}export{performCopyOperations};//# sourceMappingURL=performCopyOperations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performCopyOperations.js","sources":["../../../src/tools/codegen/performCopyOperations.ts"],"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C;iBAC1B;aACJ;YAAC,OAAO,CAAC,EAAE;gBACR,OAAO,CAAC,KAAK,CAAC,CAAA,2BAAA,EAA8B,UAAU,CAAE,CAAA,EAAE,CAAC,CAAC,CAAC;;aAEhE;SACJ;KACJ;;IAGD,IAAI,eAAe,EAAE;AACjB,QAAA,QAAQ,CAAC,CAAA,qCAAA,EAAwCA,aAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA,CAAE,CAAC,CAAC;KACvG;AACL"}
|
|
@@ -0,0 +1,106 @@
|
|
|
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;// If you also need checkFileExists, import it from the same file:
|
|
2
|
+
// import { pathsConfig, checkFileExists } from './commonPaths.mjs';
|
|
3
|
+
// ESM-compatible require
|
|
4
|
+
const require$1 = 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)));
|
|
5
|
+
/**
|
|
6
|
+
* Reads modules from both config files, resolves each package's location,
|
|
7
|
+
* and returns an array of objects: { client, core, browser, server } for local modules,
|
|
8
|
+
* or specialized subpaths for node_module packages, based on the snippet logic.
|
|
9
|
+
*/
|
|
10
|
+
function readModules(serverConfigPaths = []) {
|
|
11
|
+
// 1) Load the JSON configuration for each .json file
|
|
12
|
+
const [clientModules, serverModules] = serverConfigPaths.map((configFile) => {
|
|
13
|
+
if (!fs.existsSync(configFile)) {
|
|
14
|
+
console.error(`Config file not found: ${configFile}`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
const configData = JSON.parse(fs.readFileSync(configFile, 'utf-8'));
|
|
18
|
+
if (!configData.modules || !Array.isArray(configData.modules)) {
|
|
19
|
+
console.error('Invalid config file format. Expected "modules" as an array.');
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
return configData.modules;
|
|
23
|
+
});
|
|
24
|
+
// 2) Combine client + server modules uniquely
|
|
25
|
+
const allModules = [...new Set([...clientModules, ...serverModules])];
|
|
26
|
+
// 3) Transform each moduleName into a module object
|
|
27
|
+
const processedModules = new Set();
|
|
28
|
+
return allModules.reduce((acc, moduleName) => {
|
|
29
|
+
try {
|
|
30
|
+
// Resolve the module path using require.resolve(...)
|
|
31
|
+
const dirName = path.dirname(require$1.resolve(moduleName));
|
|
32
|
+
// Convert absolute path to something relative to <repoRoot>/..
|
|
33
|
+
// (The snippet used path.join(__dirname, '../'); replicate that logic below.)
|
|
34
|
+
const modulePath = path.relative(commonPaths.pathsConfig.repoRoot, dirName);
|
|
35
|
+
// Reverse, check if node_modules is in the path
|
|
36
|
+
const [dir, pkg, ...rest] = modulePath.split('/').reverse();
|
|
37
|
+
const isLocal = !rest.includes('node_modules');
|
|
38
|
+
// For local modules, baseModule might be "packages-modules/foo";
|
|
39
|
+
// For node_modules, it's something like "node_modules/some-lib"
|
|
40
|
+
// The snippet also strips out "/lib" for non-local.
|
|
41
|
+
const baseModule = isLocal ? [...rest].reverse().join('/') : modulePath.replace('/lib', '');
|
|
42
|
+
if (processedModules.has(baseModule)) {
|
|
43
|
+
return acc;
|
|
44
|
+
}
|
|
45
|
+
processedModules.add(baseModule);
|
|
46
|
+
// Helper: local => "src", node => "lib"
|
|
47
|
+
const srcOrLib = isLocal ? 'src' : 'lib';
|
|
48
|
+
const generatePath = (type) => `${baseModule}${isLocal ? `/${type}` : ''}/${srcOrLib}`;
|
|
49
|
+
// 4) If local, always return { client, core, browser, server }
|
|
50
|
+
if (isLocal) {
|
|
51
|
+
return [
|
|
52
|
+
...acc,
|
|
53
|
+
{
|
|
54
|
+
client: generatePath('client'),
|
|
55
|
+
core: generatePath('core'),
|
|
56
|
+
browser: generatePath('browser'),
|
|
57
|
+
server: generatePath('server'),
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
// 5) Otherwise, handle node_module naming conventions
|
|
62
|
+
// If the baseModule ends with "-browser"
|
|
63
|
+
if (baseModule.endsWith('-browser')) {
|
|
64
|
+
// If it ends with -browser, also provide -client, -core
|
|
65
|
+
return [
|
|
66
|
+
...acc,
|
|
67
|
+
{
|
|
68
|
+
browser: `${baseModule}/${srcOrLib}`,
|
|
69
|
+
client: `${baseModule.replace(/-browser$/, '-client')}/${srcOrLib}`,
|
|
70
|
+
core: `${baseModule.replace(/-browser$/, '-core')}/${srcOrLib}`,
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
if (baseModule.endsWith('-server')) {
|
|
75
|
+
// If it ends with -server
|
|
76
|
+
return [
|
|
77
|
+
...acc,
|
|
78
|
+
{
|
|
79
|
+
server: `${baseModule}/${srcOrLib}`,
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
if (baseModule.includes('-browser')) {
|
|
84
|
+
// If it has '-browser' somewhere else
|
|
85
|
+
return [
|
|
86
|
+
...acc,
|
|
87
|
+
{
|
|
88
|
+
browser: `${baseModule}/${srcOrLib}`,
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
// Default fallback
|
|
93
|
+
return [
|
|
94
|
+
...acc,
|
|
95
|
+
{
|
|
96
|
+
independent: `${baseModule}/${srcOrLib}`,
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
console.error(e);
|
|
102
|
+
console.log('Error while processing module:', moduleName);
|
|
103
|
+
return acc;
|
|
104
|
+
}
|
|
105
|
+
}, []);
|
|
106
|
+
}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":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E,EAAE,CAAC,CAAC;AACX"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import fs__default from'fs';import path__default from'path';import {createRequire}from'module';import {pathsConfig}from'./commonPaths.js';// If you also need checkFileExists, import it from the same file:
|
|
2
|
+
// import { pathsConfig, checkFileExists } from './commonPaths.mjs';
|
|
3
|
+
// ESM-compatible require
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
/**
|
|
6
|
+
* Reads modules from both config files, resolves each package's location,
|
|
7
|
+
* and returns an array of objects: { client, core, browser, server } for local modules,
|
|
8
|
+
* or specialized subpaths for node_module packages, based on the snippet logic.
|
|
9
|
+
*/
|
|
10
|
+
function readModules(serverConfigPaths = []) {
|
|
11
|
+
// 1) Load the JSON configuration for each .json file
|
|
12
|
+
const [clientModules, serverModules] = serverConfigPaths.map((configFile) => {
|
|
13
|
+
if (!fs__default.existsSync(configFile)) {
|
|
14
|
+
console.error(`Config file not found: ${configFile}`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
const configData = JSON.parse(fs__default.readFileSync(configFile, 'utf-8'));
|
|
18
|
+
if (!configData.modules || !Array.isArray(configData.modules)) {
|
|
19
|
+
console.error('Invalid config file format. Expected "modules" as an array.');
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
return configData.modules;
|
|
23
|
+
});
|
|
24
|
+
// 2) Combine client + server modules uniquely
|
|
25
|
+
const allModules = [...new Set([...clientModules, ...serverModules])];
|
|
26
|
+
// 3) Transform each moduleName into a module object
|
|
27
|
+
const processedModules = new Set();
|
|
28
|
+
return allModules.reduce((acc, moduleName) => {
|
|
29
|
+
try {
|
|
30
|
+
// Resolve the module path using require.resolve(...)
|
|
31
|
+
const dirName = path__default.dirname(require.resolve(moduleName));
|
|
32
|
+
// Convert absolute path to something relative to <repoRoot>/..
|
|
33
|
+
// (The snippet used path.join(__dirname, '../'); replicate that logic below.)
|
|
34
|
+
const modulePath = path__default.relative(pathsConfig.repoRoot, dirName);
|
|
35
|
+
// Reverse, check if node_modules is in the path
|
|
36
|
+
const [dir, pkg, ...rest] = modulePath.split('/').reverse();
|
|
37
|
+
const isLocal = !rest.includes('node_modules');
|
|
38
|
+
// For local modules, baseModule might be "packages-modules/foo";
|
|
39
|
+
// For node_modules, it's something like "node_modules/some-lib"
|
|
40
|
+
// The snippet also strips out "/lib" for non-local.
|
|
41
|
+
const baseModule = isLocal ? [...rest].reverse().join('/') : modulePath.replace('/lib', '');
|
|
42
|
+
if (processedModules.has(baseModule)) {
|
|
43
|
+
return acc;
|
|
44
|
+
}
|
|
45
|
+
processedModules.add(baseModule);
|
|
46
|
+
// Helper: local => "src", node => "lib"
|
|
47
|
+
const srcOrLib = isLocal ? 'src' : 'lib';
|
|
48
|
+
const generatePath = (type) => `${baseModule}${isLocal ? `/${type}` : ''}/${srcOrLib}`;
|
|
49
|
+
// 4) If local, always return { client, core, browser, server }
|
|
50
|
+
if (isLocal) {
|
|
51
|
+
return [
|
|
52
|
+
...acc,
|
|
53
|
+
{
|
|
54
|
+
client: generatePath('client'),
|
|
55
|
+
core: generatePath('core'),
|
|
56
|
+
browser: generatePath('browser'),
|
|
57
|
+
server: generatePath('server'),
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
// 5) Otherwise, handle node_module naming conventions
|
|
62
|
+
// If the baseModule ends with "-browser"
|
|
63
|
+
if (baseModule.endsWith('-browser')) {
|
|
64
|
+
// If it ends with -browser, also provide -client, -core
|
|
65
|
+
return [
|
|
66
|
+
...acc,
|
|
67
|
+
{
|
|
68
|
+
browser: `${baseModule}/${srcOrLib}`,
|
|
69
|
+
client: `${baseModule.replace(/-browser$/, '-client')}/${srcOrLib}`,
|
|
70
|
+
core: `${baseModule.replace(/-browser$/, '-core')}/${srcOrLib}`,
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
if (baseModule.endsWith('-server')) {
|
|
75
|
+
// If it ends with -server
|
|
76
|
+
return [
|
|
77
|
+
...acc,
|
|
78
|
+
{
|
|
79
|
+
server: `${baseModule}/${srcOrLib}`,
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
if (baseModule.includes('-browser')) {
|
|
84
|
+
// If it has '-browser' somewhere else
|
|
85
|
+
return [
|
|
86
|
+
...acc,
|
|
87
|
+
{
|
|
88
|
+
browser: `${baseModule}/${srcOrLib}`,
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
// Default fallback
|
|
93
|
+
return [
|
|
94
|
+
...acc,
|
|
95
|
+
{
|
|
96
|
+
independent: `${baseModule}/${srcOrLib}`,
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
console.error(e);
|
|
102
|
+
console.log('Error while processing module:', moduleName);
|
|
103
|
+
return acc;
|
|
104
|
+
}
|
|
105
|
+
}, []);
|
|
106
|
+
}export{readModules};//# sourceMappingURL=readModules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readModules.js","sources":["../../../src/tools/codegen/readModules.ts"],"sourcesContent":[null],"names":["fs","path"],"mappings":"0IAKA;AACA;AAEA;AACA,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C;;;;AAIG;AACa,SAAA,WAAW,CAAC,iBAAiB,GAAG,EAAE,EAAA;;AAE9C,IAAA,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,KAAI;QACxE,IAAI,CAACA,WAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;AAC5B,YAAA,OAAO,CAAC,KAAK,CAAC,0BAA0B,UAAU,CAAA,CAAE,CAAC,CAAC;AACtD,YAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACnB;AACD,QAAA,MAAM,UAAU,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AC,EAAE;;gBAEhC,OAAO;AACH,oBAAA,GAAG,GAAG;AACN,oBAAA;AACI,wBAAA,MAAM,EAAE,CAAA,EAAG,UAAU,CAAA,CAAA,EAAI,QAAQ,CAAE,CAAA;AACtC,qBAAA;iBACJ,CAAC;aACL;AACD,YAAA,IAAI,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;;gBAEjC,OAAO;AACH,oBAAA,GAAG,GAAG;AACN,oBAAA;AACI,wBAAA,OAAO,EAAE,CAAA,EAAG,UAAU,CAAA,CAAA,EAAI,QAAQ,CAAE,CAAA;AACvC,qBAAA;iBACJ,CAAC;aACL;;YAED,OAAO;AACH,gBAAA,GAAG,GAAG;AACN,gBAAA;AACI,oBAAA,WAAW,EAAE,CAAA,EAAG,UAAU,CAAA,CAAA,EAAI,QAAQ,CAAE,CAAA;AAC3C,iBAAA;aACJ,CAAC;SACL;QAAC,OAAO,CAAC,EAAE;AACR,YAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACjB,YAAA,OAAO,CAAC,GAAG,CAAC,gCAAgC,EAAE,UAAU,CAAC,CAAC;AAC1D,YAAA,OAAO,GAAG,CAAC;SACd;KACJ,EAAE,EAAE,CAAC,CAAC;AACX"}
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
* Clears and re-creates the "common" package directory,
|
|
13
|
+
* then copies the template content there.
|
|
14
|
+
*
|
|
15
|
+
* Provide optional projectPaths to override defaults.
|
|
16
|
+
*/
|
|
17
|
+
function setupCommonPackage(projectPaths = {}) {
|
|
18
|
+
// Default template path, if none provided in projectPaths
|
|
19
|
+
const templatePath = projectPaths.templateCommonDir
|
|
20
|
+
? path.resolve(projectPaths.templateCommonDir)
|
|
21
|
+
: path.join(currentDirname, 'templates/common');
|
|
22
|
+
// Default "common" package output, if none provided
|
|
23
|
+
const commonPackagePath = projectPaths.commonPackageDir
|
|
24
|
+
? path.resolve(projectPaths.commonPackageDir)
|
|
25
|
+
: path.join(process.cwd(), 'packages/common');
|
|
26
|
+
console.log('--- Debug Info (setupCommonPackage) ---');
|
|
27
|
+
console.log('templatePath:', templatePath);
|
|
28
|
+
console.log('commonPackagePath:', commonPackagePath);
|
|
29
|
+
// 1) Remove existing directory
|
|
30
|
+
fs.removeSync(commonPackagePath);
|
|
31
|
+
// 2) Recreate it
|
|
32
|
+
fs.ensureDirSync(commonPackagePath);
|
|
33
|
+
// 3) Copy template into it
|
|
34
|
+
if (!fs.existsSync(templatePath)) {
|
|
35
|
+
console.error(`Template path not found: ${templatePath}`);
|
|
36
|
+
console.error('Check your config or directory layout.');
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
// Copy with specific options to preserve templates
|
|
40
|
+
fs.copySync(templatePath, commonPackagePath, {
|
|
41
|
+
overwrite: true,
|
|
42
|
+
filter: (src) => {
|
|
43
|
+
// Don't ignore any files in templates directory
|
|
44
|
+
if (src.includes('templates')) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
// Default filtering (ignores node_modules, etc)
|
|
48
|
+
return !src.includes('node_modules');
|
|
49
|
+
},
|
|
50
|
+
// transform: (src, dest) => {
|
|
51
|
+
// // Get the base filename
|
|
52
|
+
// const basename = path.basename(dest);
|
|
53
|
+
// // If it's a template file, rename it by removing the template extension
|
|
54
|
+
// if (basename.endsWith('.template') || basename.endsWith('.tpl')) {
|
|
55
|
+
// const newPath = path.join(path.dirname(dest), stripTemplateExtension(basename));
|
|
56
|
+
// // Move to new path without template extension
|
|
57
|
+
// fs.moveSync(dest, newPath, { overwrite: true });
|
|
58
|
+
// }
|
|
59
|
+
// return undefined; // No content transformation needed
|
|
60
|
+
// },
|
|
61
|
+
});
|
|
62
|
+
// Then rename “.template” or “.tpl” files post-copy (pseudo-code):
|
|
63
|
+
const allCopiedFiles = fs.readdirSync(commonPackagePath);
|
|
64
|
+
allCopiedFiles.forEach((file) => {
|
|
65
|
+
if (file.endsWith('.template') || file.endsWith('.tpl')) {
|
|
66
|
+
const oldPath = path.join(commonPackagePath, file);
|
|
67
|
+
const newName = stripTemplateExtension(file);
|
|
68
|
+
const newPath = path.join(commonPackagePath, newName);
|
|
69
|
+
fs.moveSync(oldPath, newPath, { overwrite: true });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
console.log('Module generated from template!');
|
|
73
|
+
}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;;;;;AAKG;AACa,SAAA,kBAAkB,CA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,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;SACxC;;;;;;;;;;;;AAcJ,KAAA,CAAC,CAAC;;IAEH,MAAM,cAAc,GAAG,EAAE,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;AACzD,IAAA,cAAc,CAAC,OAAO,CAAC,CAAC,IAAI,KAAI;AAC5B,QAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACrD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;AACnD,YAAA,MAAM,OAAO,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;YAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;AACtD,YAAA,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;SACtD;AACL,KAAC,CAAC,CAAC;AAEH,IAAA,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AACnD"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
interface ProjectPaths {
|
|
2
|
+
templateCommonDir?: string;
|
|
3
|
+
commonPackageDir?: string;
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
6
|
* Clears and re-creates the "common" package directory,
|
|
3
7
|
* then copies the template content there.
|
|
4
8
|
*
|
|
5
|
-
* Provide optional
|
|
9
|
+
* Provide optional projectPaths to override defaults.
|
|
6
10
|
*/
|
|
7
|
-
export declare function setupCommonPackage(projectPaths?:
|
|
11
|
+
export declare function setupCommonPackage(projectPaths?: ProjectPaths): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fs from'fs-extra';import path__default from'path';import {fileURLToPath}from'url';const currentFilename = fileURLToPath(import.meta.url);
|
|
2
|
+
const currentDirname = path__default.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
|
+
* Clears and re-creates the "common" package directory,
|
|
13
|
+
* then copies the template content there.
|
|
14
|
+
*
|
|
15
|
+
* Provide optional projectPaths to override defaults.
|
|
16
|
+
*/
|
|
17
|
+
function setupCommonPackage(projectPaths = {}) {
|
|
18
|
+
// Default template path, if none provided in projectPaths
|
|
19
|
+
const templatePath = projectPaths.templateCommonDir
|
|
20
|
+
? path__default.resolve(projectPaths.templateCommonDir)
|
|
21
|
+
: path__default.join(currentDirname, 'templates/common');
|
|
22
|
+
// Default "common" package output, if none provided
|
|
23
|
+
const commonPackagePath = projectPaths.commonPackageDir
|
|
24
|
+
? path__default.resolve(projectPaths.commonPackageDir)
|
|
25
|
+
: path__default.join(process.cwd(), 'packages/common');
|
|
26
|
+
console.log('--- Debug Info (setupCommonPackage) ---');
|
|
27
|
+
console.log('templatePath:', templatePath);
|
|
28
|
+
console.log('commonPackagePath:', commonPackagePath);
|
|
29
|
+
// 1) Remove existing directory
|
|
30
|
+
fs.removeSync(commonPackagePath);
|
|
31
|
+
// 2) Recreate it
|
|
32
|
+
fs.ensureDirSync(commonPackagePath);
|
|
33
|
+
// 3) Copy template into it
|
|
34
|
+
if (!fs.existsSync(templatePath)) {
|
|
35
|
+
console.error(`Template path not found: ${templatePath}`);
|
|
36
|
+
console.error('Check your config or directory layout.');
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
// Copy with specific options to preserve templates
|
|
40
|
+
fs.copySync(templatePath, commonPackagePath, {
|
|
41
|
+
overwrite: true,
|
|
42
|
+
filter: (src) => {
|
|
43
|
+
// Don't ignore any files in templates directory
|
|
44
|
+
if (src.includes('templates')) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
// Default filtering (ignores node_modules, etc)
|
|
48
|
+
return !src.includes('node_modules');
|
|
49
|
+
},
|
|
50
|
+
// transform: (src, dest) => {
|
|
51
|
+
// // Get the base filename
|
|
52
|
+
// const basename = path.basename(dest);
|
|
53
|
+
// // If it's a template file, rename it by removing the template extension
|
|
54
|
+
// if (basename.endsWith('.template') || basename.endsWith('.tpl')) {
|
|
55
|
+
// const newPath = path.join(path.dirname(dest), stripTemplateExtension(basename));
|
|
56
|
+
// // Move to new path without template extension
|
|
57
|
+
// fs.moveSync(dest, newPath, { overwrite: true });
|
|
58
|
+
// }
|
|
59
|
+
// return undefined; // No content transformation needed
|
|
60
|
+
// },
|
|
61
|
+
});
|
|
62
|
+
// Then rename “.template” or “.tpl” files post-copy (pseudo-code):
|
|
63
|
+
const allCopiedFiles = fs.readdirSync(commonPackagePath);
|
|
64
|
+
allCopiedFiles.forEach((file) => {
|
|
65
|
+
if (file.endsWith('.template') || file.endsWith('.tpl')) {
|
|
66
|
+
const oldPath = path__default.join(commonPackagePath, file);
|
|
67
|
+
const newName = stripTemplateExtension(file);
|
|
68
|
+
const newPath = path__default.join(commonPackagePath, newName);
|
|
69
|
+
fs.moveSync(oldPath, newPath, { overwrite: true });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
console.log('Module generated from template!');
|
|
73
|
+
}export{setupCommonPackage};//# sourceMappingURL=setupCommonPackage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupCommonPackage.js","sources":["../../../src/tools/codegen/setupCommonPackage.ts"],"sourcesContent":[null],"names":["path"],"mappings":"yFAUA,MAAM,eAAe,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvD,MAAM,cAAc,GAAGA,aAAI,CAAC,OAAO,CAAC,eAAe,CAAC,C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,SAAS,EAAE,IAAI;AACf,QAAA,MAAM,EAAE,CAAC,GAAG,KAAI;;AAEZ,YAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;AAC3B,gBAAA,OAAO,IAAI,CAAC;aACf;;AAED,YAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;SACxC;;;;;;;;;;;;AAcJ,KAAA,CAAC,CAAC;;IAEH,MAAM,cAAc,GAAG,EAAE,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;AACzD,IAAA,cAAc,CAAC,OAAO,CAAC,CAAC,IAAI,KAAI;AAC5B,QAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACrD,MAAM,OAAO,GAAGA,aAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;AACnD,YAAA,MAAM,OAAO,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;YAC7C,MAAM,OAAO,GAAGA,aAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;AACtD,YAAA,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;SACtD;AACL,KAAC,CAAC,CAAC;AAEH,IAAA,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AACnD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "common",
|
|
3
|
+
"version": "3.1.1-alpha.7",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "AdminIDE core for higher packages to depend on",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"author": "CDMBase LLC",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"module": "lib/index.js",
|
|
11
|
+
"typings": "lib/index.d.ts",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "npm run build:clean && npm run build:lib",
|
|
14
|
+
"build:clean": "rimraf lib",
|
|
15
|
+
"build:lib": "rollup -c rollup.config.mjs",
|
|
16
|
+
"build:lib:watch": "npm run build:lib -- -w",
|
|
17
|
+
"watch": "npm run build:lib:watch"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"rollup-plugin-multi-input": "1.5.0"
|
|
21
|
+
},
|
|
22
|
+
"typescript": {
|
|
23
|
+
"definition": "lib/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createRollupConfig } from '../../rollup.config.base.mjs';
|
|
2
|
+
import multiInput from 'rollup-plugin-multi-input';
|
|
3
|
+
|
|
4
|
+
const additionalPlugins = [multiInput()];
|
|
5
|
+
// Use the createRollupConfig function to merge the base and specific configurations
|
|
6
|
+
export default (commandLineArgs) => {
|
|
7
|
+
const isWatchMode = commandLineArgs.watch;
|
|
8
|
+
return [
|
|
9
|
+
createRollupConfig(
|
|
10
|
+
{
|
|
11
|
+
input: ['src/**/*.{ts,tsx}'],
|
|
12
|
+
plugins: [
|
|
13
|
+
// Spread in additional plugins specific to this config
|
|
14
|
+
...additionalPlugins,
|
|
15
|
+
],
|
|
16
|
+
output: [
|
|
17
|
+
{
|
|
18
|
+
dir: 'lib',
|
|
19
|
+
format: 'es',
|
|
20
|
+
name: 'common',
|
|
21
|
+
compact: true,
|
|
22
|
+
exports: 'named',
|
|
23
|
+
sourcemap: true,
|
|
24
|
+
preserveModules: true,
|
|
25
|
+
chunkFileNames: '[name]-[hash].[format].js',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
isWatchMode,
|
|
30
|
+
),
|
|
31
|
+
];
|
|
32
|
+
};
|
package/lib/tools/codegen/templates/common/src/{apollo-context.d.ts → apollo-context.ts.template}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
1
2
|
import { DataProxy } from '@apollo/client/cache';
|
|
2
3
|
import { ApolloClient } from '@apollo/client/index.js';
|
|
3
4
|
import { CdmLogger } from '@cdm-logger/core';
|
|
@@ -10,6 +11,7 @@ import { IUserContext, IUserProfile, IIAuth0Token, IAuthStrategyEnum } from './g
|
|
|
10
11
|
* @export
|
|
11
12
|
* @interface MyContext
|
|
12
13
|
*/
|
|
14
|
+
|
|
13
15
|
export interface ClientContext {
|
|
14
16
|
/**
|
|
15
17
|
* Only application on the client side
|
|
@@ -18,18 +20,16 @@ export interface ClientContext {
|
|
|
18
20
|
/**
|
|
19
21
|
* Only application on the client side
|
|
20
22
|
*/
|
|
21
|
-
getCacheKey: (options: {
|
|
22
|
-
__typename: string;
|
|
23
|
-
id?: string;
|
|
24
|
-
}) => string;
|
|
23
|
+
getCacheKey: (options: { __typename: string; id?: string }) => string;
|
|
25
24
|
/**
|
|
26
25
|
* Only applicable on the client side
|
|
27
26
|
*/
|
|
28
|
-
apolloClient: ApolloClient<any>;
|
|
27
|
+
apolloClient: ApolloClient<any>; // deprecated use `client` instead
|
|
29
28
|
client: ApolloClient<any>;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
}
|
|
30
|
+
|
|
31
|
+
export interface IDataSources {}
|
|
32
|
+
|
|
33
33
|
export interface IHttpMiddlewareContext {
|
|
34
34
|
req?: express.Request & {
|
|
35
35
|
authStrategy: IAuthStrategyEnum | string;
|
|
@@ -55,5 +55,4 @@ export interface ServerContext extends IHttpMiddlewareContext {
|
|
|
55
55
|
preferences: IPreferncesTransformed[];
|
|
56
56
|
accountService?: any;
|
|
57
57
|
}
|
|
58
|
-
export interface MyContext extends ClientContext, ServerContext {
|
|
59
|
-
}
|
|
58
|
+
export interface MyContext extends ClientContext, ServerContext {}
|
package/lib/tools/codegen/templates/common/src/{configuration.d.ts → configuration.ts.template}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const enum ConfigurationTarget {
|
|
2
2
|
/**
|
|
3
3
|
* Targets the user/application configuraton file for writing.
|
|
4
4
|
*/
|
|
@@ -6,27 +6,27 @@ export declare const enum ConfigurationTarget {
|
|
|
6
6
|
/**
|
|
7
7
|
* Targets the application configuration file for writing.
|
|
8
8
|
*/
|
|
9
|
-
APPLICATION
|
|
9
|
+
APPLICATION,
|
|
10
10
|
/**
|
|
11
11
|
* Targets the machine configuration file for writing. This only works if a machine is opened.
|
|
12
12
|
*/
|
|
13
|
-
MACHINE
|
|
13
|
+
MACHINE,
|
|
14
14
|
/**
|
|
15
15
|
* Targets the organization configuration file for writing. This only works if organization is opened.
|
|
16
16
|
*/
|
|
17
|
-
ORGANIZATION
|
|
17
|
+
ORGANIZATION,
|
|
18
18
|
/**
|
|
19
19
|
* Targets the resource configuration file for writing. This only works if a organization is opened.
|
|
20
20
|
*/
|
|
21
|
-
ORGANIZATION_RESOURCE
|
|
22
|
-
DEFAULT
|
|
23
|
-
MEMORY
|
|
21
|
+
ORGANIZATION_RESOURCE,
|
|
22
|
+
DEFAULT,
|
|
23
|
+
MEMORY,
|
|
24
24
|
/**
|
|
25
25
|
* Resource specific configuration that can be configured
|
|
26
26
|
*/
|
|
27
|
-
RESOURCE_OVERRIDABLE
|
|
27
|
+
RESOURCE_OVERRIDABLE,
|
|
28
28
|
/**
|
|
29
29
|
* Machine specific conifugration that can also be configured
|
|
30
30
|
*/
|
|
31
|
-
MACHINE_OVERRIDABLE
|
|
31
|
+
MACHINE_OVERRIDABLE,
|
|
32
32
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DUMMY = 'dummy';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es2017",
|
|
5
|
+
"lib": ["es2017"],
|
|
6
|
+
"resolveJsonModule": true,
|
|
7
|
+
"allowSyntheticDefaultImports": true,
|
|
8
|
+
"experimentalDecorators": true,
|
|
9
|
+
"rootDir": "src",
|
|
10
|
+
"outDir": "lib",
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"preserveConstEnums": true,
|
|
13
|
+
"declarationDir": "lib",
|
|
14
|
+
"skipLibCheck": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src"],
|
|
17
|
+
"exclude": ["../../../node_modules", "node_modules", "lib", "lib", "webpack.config.js", "rollup.config.mjs"]
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common-stack/rollup-vite-utils",
|
|
3
|
-
"version": "6.0.8-alpha.
|
|
3
|
+
"version": "6.0.8-alpha.26",
|
|
4
4
|
"description": "Client Module for react app",
|
|
5
5
|
"homepage": "https://github.com/cdmbase/fullstack-pro#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "f9b08c8531a2e8e7fb23635840fc65d4feefabe5",
|
|
60
60
|
"typescript": {
|
|
61
61
|
"definition": "lib/index.d.ts"
|
|
62
62
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const DUMMY = "dummy";
|
|
File without changes
|