@common-stack/generate-plugin 6.0.6-alpha.21 → 6.0.6-alpha.22

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/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [6.0.6-alpha.22](https://github.com/cdmbase/common-stack/compare/v6.0.6-alpha.21...v6.0.6-alpha.22) (2024-09-14)
7
+
8
+ **Note:** Version bump only for package @common-stack/generate-plugin
9
+
6
10
  ## [6.0.6-alpha.21](https://github.com/cdmbase/common-stack/compare/v6.0.6-alpha.20...v6.0.6-alpha.21) (2024-09-12)
7
11
 
8
12
  **Note:** Version bump only for package @common-stack/generate-plugin
@@ -81,7 +81,7 @@
81
81
  "devDependencies": {
82
82
  "@cdmbase/vite-plugin-i18next-loader": "^2.0.12",
83
83
  "@common-stack/frontend-stack-react": "6.0.6-alpha.20",
84
- "@common-stack/rollup-vite-utils": "6.0.6-alpha.20",
84
+ "@common-stack/rollup-vite-utils": "6.0.6-alpha.21",
85
85
  "@remix-run/dev": "^2.8.1",
86
86
  "@remix-run/serve": "^2.8.1",
87
87
  "cross-env": "^7.0.3",
@@ -147,7 +147,7 @@
147
147
  "@babel/register": "^7.18.9",
148
148
  "@babel/runtime": "^7.20.1",
149
149
  "@common-stack/env-list-loader": "6.0.6-alpha.5",
150
- "@common-stack/generate-plugin": "6.0.6-alpha.20",
150
+ "@common-stack/generate-plugin": "6.0.6-alpha.21",
151
151
  "@emotion/babel-plugin": "^11.11.0",
152
152
  "@graphql-codegen/add": "^5.0.2",
153
153
  "@graphql-codegen/cli": "^5.0.2",
@@ -10,86 +10,118 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
10
10
  const JSON_SPACING = 4;
11
11
  const ADD_END_NEWLINE = true; // Set to true to add a newline at the end of the file
12
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');
13
+ // Paths to package.json files (now using arrays to handle multiple paths for backend, frontend, and mobile)
14
+ const packagePaths = {
15
+ backend: [
16
+ resolve(__dirname, '../servers/backend-server/package.json'),
17
+ ],
18
+ frontend: [
19
+ resolve(__dirname, '../servers/frontend-server/package.json'),
20
+ ],
21
+ mobile: [
22
+ resolve(__dirname, '../portable-devices/mobile/package.json'),
23
+ ]
24
+ };
16
25
 
17
26
  // Packages to check
18
27
  const packagesToCheck = [
19
28
  '@common-stack/server-stack',
20
- '@common-stack/frontend-stack-react'
29
+ '@common-stack/frontend-stack-react',
30
+ '@common-stack/mobile-stack-react'
21
31
  ];
22
32
 
33
+ // Utility function to wrap `exec` in a promise for sequential execution
34
+ const execCommand = (command, cwd) => {
35
+ return new Promise((resolve, reject) => {
36
+ exec(command, { cwd }, (err, stdout, stderr) => {
37
+ if (err) {
38
+ console.error(`Error executing command: ${command}\n${stderr}`);
39
+ return reject(err);
40
+ }
41
+ console.log(stdout);
42
+ resolve();
43
+ });
44
+ });
45
+ };
46
+
23
47
  // Function to update dependencies
24
48
  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
+ const targetPackageJson = JSON.parse(await readFile(targetPackagePath, 'utf-8'));
50
+ const sourcePackageJson = JSON.parse(await readFile(sourcePackagePath, 'utf-8'));
51
+
52
+ const mergeDependencies = (targetDeps = {}, sourceDeps = {}) => ({
53
+ ...targetDeps,
54
+ ...sourceDeps
55
+ });
56
+
57
+ // Merge dependencies only
58
+ targetPackageJson.dependencies = mergeDependencies(targetPackageJson.dependencies, sourcePackageJson.dependencies);
59
+
60
+ // Format the JSON string with the specified spacing
61
+ let jsonString = JSON.stringify(targetPackageJson, null, JSON_SPACING);
62
+
63
+ // Optionally add a newline at the end
64
+ if (ADD_END_NEWLINE) {
65
+ jsonString += '\n';
66
+ }
67
+
68
+ // Write the formatted JSON back to disk
69
+ await writeFile(targetPackagePath, jsonString, 'utf-8');
49
70
  };
50
71
 
51
- // Function to run `ncu`, update dependencies, and then run linting
72
+ // Function to run `ncu`, `yarn` from the root, update dependencies, and then run linting
52
73
  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
- });
74
+ // Step 1: Run `ncu` to update the dependencies from the root level
75
+ console.log('Updating dependencies using `ncu`...');
76
+ await execCommand(
77
+ 'ncu -u -t minor "@common-stack*" && lerna exec "ncu -u -t minor /@common-stack*/"',
78
+ resolve(__dirname, '..')
79
+ );
64
80
 
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);
81
+ // Step 2: Run `yarn` to install updated packages from the root
82
+ console.log('Running yarn install...');
83
+ await execCommand('yarn', resolve(__dirname, '..'));
84
+
85
+ // Step 3: Update dependencies for each package
86
+ for (const packageName of packagesToCheck) {
87
+ const packagePath = resolve(__dirname, `../node_modules/${packageName}/package.json`);
88
+ let targetPaths;
89
+
90
+ // Determine the target package.json paths (array of paths)
91
+ if (packageName.includes('server-stack')) {
92
+ targetPaths = packagePaths.backend;
93
+ } else if (packageName.includes('mobile-stack-react')) {
94
+ targetPaths = packagePaths.mobile;
95
+ } else {
96
+ targetPaths = packagePaths.frontend;
97
+ }
98
+
99
+ // Iterate over all target paths in the corresponding array
100
+ for (const targetPackagePath of targetPaths) {
101
+ try {
102
+ await updateDependencies(targetPackagePath, packagePath);
103
+ console.log(`Updated dependencies for ${packageName} in ${targetPackagePath}`);
104
+ } catch (error) {
105
+ console.warn(`Package ${packageName} not found or failed to update in ${targetPackagePath}:`, error);
106
+ }
107
+ }
75
108
  }
76
- }
77
109
 
78
- console.log('Dependencies from @common-stack packages have been updated.');
110
+ console.log('Dependencies from @common-stack packages have been updated.');
79
111
 
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
- }
112
+ // Step 4: Run linting to apply Prettier
113
+ try {
114
+ await runLintStaged();
115
+ console.log('Prettier formatting applied.');
116
+ } catch (err) {
117
+ console.error('Failed to run Prettier:', err);
118
+ }
87
119
  };
88
120
 
89
121
  // Execute the function if this file is run directly
90
122
  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
- });
123
+ runUpdateDependencies().catch((err) => {
124
+ console.error('Failed to update dependencies:', err);
125
+ process.exit(1);
126
+ });
95
127
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@common-stack/generate-plugin",
3
- "version": "6.0.6-alpha.21",
3
+ "version": "6.0.6-alpha.22",
4
4
  "type": "module",
5
5
  "main": "./lib/index.mjs",
6
6
  "typings": "./lib/index.d.ts",
@@ -25,5 +25,5 @@
25
25
  },
26
26
  "executors": "./executors.json",
27
27
  "generators": "./generators.json",
28
- "gitHead": "acdc3adbed61f83a2adb52ce0ccafea92ea3b0b8"
28
+ "gitHead": "f30c1a84478e52e724554437b85db2dd8bb15dfd"
29
29
  }
@@ -147,7 +147,7 @@
147
147
  "@babel/register": "^7.18.9",
148
148
  "@babel/runtime": "^7.20.1",
149
149
  "@common-stack/env-list-loader": "6.0.6-alpha.5",
150
- "@common-stack/generate-plugin": "6.0.6-alpha.20",
150
+ "@common-stack/generate-plugin": "6.0.6-alpha.21",
151
151
  "@emotion/babel-plugin": "^11.11.0",
152
152
  "@graphql-codegen/add": "^5.0.2",
153
153
  "@graphql-codegen/cli": "^5.0.2",
@@ -10,86 +10,118 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
10
10
  const JSON_SPACING = 4;
11
11
  const ADD_END_NEWLINE = true; // Set to true to add a newline at the end of the file
12
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');
13
+ // Paths to package.json files (now using arrays to handle multiple paths for backend, frontend, and mobile)
14
+ const packagePaths = {
15
+ backend: [
16
+ resolve(__dirname, '../servers/backend-server/package.json'),
17
+ ],
18
+ frontend: [
19
+ resolve(__dirname, '../servers/frontend-server/package.json'),
20
+ ],
21
+ mobile: [
22
+ resolve(__dirname, '../portable-devices/mobile/package.json'),
23
+ ]
24
+ };
16
25
 
17
26
  // Packages to check
18
27
  const packagesToCheck = [
19
28
  '@common-stack/server-stack',
20
- '@common-stack/frontend-stack-react'
29
+ '@common-stack/frontend-stack-react',
30
+ '@common-stack/mobile-stack-react'
21
31
  ];
22
32
 
33
+ // Utility function to wrap `exec` in a promise for sequential execution
34
+ const execCommand = (command, cwd) => {
35
+ return new Promise((resolve, reject) => {
36
+ exec(command, { cwd }, (err, stdout, stderr) => {
37
+ if (err) {
38
+ console.error(`Error executing command: ${command}\n${stderr}`);
39
+ return reject(err);
40
+ }
41
+ console.log(stdout);
42
+ resolve();
43
+ });
44
+ });
45
+ };
46
+
23
47
  // Function to update dependencies
24
48
  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
+ const targetPackageJson = JSON.parse(await readFile(targetPackagePath, 'utf-8'));
50
+ const sourcePackageJson = JSON.parse(await readFile(sourcePackagePath, 'utf-8'));
51
+
52
+ const mergeDependencies = (targetDeps = {}, sourceDeps = {}) => ({
53
+ ...targetDeps,
54
+ ...sourceDeps
55
+ });
56
+
57
+ // Merge dependencies only
58
+ targetPackageJson.dependencies = mergeDependencies(targetPackageJson.dependencies, sourcePackageJson.dependencies);
59
+
60
+ // Format the JSON string with the specified spacing
61
+ let jsonString = JSON.stringify(targetPackageJson, null, JSON_SPACING);
62
+
63
+ // Optionally add a newline at the end
64
+ if (ADD_END_NEWLINE) {
65
+ jsonString += '\n';
66
+ }
67
+
68
+ // Write the formatted JSON back to disk
69
+ await writeFile(targetPackagePath, jsonString, 'utf-8');
49
70
  };
50
71
 
51
- // Function to run `ncu`, update dependencies, and then run linting
72
+ // Function to run `ncu`, `yarn` from the root, update dependencies, and then run linting
52
73
  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
- });
74
+ // Step 1: Run `ncu` to update the dependencies from the root level
75
+ console.log('Updating dependencies using `ncu`...');
76
+ await execCommand(
77
+ 'ncu -u -t minor "@common-stack*" && lerna exec "ncu -u -t minor /@common-stack*/"',
78
+ resolve(__dirname, '..')
79
+ );
64
80
 
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);
81
+ // Step 2: Run `yarn` to install updated packages from the root
82
+ console.log('Running yarn install...');
83
+ await execCommand('yarn', resolve(__dirname, '..'));
84
+
85
+ // Step 3: Update dependencies for each package
86
+ for (const packageName of packagesToCheck) {
87
+ const packagePath = resolve(__dirname, `../node_modules/${packageName}/package.json`);
88
+ let targetPaths;
89
+
90
+ // Determine the target package.json paths (array of paths)
91
+ if (packageName.includes('server-stack')) {
92
+ targetPaths = packagePaths.backend;
93
+ } else if (packageName.includes('mobile-stack-react')) {
94
+ targetPaths = packagePaths.mobile;
95
+ } else {
96
+ targetPaths = packagePaths.frontend;
97
+ }
98
+
99
+ // Iterate over all target paths in the corresponding array
100
+ for (const targetPackagePath of targetPaths) {
101
+ try {
102
+ await updateDependencies(targetPackagePath, packagePath);
103
+ console.log(`Updated dependencies for ${packageName} in ${targetPackagePath}`);
104
+ } catch (error) {
105
+ console.warn(`Package ${packageName} not found or failed to update in ${targetPackagePath}:`, error);
106
+ }
107
+ }
75
108
  }
76
- }
77
109
 
78
- console.log('Dependencies from @common-stack packages have been updated.');
110
+ console.log('Dependencies from @common-stack packages have been updated.');
79
111
 
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
- }
112
+ // Step 4: Run linting to apply Prettier
113
+ try {
114
+ await runLintStaged();
115
+ console.log('Prettier formatting applied.');
116
+ } catch (err) {
117
+ console.error('Failed to run Prettier:', err);
118
+ }
87
119
  };
88
120
 
89
121
  // Execute the function if this file is run directly
90
122
  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
- });
123
+ runUpdateDependencies().catch((err) => {
124
+ console.error('Failed to update dependencies:', err);
125
+ process.exit(1);
126
+ });
95
127
  }