@common-stack/generate-plugin 5.0.6-alpha.5 → 5.0.6-alpha.8

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.
Files changed (140) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +280 -10
  3. package/cde-config.json +86 -0
  4. package/lib/constants/index.cjs +2 -1
  5. package/lib/constants/index.cjs.map +1 -1
  6. package/lib/constants/index.d.ts +1 -0
  7. package/lib/constants/index.mjs +2 -1
  8. package/lib/constants/index.mjs.map +1 -1
  9. package/lib/generators/add-backend/files/CHANGELOG.md +0 -0
  10. package/lib/generators/add-backend/files/Dockerfile +1 -1
  11. package/lib/generators/add-backend/files/__tests__/test.ts.template +3 -2
  12. package/lib/generators/add-backend/files/package.json +2 -48
  13. package/lib/generators/add-backend/generator.cjs +21 -17
  14. package/lib/generators/add-backend/generator.cjs.map +1 -1
  15. package/lib/generators/add-backend/generator.d.ts +1 -0
  16. package/lib/generators/add-backend/generator.mjs +21 -17
  17. package/lib/generators/add-backend/generator.mjs.map +1 -1
  18. package/lib/generators/add-browser-package/files/package.json +1 -1
  19. package/lib/generators/add-browser-package/generator.cjs +14 -16
  20. package/lib/generators/add-browser-package/generator.cjs.map +1 -1
  21. package/lib/generators/add-browser-package/generator.d.ts +1 -0
  22. package/lib/generators/add-browser-package/generator.mjs +14 -16
  23. package/lib/generators/add-browser-package/generator.mjs.map +1 -1
  24. package/lib/generators/add-client-package/files/package.json +2 -3
  25. package/lib/generators/add-client-package/generator.cjs +14 -16
  26. package/lib/generators/add-client-package/generator.cjs.map +1 -1
  27. package/lib/generators/add-client-package/generator.d.ts +1 -0
  28. package/lib/generators/add-client-package/generator.mjs +14 -16
  29. package/lib/generators/add-client-package/generator.mjs.map +1 -1
  30. package/lib/generators/add-core-package/files/package.json +2 -3
  31. package/lib/generators/add-core-package/generator.cjs +14 -16
  32. package/lib/generators/add-core-package/generator.cjs.map +1 -1
  33. package/lib/generators/add-core-package/generator.d.ts +1 -0
  34. package/lib/generators/add-core-package/generator.mjs +14 -16
  35. package/lib/generators/add-core-package/generator.mjs.map +1 -1
  36. package/lib/generators/add-frontend/frameworks/chakraui/entry.client.tsx.template +30 -24
  37. package/lib/generators/add-frontend/frameworks/chakraui/entry.server.tsx.template +5 -8
  38. package/lib/generators/add-frontend/frameworks/chakraui/root.tsx.template +3 -3
  39. package/lib/generators/add-frontend/frameworks/tailwindui/entry.client.tsx.template +90 -0
  40. package/lib/generators/add-frontend/frameworks/tailwindui/entry.server.tsx.template +238 -0
  41. package/lib/generators/add-frontend/frameworks/tailwindui/root.tsx.template +117 -0
  42. package/lib/generators/add-frontend/frameworks/tailwindui/tailwind.css +3 -0
  43. package/lib/generators/add-frontend/generator.cjs +60 -42
  44. package/lib/generators/add-frontend/generator.cjs.map +1 -1
  45. package/lib/generators/add-frontend/generator.d.ts +1 -0
  46. package/lib/generators/add-frontend/generator.mjs +60 -42
  47. package/lib/generators/add-frontend/generator.mjs.map +1 -1
  48. package/lib/generators/add-frontend/schema.json +1 -1
  49. package/lib/generators/add-frontend/templates/package.json +18 -77
  50. package/lib/generators/add-frontend/templates/postcss.config.js +6 -0
  51. package/lib/generators/add-frontend/templates/tailwind.config.ts.template +12 -0
  52. package/lib/generators/add-fullstack/files/Jenkinsfile +3 -6
  53. package/lib/generators/add-fullstack/files/jest-mongodb-config.js +3 -2
  54. package/lib/generators/add-fullstack/files/jest.config.base.js +43 -4
  55. package/lib/generators/add-fullstack/files/jest.config.base.mjs +99 -0
  56. package/lib/generators/add-fullstack/files/jest.config.mongodb.mjs +3 -0
  57. package/lib/generators/add-fullstack/files/lint-staged.config.js +4 -1
  58. package/lib/generators/add-fullstack/files/nx.json +18 -13
  59. package/lib/generators/add-fullstack/files/package.json +12 -24
  60. package/lib/generators/add-fullstack/files/tools/cli/helpers/util.js +1 -1
  61. package/lib/generators/add-fullstack/files/tools/deploy-cli/updateLernaVersion.js +1 -1
  62. package/lib/generators/add-fullstack/files/tools/deploy-cli/updateYamlSettings.js +14 -15
  63. package/lib/generators/add-fullstack/files/tools/prettier.config.js +8 -0
  64. package/lib/generators/add-fullstack/files/tools/rollup/rollupPluginGenerateJson.mjs +48 -0
  65. package/lib/generators/add-fullstack/files/tools/rollup/rollupPluginModifyLibFiles.mjs +410 -0
  66. package/lib/generators/add-fullstack/files/tools/runLint.mjs +15 -0
  67. package/lib/generators/add-fullstack/files/tools/sortPackageJson.mjs +8 -2
  68. package/lib/generators/add-fullstack/files/tools/update-dependencies.mjs +95 -0
  69. package/lib/generators/add-fullstack/files/tools/update-dependency-link.mjs +138 -0
  70. package/lib/generators/add-fullstack/files/tools/update-dependency-version.js +104 -89
  71. package/lib/generators/add-fullstack/files/tools/updateUtils.mjs +77 -0
  72. package/lib/generators/add-fullstack/generator.cjs +71 -13
  73. package/lib/generators/add-fullstack/generator.cjs.map +1 -1
  74. package/lib/generators/add-fullstack/generator.mjs +71 -13
  75. package/lib/generators/add-fullstack/generator.mjs.map +1 -1
  76. package/lib/generators/add-fullstack/schema.json +9 -0
  77. package/lib/generators/add-fullstack/updates/index.d.ts +2 -0
  78. package/lib/generators/add-fullstack/updates/jenkinsfileUpdate.cjs +36 -0
  79. package/lib/generators/add-fullstack/updates/jenkinsfileUpdate.cjs.map +1 -0
  80. package/lib/generators/add-fullstack/updates/jenkinsfileUpdate.d.ts +1 -0
  81. package/lib/generators/add-fullstack/updates/jenkinsfileUpdate.mjs +36 -0
  82. package/lib/generators/add-fullstack/updates/jenkinsfileUpdate.mjs.map +1 -0
  83. package/lib/generators/add-fullstack/updates/packageJsonUpdate.cjs +8 -0
  84. package/lib/generators/add-fullstack/updates/packageJsonUpdate.cjs.map +1 -0
  85. package/lib/generators/add-fullstack/updates/packageJsonUpdate.d.ts +2 -0
  86. package/lib/generators/add-fullstack/updates/packageJsonUpdate.mjs +8 -0
  87. package/lib/generators/add-fullstack/updates/packageJsonUpdate.mjs.map +1 -0
  88. package/lib/generators/add-moleculer/files/package.json +3 -3
  89. package/lib/generators/add-moleculer/generator.cjs +14 -16
  90. package/lib/generators/add-moleculer/generator.cjs.map +1 -1
  91. package/lib/generators/add-moleculer/generator.d.ts +1 -0
  92. package/lib/generators/add-moleculer/generator.mjs +14 -16
  93. package/lib/generators/add-moleculer/generator.mjs.map +1 -1
  94. package/lib/generators/add-server-package/files/package.json +2 -2
  95. package/lib/generators/add-server-package/generator.cjs +14 -16
  96. package/lib/generators/add-server-package/generator.cjs.map +1 -1
  97. package/lib/generators/add-server-package/generator.d.ts +1 -0
  98. package/lib/generators/add-server-package/generator.mjs +14 -16
  99. package/lib/generators/add-server-package/generator.mjs.map +1 -1
  100. package/lib/index.cjs +1 -1
  101. package/lib/index.mjs +1 -1
  102. package/package.json +3 -2
  103. package/src/constants/index.ts +2 -1
  104. package/src/generators/add-backend/generator.ts +8 -4
  105. package/src/generators/add-browser-package/generator.ts +7 -6
  106. package/src/generators/add-client-package/generator.ts +7 -6
  107. package/src/generators/add-core-package/generator.ts +7 -6
  108. package/src/generators/add-frontend/frameworks/tailwindui/entry.client.tsx.template +90 -0
  109. package/src/generators/add-frontend/frameworks/tailwindui/entry.server.tsx.template +238 -0
  110. package/src/generators/add-frontend/frameworks/tailwindui/root.tsx.template +117 -0
  111. package/src/generators/add-frontend/frameworks/tailwindui/tailwind.css +3 -0
  112. package/src/generators/add-frontend/generator.ts +24 -2
  113. package/src/generators/add-frontend/schema.json +1 -1
  114. package/src/generators/add-fullstack/files/jest-mongodb-config.js +3 -2
  115. package/src/generators/add-fullstack/files/jest.config copy.js +27 -0
  116. package/src/generators/add-fullstack/files/jest.config.base.js +43 -4
  117. package/src/generators/add-fullstack/files/jest.config.base.mjs +99 -0
  118. package/src/generators/add-fullstack/files/jest.config.mongodb.mjs +3 -0
  119. package/src/generators/add-fullstack/files/lint-staged.config.js +4 -1
  120. package/src/generators/add-fullstack/files/nx.json +18 -13
  121. package/src/generators/add-fullstack/files/tools/cli/helpers/util.js +1 -1
  122. package/src/generators/add-fullstack/files/tools/deploy-cli/updateLernaVersion.js +1 -1
  123. package/src/generators/add-fullstack/files/tools/html-plugin-template.ejs +28 -0
  124. package/src/generators/add-fullstack/files/tools/prettier.config.js +8 -0
  125. package/src/generators/add-fullstack/files/tools/rollup/rollupPluginGenerateJson.mjs +48 -0
  126. package/src/generators/add-fullstack/files/tools/rollup/rollupPluginModifyLibFiles.mjs +410 -0
  127. package/src/generators/add-fullstack/files/tools/runLint.mjs +15 -0
  128. package/src/generators/add-fullstack/files/tools/sortPackageJson.mjs +0 -1
  129. package/src/generators/add-fullstack/files/tools/update-dependencies.mjs +95 -0
  130. package/src/generators/add-fullstack/files/tools/update-dependency-link.mjs +138 -0
  131. package/src/generators/add-fullstack/files/tools/update-dependency-version.js +104 -89
  132. package/src/generators/add-fullstack/files/tools/updateUtils.mjs +77 -0
  133. package/src/generators/add-fullstack/generator.ts +83 -1
  134. package/src/generators/add-fullstack/schema.d.ts +1 -0
  135. package/src/generators/add-fullstack/schema.json +4 -0
  136. package/src/generators/add-moleculer/files/package.json +1 -1
  137. package/src/generators/add-moleculer/generator.ts +7 -6
  138. package/src/generators/add-server-package/generator.ts +7 -6
  139. package/lib/generators/add-fullstack/files/tools/update-dependency-link.js +0 -107
  140. package/src/generators/add-fullstack/files/tools/update-dependency-link.js +0 -107
@@ -0,0 +1,48 @@
1
+ import { promisify } from 'util';
2
+ import glob from 'glob';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+
6
+ const globPromise = promisify(glob.glob); // Make sure to call .glob here
7
+
8
+ export default function generateJsonFromSpecificFiles(options = {}) {
9
+ const {
10
+ pattern = '**/**/compute.js', // Pattern to match files
11
+ dist = 'lib', // Default output directory
12
+ outputFile = 'routes.json', // Output filename
13
+ } = options;
14
+
15
+ return {
16
+ name: 'aggregate-compute-routes',
17
+ async writeBundle() { // Changed from generateBundle to writeBundle
18
+ const files = await globPromise(path.join(dist, pattern), { absolute: true }); // Ensure paths are absolute
19
+ let allFilteredRoutes = [];
20
+
21
+ for (const file of files) {
22
+ try {
23
+ // Dynamically import the JS file assuming it exports filteredRoutes
24
+ const module = await import(file); // file is already absolute
25
+ if (module.filteredRoutes) {
26
+ const newRoutes = module.filteredRoutes.map((filteredRoute) => {
27
+ let routConfig = Object.values(filteredRoute)[0];
28
+ return { [routConfig.path]: routConfig };
29
+ });
30
+ allFilteredRoutes.push(...newRoutes);
31
+ }
32
+ } catch (error) {
33
+ this.warn(`Error importing ${file}: ${error}`);
34
+ }
35
+ }
36
+
37
+ // Ensure the dist directory exists
38
+ if (!fs.existsSync(dist)) {
39
+ fs.mkdirSync(dist, { recursive: true });
40
+ }
41
+
42
+ // Specify the output file path and write the aggregated filteredRoutes to a JSON file
43
+ const outputPath = path.join(dist, outputFile);
44
+ fs.writeFileSync(outputPath, JSON.stringify(allFilteredRoutes, null, 2), 'utf8');
45
+ console.log(`Aggregated filtered routes have been written to ${outputPath}`);
46
+ },
47
+ };
48
+ }
@@ -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
+ };
@@ -11,24 +11,28 @@ const sortPackageJson = await import('sort-package-json').then(module => module.
11
11
 
12
12
  // Directories to process
13
13
  const directories = [
14
- path.join(__dirname, '../packages'),
14
+ path.join(__dirname, '../'),
15
15
  path.join(__dirname, '../packages-modules'),
16
+ path.join(__dirname, '../packages'),
16
17
  path.join(__dirname, '../servers'),
17
18
  path.join(__dirname, '../portable-devices')
18
19
  ];
19
20
 
21
+ // Function to sort a single package.json file
20
22
  async function sortPackageJsonFile(filePath) {
21
23
  const packageJson = JSON.parse(await fsPromises.readFile(filePath, 'utf8'));
22
24
  const sortedPackageJson = sortPackageJson(packageJson);
23
25
  await fsPromises.writeFile(filePath, JSON.stringify(sortedPackageJson, null, 2) + '\n');
24
26
  }
25
27
 
28
+ // Recursive function to sort all package.json files in a directory, skipping node_modules
26
29
  async function sortAllPackageJsonFiles(dir) {
27
30
  const files = await fsPromises.readdir(dir);
28
31
  for (const file of files) {
29
32
  const fullPath = path.join(dir, file);
30
33
  const stat = await fsPromises.lstat(fullPath);
31
- if (stat.isDirectory()) {
34
+
35
+ if (stat.isDirectory() && file !== 'node_modules') {
32
36
  await sortAllPackageJsonFiles(fullPath);
33
37
  } else if (file === 'package.json') {
34
38
  await sortPackageJsonFile(fullPath);
@@ -37,10 +41,12 @@ async function sortAllPackageJsonFiles(dir) {
37
41
  }
38
42
  }
39
43
 
44
+ // Function to process all directories
40
45
  async function processDirectories(dirs) {
41
46
  for (const dir of dirs) {
42
47
  await sortAllPackageJsonFiles(dir);
43
48
  }
44
49
  }
45
50
 
51
+ // Execute the sorting process
46
52
  await processDirectories(directories);
@@ -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
+ }