@common-stack/generate-plugin 6.0.1-alpha.9 → 6.0.2-alpha.2
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/.eslintrc.json +1 -1
- package/CHANGELOG.md +12 -0
- package/README.md +280 -10
- package/cde-config.json +86 -0
- package/executors.json +14 -0
- package/generators.json +15 -0
- package/lib/constants/index.cjs +2 -1
- package/lib/constants/index.cjs.map +1 -1
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.mjs +2 -1
- package/lib/constants/index.mjs.map +1 -1
- package/lib/executors/sort-package-json/executor.cjs +46 -0
- package/lib/executors/sort-package-json/executor.cjs.map +1 -0
- package/lib/executors/sort-package-json/executor.d.ts +4 -0
- package/lib/executors/sort-package-json/executor.mjs +46 -0
- package/lib/executors/sort-package-json/executor.mjs.map +1 -0
- package/lib/executors/sort-package-json/executor.spec.d.ts +1 -0
- package/lib/executors/sort-package-json/schema.json +9 -0
- package/lib/executors/update-deploy-version/executor.cjs +22 -0
- package/lib/executors/update-deploy-version/executor.cjs.map +1 -0
- package/lib/executors/update-deploy-version/executor.d.ts +4 -0
- package/lib/executors/update-deploy-version/executor.mjs +22 -0
- package/lib/executors/update-deploy-version/executor.mjs.map +1 -0
- package/lib/executors/update-deploy-version/executor.spec.d.ts +1 -0
- package/lib/executors/update-deploy-version/schema.json +14 -0
- package/lib/generators/add-backend/files/CHANGELOG.md +0 -0
- package/lib/generators/add-backend/files/Dockerfile +1 -1
- package/lib/generators/add-backend/files/package.json +1 -18
- package/lib/generators/add-backend/files/tsconfig.json +1 -1
- package/lib/generators/add-backend/files/webpack.config.js +6 -10
- package/lib/generators/add-backend/generator.cjs +21 -17
- package/lib/generators/add-backend/generator.cjs.map +1 -1
- package/lib/generators/add-backend/generator.d.ts +1 -0
- package/lib/generators/add-backend/generator.mjs +21 -17
- package/lib/generators/add-backend/generator.mjs.map +1 -1
- package/lib/generators/add-browser-package/files/package.json +2 -2
- package/lib/generators/add-browser-package/generator.cjs +14 -16
- package/lib/generators/add-browser-package/generator.cjs.map +1 -1
- package/lib/generators/add-browser-package/generator.d.ts +1 -0
- package/lib/generators/add-browser-package/generator.mjs +14 -16
- package/lib/generators/add-browser-package/generator.mjs.map +1 -1
- package/lib/generators/add-client-package/files/CHANGELOG.md +807 -0
- package/lib/generators/add-client-package/files/LICENSE +674 -0
- package/lib/generators/add-client-package/files/jest.config.js +13 -0
- package/lib/generators/add-client-package/files/package.json +30 -0
- package/lib/generators/add-client-package/files/rollup.config.mjs +29 -0
- package/lib/generators/add-client-package/files/src/components/index.tsx.template +1 -0
- package/lib/generators/add-client-package/files/src/index.ts.template +1 -0
- package/lib/generators/add-client-package/files/tsconfig.json +27 -0
- package/lib/generators/add-client-package/files/webpack.config.js +72 -0
- package/lib/generators/add-client-package/generator.cjs +17 -0
- package/lib/generators/add-client-package/generator.cjs.map +1 -0
- package/lib/generators/add-client-package/generator.d.ts +5 -0
- package/lib/generators/add-client-package/generator.mjs +17 -0
- package/lib/generators/add-client-package/generator.mjs.map +1 -0
- package/lib/generators/add-client-package/generator.spec.d.ts +1 -0
- package/lib/generators/add-client-package/schema.json +19 -0
- package/lib/generators/add-core-package/files/CHANGELOG.md +1076 -0
- package/lib/generators/add-core-package/files/LICENSE +39 -0
- package/lib/generators/add-core-package/files/jest.config.js +3 -0
- package/lib/generators/add-core-package/files/package.json +30 -0
- package/lib/generators/add-core-package/files/rollup.config.mjs +65 -0
- package/lib/generators/add-core-package/files/src/constants/index.ts.template +1 -0
- package/lib/generators/add-core-package/files/src/constants/types.ts.template +3 -0
- package/lib/generators/add-core-package/files/src/index.ts.template +2 -0
- package/lib/generators/add-core-package/files/src/types/index.ts.template +1 -0
- package/lib/generators/add-core-package/files/src/types/types.ts.template +17 -0
- package/lib/generators/add-core-package/files/tsconfig.json +22 -0
- package/lib/generators/add-core-package/files/webpack.config.js +53 -0
- package/lib/generators/add-core-package/generator.cjs +17 -0
- package/lib/generators/add-core-package/generator.cjs.map +1 -0
- package/lib/generators/add-core-package/generator.d.ts +5 -0
- package/lib/generators/add-core-package/generator.mjs +17 -0
- package/lib/generators/add-core-package/generator.mjs.map +1 -0
- package/lib/generators/add-core-package/generator.spec.d.ts +1 -0
- package/lib/generators/add-core-package/schema.json +19 -0
- package/lib/generators/add-frontend/frameworks/tailwindui/entry.client.tsx.template +90 -0
- package/lib/generators/add-frontend/frameworks/tailwindui/entry.server.tsx.template +238 -0
- package/lib/generators/add-frontend/frameworks/tailwindui/root.tsx.template +117 -0
- package/lib/generators/add-frontend/frameworks/tailwindui/tailwind.css +3 -0
- package/lib/generators/add-frontend/generator.cjs +60 -42
- package/lib/generators/add-frontend/generator.cjs.map +1 -1
- package/lib/generators/add-frontend/generator.d.ts +1 -0
- package/lib/generators/add-frontend/generator.mjs +60 -42
- package/lib/generators/add-frontend/generator.mjs.map +1 -1
- package/lib/generators/add-frontend/schema.json +1 -1
- package/lib/generators/add-frontend/templates/package.json +18 -76
- package/lib/generators/add-frontend/templates/postcss.config.js +6 -0
- package/lib/generators/add-frontend/templates/tailwind.config.ts.template +12 -0
- package/lib/generators/add-fullstack/files/jest-mongodb-config.js +3 -2
- package/lib/generators/add-fullstack/files/jest.config copy.js +27 -0
- package/lib/generators/add-fullstack/files/jest.config.base.js +43 -4
- package/lib/generators/add-fullstack/files/jest.config.base.mjs +99 -0
- package/lib/generators/add-fullstack/files/jest.config.mongodb.mjs +3 -0
- package/lib/generators/add-fullstack/files/lint-staged.config.js +4 -1
- package/lib/generators/add-fullstack/files/nx.json +18 -13
- package/lib/generators/add-fullstack/files/package.json +8 -8
- package/lib/generators/add-fullstack/files/tools/cli/helpers/util.js +1 -1
- package/lib/generators/add-fullstack/files/tools/deploy-cli/updateLernaVersion.js +1 -1
- package/lib/generators/add-fullstack/files/tools/prettier.config.js +8 -0
- package/lib/generators/add-fullstack/files/tools/rollup/rollupPluginGenerateJson.mjs +48 -0
- package/lib/generators/add-fullstack/files/tools/rollup/rollupPluginModifyLibFiles.mjs +410 -0
- package/lib/generators/add-fullstack/files/tools/runLint.mjs +15 -0
- package/lib/generators/add-fullstack/files/tools/sortPackageJson.mjs +0 -1
- package/lib/generators/add-fullstack/files/tools/update-dependencies.mjs +95 -0
- package/lib/generators/add-fullstack/files/tools/update-dependency-link.mjs +138 -0
- package/lib/generators/add-fullstack/files/tools/update-dependency-version.js +104 -89
- package/lib/generators/add-fullstack/files/tools/updateUtils.mjs +77 -0
- package/lib/generators/add-fullstack/generator.cjs +63 -2
- package/lib/generators/add-fullstack/generator.cjs.map +1 -1
- package/lib/generators/add-fullstack/generator.mjs +63 -2
- package/lib/generators/add-fullstack/generator.mjs.map +1 -1
- package/lib/generators/add-fullstack/schema.json +4 -0
- package/lib/generators/add-moleculer/files/package.json +7 -7
- package/lib/generators/add-moleculer/generator.cjs +14 -16
- package/lib/generators/add-moleculer/generator.cjs.map +1 -1
- package/lib/generators/add-moleculer/generator.d.ts +1 -0
- package/lib/generators/add-moleculer/generator.mjs +14 -16
- package/lib/generators/add-moleculer/generator.mjs.map +1 -1
- package/lib/generators/add-server-package/files/CHANGELOG.md +2599 -0
- package/lib/generators/add-server-package/files/LICENSE +674 -0
- package/lib/generators/add-server-package/files/jest.config.js +32 -0
- package/lib/generators/add-server-package/files/package.json +78 -0
- package/lib/generators/add-server-package/files/rollup.config.mjs +30 -0
- package/lib/generators/add-server-package/files/src/constants/constants.ts.template +62 -0
- package/lib/generators/add-server-package/files/src/constants/index.ts.template +1 -0
- package/lib/generators/add-server-package/files/src/constants/types.ts.template +21 -0
- package/lib/generators/add-server-package/files/src/index.ts.template +6 -0
- package/lib/generators/add-server-package/files/src/module.ts.template +6 -0
- package/lib/generators/add-server-package/files/tsconfig.json +27 -0
- package/lib/generators/add-server-package/generator.cjs +17 -0
- package/lib/generators/add-server-package/generator.cjs.map +1 -0
- package/lib/generators/add-server-package/generator.d.ts +5 -0
- package/lib/generators/add-server-package/generator.mjs +17 -0
- package/lib/generators/add-server-package/generator.mjs.map +1 -0
- package/lib/generators/add-server-package/generator.spec.d.ts +1 -0
- package/lib/generators/add-server-package/schema.json +19 -0
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +5 -0
- package/lib/index.mjs +1 -1
- package/package.json +4 -2
- package/project.json +12 -1
- package/rollup.config.mjs +8 -0
- package/src/constants/index.ts +2 -1
- package/src/executors/sort-package-json/executor.spec.ts +18 -0
- package/src/executors/sort-package-json/executor.ts +53 -0
- package/src/executors/sort-package-json/schema.d.ts +1 -0
- package/src/executors/sort-package-json/schema.json +9 -0
- package/src/executors/update-deploy-version/executor.spec.ts +18 -0
- package/src/executors/update-deploy-version/executor.ts +36 -0
- package/src/executors/update-deploy-version/schema.d.ts +3 -0
- package/src/executors/update-deploy-version/schema.json +14 -0
- package/src/generators/add-backend/generator.ts +8 -4
- package/src/generators/add-browser-package/generator.ts +7 -6
- package/src/generators/add-client-package/generator.spec.ts +20 -0
- package/src/generators/add-client-package/generator.ts +24 -0
- package/src/generators/add-client-package/schema.d.ts +4 -0
- package/src/generators/add-client-package/schema.json +19 -0
- package/src/generators/add-core-package/generator.spec.ts +20 -0
- package/src/generators/add-core-package/generator.ts +24 -0
- package/src/generators/add-core-package/schema.d.ts +4 -0
- package/src/generators/add-core-package/schema.json +19 -0
- package/src/generators/add-frontend/frameworks/tailwindui/entry.client.tsx.template +90 -0
- package/src/generators/add-frontend/frameworks/tailwindui/entry.server.tsx.template +238 -0
- package/src/generators/add-frontend/frameworks/tailwindui/root.tsx.template +117 -0
- package/src/generators/add-frontend/frameworks/tailwindui/tailwind.css +3 -0
- package/src/generators/add-frontend/generator.ts +24 -2
- package/src/generators/add-frontend/schema.json +1 -1
- package/src/generators/add-fullstack/files/jest-mongodb-config.js +3 -2
- package/src/generators/add-fullstack/files/jest.config copy.js +27 -0
- package/src/generators/add-fullstack/files/jest.config.base.js +43 -4
- package/src/generators/add-fullstack/files/jest.config.base.mjs +99 -0
- package/src/generators/add-fullstack/files/jest.config.mongodb.mjs +3 -0
- package/src/generators/add-fullstack/files/lint-staged.config.js +4 -1
- package/src/generators/add-fullstack/files/nx.json +18 -13
- package/src/generators/add-fullstack/files/package.json +8 -8
- package/src/generators/add-fullstack/files/tools/cli/helpers/util.js +1 -1
- package/src/generators/add-fullstack/files/tools/deploy-cli/updateLernaVersion.js +1 -1
- package/src/generators/add-fullstack/files/tools/prettier.config.js +8 -0
- package/src/generators/add-fullstack/files/tools/rollup/rollupPluginGenerateJson.mjs +48 -0
- package/src/generators/add-fullstack/files/tools/rollup/rollupPluginModifyLibFiles.mjs +410 -0
- package/src/generators/add-fullstack/files/tools/runLint.mjs +15 -0
- package/src/generators/add-fullstack/files/tools/sortPackageJson.mjs +0 -1
- package/src/generators/add-fullstack/files/tools/update-dependencies.mjs +95 -0
- package/src/generators/add-fullstack/files/tools/update-dependency-link.mjs +138 -0
- package/src/generators/add-fullstack/files/tools/update-dependency-version.js +104 -89
- package/src/generators/add-fullstack/files/tools/updateUtils.mjs +77 -0
- package/src/generators/add-fullstack/generator.ts +83 -1
- package/src/generators/add-fullstack/schema.d.ts +1 -0
- package/src/generators/add-fullstack/schema.json +4 -0
- package/src/generators/add-moleculer/files/package.json +7 -7
- package/src/generators/add-moleculer/generator.ts +7 -6
- package/src/generators/add-server-package/generator.spec.ts +20 -0
- package/src/generators/add-server-package/generator.ts +24 -0
- package/src/generators/add-server-package/schema.d.ts +4 -0
- package/src/generators/add-server-package/schema.json +19 -0
- package/src/index.ts +5 -0
- package/lib/generators/add-backend/files/knexfile.js +0 -63
- package/lib/generators/add-backend/files/src/api/remote-config.ts.template +0 -11
- package/lib/generators/add-backend/files/src/api/resolver.ts.template +0 -15
- package/lib/generators/add-backend/files/src/api/scalar.ts.template +0 -16
- package/lib/generators/add-backend/files/src/api/schema-builder.ts.template +0 -189
- package/lib/generators/add-backend/files/src/api/utils.ts.template +0 -44
- package/lib/generators/add-backend/files/src/config/moleculer.config.ts.template +0 -228
- package/lib/generators/add-backend/files/src/connectors/connection-broker.ts.template +0 -80
- package/lib/generators/add-backend/files/src/connectors/graphql-pubsub-connector.ts.template +0 -43
- package/lib/generators/add-backend/files/src/connectors/mongo-connector.ts.template +0 -78
- package/lib/generators/add-backend/files/src/connectors/nats-connector.ts.template +0 -82
- package/lib/generators/add-backend/files/src/connectors/redis-connector.ts.template +0 -73
- package/lib/generators/add-backend/files/src/express-app.ts.template +0 -67
- package/lib/generators/add-backend/files/src/interfaces/index.ts.template +0 -1
- package/lib/generators/add-backend/files/src/interfaces/module-interface.ts.template +0 -16
- package/lib/generators/add-backend/files/src/main.spec.ts.template +0 -129
- package/lib/generators/add-backend/files/src/middleware/__tests__/cors.test.ts.template +0 -12
- package/lib/generators/add-backend/files/src/middleware/cors.ts.template +0 -31
- package/lib/generators/add-backend/files/src/middleware/error.ts.template +0 -63
- package/lib/generators/add-backend/files/src/middleware/moleculer-inter-namespace.ts.template +0 -60
- package/lib/generators/add-backend/files/src/middleware/persistedQuery.ts.template +0 -40
- package/lib/generators/add-backend/files/src/middleware/sentry.ts.template +0 -9
- package/lib/generators/add-backend/files/src/middleware/services.ts.template +0 -16
- package/lib/generators/add-backend/files/src/middleware/tracer.ts.template +0 -24
- package/lib/generators/add-backend/files/src/modules/auth/schema/auth-schema.graphql +0 -25
- package/lib/generators/add-backend/files/src/server-setup/graphql-server.ts.template +0 -185
- package/lib/generators/add-backend/files/src/server-setup/graphql-subscription-server.ts.template +0 -113
- package/lib/generators/add-backend/files/src/server-setup/graphql-ws.ts.template +0 -158
- package/lib/generators/add-backend/files/src/server-setup/mongodb-migration-update.ts.template +0 -47
- package/lib/generators/add-backend/files/src/server-setup/utils.ts.template +0 -43
- package/lib/generators/add-backend/files/src/server-setup/websocket-multipath-update.ts.template +0 -88
- package/lib/generators/add-backend/files/src/stack-server.ts.template +0 -277
- package/lib/generators/add-backend/files/src/utils/migrations.ts.template +0 -32
- package/lib/generators/add-backend/files/uploads/3986781.ppt +0 -0
- package/lib/generators/add-fullstack/files/tools/update-dependency-link.js +0 -107
- package/src/generators/add-fullstack/files/tools/update-dependency-link.js +0 -107
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { parse } from '@babel/parser';
|
|
4
|
+
import traverse from '@babel/traverse';
|
|
5
|
+
import generate from '@babel/generator';
|
|
6
|
+
import * as t from '@babel/types';
|
|
7
|
+
import { promisify } from 'util';
|
|
8
|
+
import glob from 'glob';
|
|
9
|
+
import { createFilter } from '@rollup/pluginutils';
|
|
10
|
+
const globPromise = promisify(glob.glob); // Make sure to call .glob here
|
|
11
|
+
|
|
12
|
+
function findPackageJson(directory) {
|
|
13
|
+
let currentDir = directory;
|
|
14
|
+
while (currentDir && currentDir !== path.parse(currentDir).root) {
|
|
15
|
+
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
16
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
17
|
+
return packageJsonPath;
|
|
18
|
+
}
|
|
19
|
+
currentDir = path.dirname(currentDir);
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`No package.json found in path ${directory}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const RouteModule = {
|
|
25
|
+
action: 'action',
|
|
26
|
+
hasAction: 'hasAction',
|
|
27
|
+
clientAction: 'clientAction',
|
|
28
|
+
hasClientAction: 'hasClientAction',
|
|
29
|
+
clientLoader: 'clientLoader',
|
|
30
|
+
hasClientLoader: 'hasClientLoader',
|
|
31
|
+
Component: 'default', // default export
|
|
32
|
+
hasComponent: 'hasComponent',
|
|
33
|
+
ErrorBoundary: 'ErrorBoundary',
|
|
34
|
+
hasErrorBoundary: 'hasErrorBoundary',
|
|
35
|
+
handle: 'handle',
|
|
36
|
+
hasHandle: 'hasHandle',
|
|
37
|
+
headers: 'headers',
|
|
38
|
+
hasHeaders: 'hasHeaders',
|
|
39
|
+
HydrateFallback: 'HydrateFallback',
|
|
40
|
+
hasHydrateFallback: 'hasHydrateFallback',
|
|
41
|
+
links: 'links',
|
|
42
|
+
hasLinks: 'hasLinks',
|
|
43
|
+
loader: 'loader',
|
|
44
|
+
hasLoader: 'hasLoader',
|
|
45
|
+
meta: 'meta',
|
|
46
|
+
hasMeta: 'hasMeta',
|
|
47
|
+
shouldRevalidate: 'shouldRevalidate',
|
|
48
|
+
hasShouldRevalidate: 'hasShouldRevalidate',
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
function modifyDeferReturn(filePath, loaderName) {
|
|
53
|
+
const fileContent = fs.readFileSync(filePath, 'utf8');
|
|
54
|
+
const ast = parse(fileContent, {
|
|
55
|
+
sourceType: 'module',
|
|
56
|
+
plugins: ['typescript', 'jsx'],
|
|
57
|
+
});
|
|
58
|
+
console.log('---MODIFY LOADER -- filepath', filePath, '---loaderName', loaderName);
|
|
59
|
+
let modified = false; // flag to check if changes were made
|
|
60
|
+
|
|
61
|
+
let deferKeys = [];
|
|
62
|
+
traverse.default(ast, {
|
|
63
|
+
// Handle all function types
|
|
64
|
+
'FunctionDeclaration|ArrowFunctionExpression|FunctionExpression'(path) {
|
|
65
|
+
// Check if this function is the loader by comparing the names or context
|
|
66
|
+
let functionName = path.node.id ? path.node.id.name : null;
|
|
67
|
+
if (!functionName && path.parent && path.parent.id) {
|
|
68
|
+
functionName = path.parent.id.name; // For functions assigned to variables
|
|
69
|
+
}
|
|
70
|
+
// Match by function name or check if it's a default export or a direct export
|
|
71
|
+
if (
|
|
72
|
+
functionName === loaderName ||
|
|
73
|
+
path.parent.type === 'ExportDefaultDeclaration' ||
|
|
74
|
+
(path.parent.type === 'ExportNamedDeclaration' && path.parent.declaration === path.node)
|
|
75
|
+
) {
|
|
76
|
+
// Traverse into the function body to look for ReturnStatement using defer
|
|
77
|
+
path.traverse({
|
|
78
|
+
ReturnStatement(returnPath) {
|
|
79
|
+
if (
|
|
80
|
+
returnPath.node.argument &&
|
|
81
|
+
returnPath.node.argument.type === 'CallExpression' &&
|
|
82
|
+
returnPath.node.argument.callee.name === 'defer'
|
|
83
|
+
) {
|
|
84
|
+
// Check if the first argument of defer is an object with properties to unwrap
|
|
85
|
+
if (
|
|
86
|
+
returnPath.node.argument.arguments.length > 0 &&
|
|
87
|
+
returnPath.node.argument.arguments[0].type === 'ObjectExpression' &&
|
|
88
|
+
returnPath.node.argument.arguments[0].properties.length > 0
|
|
89
|
+
) {
|
|
90
|
+
const properties = returnPath.node.argument.arguments[0].properties;
|
|
91
|
+
const valuesArray = properties.map(prop => prop.value); // Map properties to their values
|
|
92
|
+
|
|
93
|
+
properties.forEach((prop) => {
|
|
94
|
+
deferKeys.push(prop.key.name);
|
|
95
|
+
});
|
|
96
|
+
// Simplify the return statement to return the first property's value of the object
|
|
97
|
+
returnPath.node.argument = t.arrayExpression(valuesArray);
|
|
98
|
+
|
|
99
|
+
modified = true; // mark as modified
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (modified) {
|
|
109
|
+
const output = generate.default(ast, {}, fileContent);
|
|
110
|
+
fs.writeFileSync(filePath, output.code);
|
|
111
|
+
console.log(`Loader modified: ${filePath}`);
|
|
112
|
+
} else {
|
|
113
|
+
console.log(`No modifications made to: ${filePath}`);
|
|
114
|
+
}
|
|
115
|
+
return deferKeys;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export default function modifyLibFilesPlugin(options = {}) {
|
|
119
|
+
// Create a filter to only include the desired files
|
|
120
|
+
const filter = createFilter(options.include, options.exclude);
|
|
121
|
+
const dist = options.outputDir || './lib'; // Default output directory
|
|
122
|
+
const pattern = '**/**/compute.js'; // Pattern to match files
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
name: 'modify-lib-files',
|
|
126
|
+
|
|
127
|
+
async writeBundle(outputOptions) {
|
|
128
|
+
const currentWorkingDir = process.cwd();
|
|
129
|
+
// Assuming you want to modify specific files, list them here
|
|
130
|
+
const filesToModify = await globPromise(path.join(dist, pattern), { absolute: true }); // Ensure paths are absolute
|
|
131
|
+
filesToModify.forEach((filePath) => {
|
|
132
|
+
if (!filter(filePath)) return; // Skip files that do not match the filter
|
|
133
|
+
|
|
134
|
+
// Read the file content
|
|
135
|
+
const code = fs.readFileSync(filePath, 'utf8');
|
|
136
|
+
// Parse the code to an AST
|
|
137
|
+
const ast = parse(code, {
|
|
138
|
+
sourceType: 'module',
|
|
139
|
+
plugins: ['js', 'dynamicImport'], // Adjust plugins as necessary
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Traverse and modify the AST as needed
|
|
143
|
+
let modified = false;
|
|
144
|
+
traverse.default(ast, {
|
|
145
|
+
enter(astroPath) {
|
|
146
|
+
// Adjust this part to target the specific objects and properties in your AST
|
|
147
|
+
if (
|
|
148
|
+
astroPath.isObjectProperty() &&
|
|
149
|
+
(astroPath.node.key.name === 'component' || astroPath.node.key.name === 'dialog')
|
|
150
|
+
) {
|
|
151
|
+
const importDeclaration = astroPath.node.value;
|
|
152
|
+
const propName = astroPath.node.key.name;
|
|
153
|
+
|
|
154
|
+
if (
|
|
155
|
+
importDeclaration.type === 'ArrowFunctionExpression' &&
|
|
156
|
+
importDeclaration.body.type === 'CallExpression' &&
|
|
157
|
+
importDeclaration.body.callee.type === 'Import'
|
|
158
|
+
) {
|
|
159
|
+
const importArg = importDeclaration.body.arguments[0];
|
|
160
|
+
|
|
161
|
+
// Ensure we're dealing with a string literal import path
|
|
162
|
+
if (importArg.type === 'StringLiteral') {
|
|
163
|
+
let importPath = importArg.value;
|
|
164
|
+
let hasLoader = false;
|
|
165
|
+
let hasAction = false;
|
|
166
|
+
let hasClientLoader = false;
|
|
167
|
+
let hasClientAction = false;
|
|
168
|
+
let hasComponent = false;
|
|
169
|
+
let hasErrorBoundary = false;
|
|
170
|
+
let hasLinks = false;
|
|
171
|
+
let hasMeta = false;
|
|
172
|
+
let hasHydrateFallback = false;
|
|
173
|
+
let hasShouldRevalidate = false;
|
|
174
|
+
let hasHandle = false;
|
|
175
|
+
let hasHeaders = false;
|
|
176
|
+
let deferKeys = [];
|
|
177
|
+
const fullPath = path.resolve(path.dirname(filePath), importPath);
|
|
178
|
+
if (astroPath.node.key.name === 'component' && fs.existsSync(fullPath)) {
|
|
179
|
+
const importedFileCode = fs.readFileSync(fullPath, 'utf8');
|
|
180
|
+
const importedAst = parse(importedFileCode, {
|
|
181
|
+
sourceType: 'module',
|
|
182
|
+
plugins: ['typescript', 'jsx'],
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
traverse.default(importedAst, {
|
|
186
|
+
ExportNamedDeclaration(namedPath) {
|
|
187
|
+
namedPath.node.specifiers.forEach((specifier) => {
|
|
188
|
+
if (specifier.exported.name === RouteModule.loader) {
|
|
189
|
+
hasLoader = true;
|
|
190
|
+
let fullPathToLoader;
|
|
191
|
+
if (namedPath.node.source) {
|
|
192
|
+
// Handle re-exported loaders
|
|
193
|
+
const loaderSourcePath = namedPath.node.source.value; // Path of the module
|
|
194
|
+
fullPathToLoader = path.resolve(
|
|
195
|
+
path.dirname(fullPath),
|
|
196
|
+
loaderSourcePath,
|
|
197
|
+
);
|
|
198
|
+
} else {
|
|
199
|
+
fullPathToLoader = fullPath;
|
|
200
|
+
}
|
|
201
|
+
deferKeys = modifyDeferReturn(
|
|
202
|
+
fullPathToLoader,
|
|
203
|
+
specifier.local.name,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
if (specifier.exported.name === RouteModule.action) {
|
|
207
|
+
hasAction = true;
|
|
208
|
+
}
|
|
209
|
+
if (specifier.exported.name === RouteModule.Component) {
|
|
210
|
+
hasComponent = true;
|
|
211
|
+
}
|
|
212
|
+
if (specifier.exported.name === RouteModule.ErrorBoundary) {
|
|
213
|
+
hasErrorBoundary = true;
|
|
214
|
+
}
|
|
215
|
+
if (specifier.exported.name === RouteModule.clientLoader) {
|
|
216
|
+
hasClientLoader = true;
|
|
217
|
+
}
|
|
218
|
+
if (specifier.exported.name === RouteModule.clientAction) {
|
|
219
|
+
hasClientAction = true;
|
|
220
|
+
}
|
|
221
|
+
if (specifier.exported.name === RouteModule.headers) {
|
|
222
|
+
hasHeaders = true;
|
|
223
|
+
}
|
|
224
|
+
if (specifier.exported.name === RouteModule.links) {
|
|
225
|
+
hasLinks = true;
|
|
226
|
+
}
|
|
227
|
+
if (specifier.exported.name === RouteModule.meta) {
|
|
228
|
+
hasMeta = true;
|
|
229
|
+
}
|
|
230
|
+
if (specifier.exported.name === RouteModule.shouldRevalidate) {
|
|
231
|
+
hasShouldRevalidate = true;
|
|
232
|
+
}
|
|
233
|
+
if (specifier.exported.name === RouteModule.HydrateFallback) {
|
|
234
|
+
hasHydrateFallback = true;
|
|
235
|
+
}
|
|
236
|
+
if (specifier.exported.name === RouteModule.handle) {
|
|
237
|
+
hasHandle = true;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
const packageJsonPath = findPackageJson(
|
|
244
|
+
path.dirname(path.resolve(process.cwd(), dist)),
|
|
245
|
+
);
|
|
246
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
247
|
+
const relativePath = path.relative(path.dirname(packageJsonPath), fullPath);
|
|
248
|
+
const normalizedImportPath = relativePath.replace(/\\/g, '/'); // Normalize path for Windows
|
|
249
|
+
|
|
250
|
+
const newImportPath = `${packageJson.name}/${normalizedImportPath}`;
|
|
251
|
+
|
|
252
|
+
// Create a new `file` property
|
|
253
|
+
const fileProperty = t.objectProperty(
|
|
254
|
+
t.identifier(`${propName}Path`),
|
|
255
|
+
t.stringLiteral(newImportPath),
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
// Get the parent object expression to add the new property
|
|
259
|
+
const parentObject = astroPath.findParent((p) => p.isObjectExpression());
|
|
260
|
+
if (parentObject) {
|
|
261
|
+
// remove component
|
|
262
|
+
astroPath.remove();
|
|
263
|
+
parentObject.node.properties.push(fileProperty);
|
|
264
|
+
if (hasLoader) {
|
|
265
|
+
parentObject.node.properties.push(
|
|
266
|
+
t.objectProperty(t.identifier(RouteModule.hasLoader), t.booleanLiteral(true)),
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
if (hasAction) {
|
|
270
|
+
parentObject.node.properties.push(
|
|
271
|
+
t.objectProperty(t.identifier(RouteModule.hasAction), t.booleanLiteral(true)),
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
if (hasClientLoader) {
|
|
275
|
+
parentObject.node.properties.push(
|
|
276
|
+
t.objectProperty(t.identifier(RouteModule.hasClientLoader), t.booleanLiteral(true)),
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
if (hasClientAction) {
|
|
280
|
+
parentObject.node.properties.push(
|
|
281
|
+
t.objectProperty(t.identifier(RouteModule.hasClientAction), t.booleanLiteral(true)),
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
if (hasComponent) {
|
|
285
|
+
parentObject.node.properties.push(
|
|
286
|
+
t.objectProperty(t.identifier(RouteModule.hasComponent), t.booleanLiteral(true)),
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
if (hasErrorBoundary) {
|
|
290
|
+
parentObject.node.properties.push(
|
|
291
|
+
t.objectProperty(t.identifier(RouteModule.hasErrorBoundary), t.booleanLiteral(true)),
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
if (hasHeaders) {
|
|
295
|
+
parentObject.node.properties.push(
|
|
296
|
+
t.objectProperty(t.identifier(RouteModule.hasHeaders), t.booleanLiteral(true)),
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
if (hasHydrateFallback) {
|
|
300
|
+
parentObject.node.properties.push(
|
|
301
|
+
t.objectProperty(t.identifier(RouteModule.hasHydrateFallback), t.booleanLiteral(true)),
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
if (hasMeta) {
|
|
305
|
+
parentObject.node.properties.push(
|
|
306
|
+
t.objectProperty(t.identifier(RouteModule.hasMeta), t.booleanLiteral(true)),
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
if (hasLinks) {
|
|
310
|
+
parentObject.node.properties.push(
|
|
311
|
+
t.objectProperty(t.identifier(RouteModule.hasLinks), t.booleanLiteral(true)),
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
if (hasHandle) {
|
|
315
|
+
parentObject.node.properties.push(
|
|
316
|
+
t.objectProperty(t.identifier(RouteModule.hasHandle), t.booleanLiteral(true)),
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
if (hasShouldRevalidate) {
|
|
320
|
+
parentObject.node.properties.push(
|
|
321
|
+
t.objectProperty(t.identifier(RouteModule.hasShouldRevalidate), t.booleanLiteral(true)),
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
if (deferKeys.length > 0) {
|
|
325
|
+
const deferKeysArrayExpression = t.arrayExpression(
|
|
326
|
+
deferKeys.map(key => t.stringLiteral(key))
|
|
327
|
+
);
|
|
328
|
+
parentObject.node.properties.push(
|
|
329
|
+
t.objectProperty(
|
|
330
|
+
t.identifier('loaderDeferKeys'),
|
|
331
|
+
deferKeysArrayExpression,
|
|
332
|
+
),
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
modified = true; // Mark as modified
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
} else if (
|
|
340
|
+
astroPath.node.key &&
|
|
341
|
+
astroPath.node.key.name === 'wrappers' &&
|
|
342
|
+
astroPath.node.value.type === 'ArrayExpression'
|
|
343
|
+
) {
|
|
344
|
+
const parentObjectExpression = astroPath.findParent((p) => p.isObjectExpression());
|
|
345
|
+
const wrapperPaths = [];
|
|
346
|
+
astroPath.node.value.elements.forEach((element, index) => {
|
|
347
|
+
if (element.type === 'CallExpression' && element.callee.type === 'Import') {
|
|
348
|
+
const importArg = element.arguments[0];
|
|
349
|
+
if (importArg && importArg.type === 'StringLiteral') {
|
|
350
|
+
const importPath = importArg.value;
|
|
351
|
+
const fullPath = path.resolve(path.dirname(filePath), importPath);
|
|
352
|
+
const packageJsonPath = findPackageJson(
|
|
353
|
+
path.dirname(path.resolve(process.cwd(), dist)),
|
|
354
|
+
);
|
|
355
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
356
|
+
const relativePath = path.relative(path.dirname(packageJsonPath), fullPath);
|
|
357
|
+
const normalizedImportPath = `${packageJson.name}/${relativePath.replace(
|
|
358
|
+
/\\/g,
|
|
359
|
+
'/',
|
|
360
|
+
)}`;
|
|
361
|
+
// Modify the import path directly
|
|
362
|
+
element.arguments[0] = t.stringLiteral(normalizedImportPath);
|
|
363
|
+
|
|
364
|
+
wrapperPaths.push(normalizedImportPath);
|
|
365
|
+
|
|
366
|
+
if (wrapperPaths.length > 0) {
|
|
367
|
+
// Construct an array expression for the wrapper paths
|
|
368
|
+
const wrapperPathsArrayExpression = t.arrayExpression(
|
|
369
|
+
wrapperPaths.map((path) => t.stringLiteral(path)),
|
|
370
|
+
);
|
|
371
|
+
// Create an object property AST node for `wrapperPaths`
|
|
372
|
+
const wrapperPathsProperty = t.objectProperty(
|
|
373
|
+
t.identifier('wrapperPaths'), // Property key
|
|
374
|
+
wrapperPathsArrayExpression, // Property value
|
|
375
|
+
);
|
|
376
|
+
astroPath.remove();
|
|
377
|
+
// Ensure the parent object expression exists and has properties
|
|
378
|
+
if (
|
|
379
|
+
parentObjectExpression &&
|
|
380
|
+
parentObjectExpression.node &&
|
|
381
|
+
parentObjectExpression.node.properties
|
|
382
|
+
) {
|
|
383
|
+
// Push the new property into the parent object's properties array
|
|
384
|
+
parentObjectExpression.node.properties.push(wrapperPathsProperty);
|
|
385
|
+
modified = true; // Mark as modified
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
// If AST was modified, regenerate code
|
|
395
|
+
if (modified) {
|
|
396
|
+
const output = generate.default(
|
|
397
|
+
ast,
|
|
398
|
+
{
|
|
399
|
+
/* options */
|
|
400
|
+
},
|
|
401
|
+
code,
|
|
402
|
+
);
|
|
403
|
+
fs.writeFileSync(filePath, output.code); // This line actually writes the changes
|
|
404
|
+
}
|
|
405
|
+
// This plugin doesn't modify the code, so return null
|
|
406
|
+
return null;
|
|
407
|
+
});
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { exec } from 'child_process';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
|
|
4
|
+
export const runLintStaged = () => {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
exec('yarn lint-staged', { cwd: resolve(import.meta.url, '../') }, (err, stdout, stderr) => {
|
|
7
|
+
if (err) {
|
|
8
|
+
console.error(`Error running lint-staged: ${stderr}`);
|
|
9
|
+
return reject(err);
|
|
10
|
+
}
|
|
11
|
+
console.log(stdout);
|
|
12
|
+
resolve();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -12,7 +12,6 @@ const sortPackageJson = await import('sort-package-json').then(module => module.
|
|
|
12
12
|
// Directories to process
|
|
13
13
|
const directories = [
|
|
14
14
|
path.join(__dirname, '../packages'),
|
|
15
|
-
path.join(__dirname, '../packages-modules'),
|
|
16
15
|
path.join(__dirname, '../servers'),
|
|
17
16
|
path.join(__dirname, '../portable-devices')
|
|
18
17
|
];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { exec } from 'child_process';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { runLintStaged } from './runLint.mjs'; // Assuming updateLint.mjs exports this function
|
|
6
|
+
|
|
7
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
8
|
+
|
|
9
|
+
// Constants for JSON formatting
|
|
10
|
+
const JSON_SPACING = 4;
|
|
11
|
+
const ADD_END_NEWLINE = true; // Set to true to add a newline at the end of the file
|
|
12
|
+
|
|
13
|
+
// Paths to package.json files
|
|
14
|
+
const backendPackagePath = resolve(__dirname, '../servers/backend-server/package.json');
|
|
15
|
+
const frontendPackagePath = resolve(__dirname, '../servers/frontend-server/package.json');
|
|
16
|
+
|
|
17
|
+
// Packages to check
|
|
18
|
+
const packagesToCheck = [
|
|
19
|
+
'@common-stack/server-stack',
|
|
20
|
+
'@common-stack/frontend-stack-react'
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
// Function to update dependencies
|
|
24
|
+
const updateDependencies = async (targetPackagePath, sourcePackagePath) => {
|
|
25
|
+
const targetPackageJson = JSON.parse(await readFile(targetPackagePath, 'utf-8'));
|
|
26
|
+
const sourcePackageJson = JSON.parse(await readFile(sourcePackagePath, 'utf-8'));
|
|
27
|
+
|
|
28
|
+
const mergeDependencies = (targetDeps = {}, sourceDeps = {}) => ({
|
|
29
|
+
...targetDeps,
|
|
30
|
+
...sourceDeps
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Merge dependencies only
|
|
34
|
+
targetPackageJson.dependencies = mergeDependencies(
|
|
35
|
+
targetPackageJson.dependencies,
|
|
36
|
+
sourcePackageJson.dependencies
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Format the JSON string with the specified spacing
|
|
40
|
+
let jsonString = JSON.stringify(targetPackageJson, null, JSON_SPACING);
|
|
41
|
+
|
|
42
|
+
// Optionally add a newline at the end
|
|
43
|
+
if (ADD_END_NEWLINE) {
|
|
44
|
+
jsonString += '\n';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Write the formatted JSON back to disk
|
|
48
|
+
await writeFile(targetPackagePath, jsonString, 'utf-8');
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Function to run `ncu`, update dependencies, and then run linting
|
|
52
|
+
export const runUpdateDependencies = async () => {
|
|
53
|
+
// Run `ncu` command to update the dependencies from the root level
|
|
54
|
+
await new Promise((resolve, reject) => {
|
|
55
|
+
exec('ncu -u -t minor "@common-stack*" && lerna exec "ncu -u -t minor /@common-stack*/"', { cwd: resolve(__dirname, '..') }, (err, stdout, stderr) => {
|
|
56
|
+
if (err) {
|
|
57
|
+
console.error(`Error running ncu and lerna: ${stderr}`);
|
|
58
|
+
return reject(err);
|
|
59
|
+
}
|
|
60
|
+
console.log(stdout);
|
|
61
|
+
resolve();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Check for changes in the specified packages
|
|
66
|
+
for (const packageName of packagesToCheck) {
|
|
67
|
+
const packagePath = resolve(__dirname, `../node_modules/${packageName}/package.json`);
|
|
68
|
+
try {
|
|
69
|
+
await updateDependencies(
|
|
70
|
+
packageName.includes('server-stack') ? backendPackagePath : frontendPackagePath,
|
|
71
|
+
packagePath
|
|
72
|
+
);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.warn(`Package ${packageName} not found or failed to update:`, error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log('Dependencies from @common-stack packages have been updated.');
|
|
79
|
+
|
|
80
|
+
// Run linting to apply Prettier
|
|
81
|
+
try {
|
|
82
|
+
await runLintStaged();
|
|
83
|
+
console.log('Prettier formatting applied.');
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error('Failed to run Prettier:', err);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Execute the function if this file is run directly
|
|
90
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
91
|
+
runUpdateDependencies().catch(err => {
|
|
92
|
+
console.error('Failed to update dependencies:', err);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import glob from 'glob';
|
|
2
|
+
import { resolve, dirname, relative } from 'path';
|
|
3
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
4
|
+
import simpleGit from 'simple-git';
|
|
5
|
+
import { runLintStaged } from './runLint.mjs';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
|
|
11
|
+
// matching prettier format
|
|
12
|
+
const JSON_SPACING = 4;
|
|
13
|
+
const ADD_END_NEWLINE = true; // Set to true to add a newline at the end of the file
|
|
14
|
+
|
|
15
|
+
const git = simpleGit();
|
|
16
|
+
|
|
17
|
+
const monorepoRoot = resolve(__dirname, '..');
|
|
18
|
+
|
|
19
|
+
const findPackageJsonFiles = () => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
glob(
|
|
22
|
+
`${monorepoRoot}/+(servers|portable-devices|packages|packages-modules)/**/package.json`,
|
|
23
|
+
{ onlyFiles: true, ignore: '**/node_modules/**' },
|
|
24
|
+
(err, files) => {
|
|
25
|
+
if (err) reject(`Unable to scan directory: ${err}`);
|
|
26
|
+
resolve(files);
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const buildPackageMap = async () => {
|
|
33
|
+
const packageJsonFiles = await findPackageJsonFiles();
|
|
34
|
+
const packageMap = new Map();
|
|
35
|
+
|
|
36
|
+
packageJsonFiles.forEach((file) => {
|
|
37
|
+
const packageJson = JSON.parse(readFileSync(file, 'utf8'));
|
|
38
|
+
if (packageJson.name) {
|
|
39
|
+
packageMap.set(packageJson.name, {
|
|
40
|
+
path: dirname(file),
|
|
41
|
+
version: packageJson.version,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return packageMap;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const searchAndUpdate = (dependencies, filePath, obj, packageMap) => {
|
|
50
|
+
let modified = false;
|
|
51
|
+
|
|
52
|
+
for (const key in dependencies) {
|
|
53
|
+
if (packageMap.has(key)) {
|
|
54
|
+
const targetDir = packageMap.get(key).path;
|
|
55
|
+
const relativePath = `link:${relative(dirname(filePath), targetDir)}`;
|
|
56
|
+
|
|
57
|
+
if (dependencies[key] !== relativePath) {
|
|
58
|
+
dependencies[key] = relativePath;
|
|
59
|
+
modified = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (modified) {
|
|
65
|
+
// Write the updated package.json back to disk with or without a newline at the end
|
|
66
|
+
let formattedJson = JSON.stringify(obj, null, JSON_SPACING);
|
|
67
|
+
if (ADD_END_NEWLINE) {
|
|
68
|
+
formattedJson += '\n';
|
|
69
|
+
}
|
|
70
|
+
writeFileSync(filePath, formattedJson, 'utf8');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return modified;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const updateDependencies = async () => {
|
|
77
|
+
const packageMap = await buildPackageMap();
|
|
78
|
+
const packageJsonFiles = await findPackageJsonFiles();
|
|
79
|
+
const modifiedFiles = [];
|
|
80
|
+
|
|
81
|
+
packageJsonFiles.forEach((file) => {
|
|
82
|
+
if (!file.includes('node_modules')) {
|
|
83
|
+
try {
|
|
84
|
+
const data = readFileSync(file, 'utf8');
|
|
85
|
+
const obj = JSON.parse(data);
|
|
86
|
+
const { dependencies, peerDependencies, devDependencies } = obj;
|
|
87
|
+
|
|
88
|
+
let modified = false;
|
|
89
|
+
modified = searchAndUpdate(dependencies, file, obj, packageMap) || modified;
|
|
90
|
+
modified = searchAndUpdate(peerDependencies, file, obj, packageMap) || modified;
|
|
91
|
+
modified = searchAndUpdate(devDependencies, file, obj, packageMap) || modified;
|
|
92
|
+
|
|
93
|
+
if (modified) {
|
|
94
|
+
console.log('--PUSHING FILE=---', file);
|
|
95
|
+
modifiedFiles.push(file);
|
|
96
|
+
}
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.error(`Unable to read file ${file}: ${err.message}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return modifiedFiles;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
updateDependencies()
|
|
107
|
+
.then((modifiedFiles) => {
|
|
108
|
+
const addArray = modifiedFiles.map((file) => `./${relative(monorepoRoot, file)}`);
|
|
109
|
+
console.log('-- Modified Files --', modifiedFiles, addArray);
|
|
110
|
+
if (addArray.length === 0) {
|
|
111
|
+
console.log('No files to stage.');
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return git.add(addArray).then(() => git.status()); // Stage files and then check status
|
|
115
|
+
})
|
|
116
|
+
.then((status) => {
|
|
117
|
+
if (status && status.modified.length) {
|
|
118
|
+
const fileArray = status.modified.filter((element) => element.includes('package.json'));
|
|
119
|
+
const addArray = fileArray.map((element) => `./${element}`);
|
|
120
|
+
return git
|
|
121
|
+
.add(addArray)
|
|
122
|
+
.then(runLintStaged)
|
|
123
|
+
.then(() => git.status()); // Run lint-staged after adding
|
|
124
|
+
} else {
|
|
125
|
+
console.log('No changes to lint or commit.');
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
.then((status) => {
|
|
130
|
+
if (status && status.modified.length > 0) {
|
|
131
|
+
return git.commit('Updated packages to use correct versions and linked dependencies');
|
|
132
|
+
} else {
|
|
133
|
+
console.log('No changes after linting. Nothing to commit.');
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
.catch((err) => {
|
|
137
|
+
console.error(err);
|
|
138
|
+
});
|