@cocreate/cli 1.49.0 → 1.51.0

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.
@@ -1,92 +1,154 @@
1
- let fs = require('fs');
2
- const path = require("path")
3
- const util = require('node:util');
4
- const exec = util.promisify(require('node:child_process').exec);
5
- const { color } = require('../fonts');
6
-
7
- let pathList, nameList, item = {}, failed = [];
8
-
9
- module.exports = async function bump(repos, args) {
10
- pathList = repos.map(o => o.absolutePath)
11
- if (repos.length <= 1) {
12
- let packageJsonPath = path.resolve(process.cwd(), 'package.json');
13
-
14
- if (fs.existsSync(packageJsonPath)) {
15
- let json = require(packageJsonPath)
16
- if (json) {
17
- let dependencies = json.dependencies || {}
18
- let devDependencies = json.devDependencies || {}
19
- let object = { ...dependencies, ...devDependencies }
20
- for (let key of Object.keys(object)) {
21
- if (key.startsWith("@cocreate/")) {
22
- const version = await exec(`npm view ${key} version`);
23
- item[key] = `^${version.stdout}`.trim()
24
- }
25
- }
26
- console.log('bump versions', item)
27
-
28
- for (let name of Object.keys(item)) {
29
- bumpVersion(packageJsonPath, name)
30
- }
31
- }
32
- }
33
-
34
- } else {
35
- nameList = pathList.map(fn => path.basename(fn).toLowerCase());
36
- for (let [index, name] of nameList.entries()) {
37
- getVersions(path.resolve(pathList[index], 'package.json'), `@${name}`)
38
- }
39
-
40
- console.log('bump versions', item)
41
-
42
- for (let [index, name] of nameList.entries()) {
43
- bumpVersion(path.resolve(pathList[index], 'package.json'), name)
44
- }
45
-
46
- }
47
-
48
- console.log('completed')
49
- return failed;
50
- }
1
+ // Import necessary modules
2
+ let fs = require("fs"); // File system module
3
+ const path = require("path"); // Path module for handling file paths
4
+ const util = require("node:util"); // Utility module for different helper functions
5
+ const exec = util.promisify(require("node:child_process").exec); // Promisified version of exec
6
+ const createSpinner = require("../spinner"); // Import custom spinner module
7
+
8
+ // Initialize variables to use throughout the module update process
9
+ let pathList = [], // Array to store paths to package.json files
10
+ item = {}, // Object to store the latest versions of modules
11
+ failed = []; // Array to track any failures that occur
12
+
13
+ let promiseMap = new Map(); // A map to cache promises for fetching versions
14
+
15
+ /**
16
+ * Updates module versions across multiple repositories.
17
+ * @param {Array} repos - An array of repository objects containing `absolutePath`.
18
+ * @param {Object} args - Additional arguments for the update process (not used here but passed for potential future use).
19
+ * @returns {Promise<Array>} - Resolves with the list of failed update attempts.
20
+ */
21
+ module.exports = async function update(repos, args) {
22
+ pathList = repos.map((o) => path.resolve(o.absolutePath, "package.json"));
23
+
24
+ // Start a spinner to indicate progress
25
+ const spinner = createSpinner({
26
+ prefix: "Waiting for all versions to be fetched"
27
+ });
28
+
29
+ // Trigger version fetching for each package.json path
30
+ for (let filePath of pathList) {
31
+ getVersions(filePath);
32
+ }
33
+
34
+ // Await the resolution of all version fetching promises
35
+ await Promise.all(promiseMap.values());
36
+
37
+ // Populate the 'item' object with fetched versions
38
+ for (let [key, promise] of promiseMap) {
39
+ const version = await promise;
40
+ if (version) {
41
+ item[key] = `^${version}`;
42
+ }
43
+ }
44
+
45
+ // End spinner as fetching process is complete
46
+ spinner.end();
51
47
 
48
+ // Update each package.json with new version data
49
+ for (let filePath of pathList) {
50
+ updateVersion(filePath);
51
+ }
52
+
53
+ console.log("Completed updating modules to their latest versions.");
54
+ return failed;
55
+ };
56
+
57
+ /**
58
+ * Fetches the latest versions of dependencies listed in a package.json file.
59
+ * @param {string} filePath - The path to the package.json file.
60
+ */
52
61
  function getVersions(filePath) {
53
- if (fs.existsSync(filePath)) {
54
- let object = require(filePath)
55
- if (object.name && object.version) {
56
- item[object.name] = `^${object.version}`
57
- }
58
- } else {
59
- failed.push({ name: 'get version', des: 'path doesn\'t exist:' + filePath })
60
- }
62
+ if (fs.existsSync(filePath)) {
63
+ let object = require(filePath); // Load JSON content
64
+ const dependencies = object.dependencies || {}; // Current dependencies
65
+ const devDependencies = object.devDependencies || {}; // Current devDependencies
66
+ const allDependencies = { ...dependencies, ...devDependencies }; // Combine both
67
+
68
+ // Iterate over each dependency
69
+ for (const key of Object.keys(allDependencies)) {
70
+ // Check and process only @cocreate/ prefixed packages
71
+ if (key.startsWith("@cocreate/") && !promiseMap.has(key)) {
72
+ const promise = exec(`npm view ${key} version`)
73
+ .then((versionObj) => versionObj.stdout.trim())
74
+ .catch((error) => {
75
+ failed.push({ name: key, error: error.message });
76
+ console.error(
77
+ `Failed fetching version for ${key}: ${error.message}`
78
+ );
79
+ return null;
80
+ });
81
+ promiseMap.set(key, promise);
82
+ }
83
+ }
84
+ } else {
85
+ const errorMessage = `Path doesn't exist: ${filePath}`;
86
+ failed.push({
87
+ name: "get version",
88
+ error: errorMessage
89
+ });
90
+ console.error(errorMessage);
91
+ }
61
92
  }
62
93
 
63
- function bumpVersion(filePath, name) {
64
- if (fs.existsSync(filePath)) {
65
-
66
- let object = require(filePath)
67
- if (object) {
68
- let newObject = { ...object }
69
- let dependencies = object.dependencies || {}
70
- let devDependencies = object.devDependencies || {}
71
- for (const name of Object.keys(dependencies)) {
72
- if (item[name]) {
73
- newObject.dependencies[name] = item[name]
74
- }
75
- }
76
-
77
- for (const name of Object.keys(devDependencies)) {
78
- if (item[name]) {
79
- newObject.devDependencies[name] = item[name]
80
- }
81
- }
82
-
83
- if (fs.existsSync(filePath)) {
84
- fs.unlinkSync(filePath)
85
- }
86
-
87
- fs.writeFileSync(filePath, JSON.stringify(object, null, 2))
88
- }
89
- } else {
90
- failed.push({ name: 'bump version', des: 'path doesn\'t exist:' + filePath })
91
- }
94
+ /**
95
+ * Updates the package.json file with the latest module versions.
96
+ * @param {string} filePath - The path to the package.json file.
97
+ */
98
+ function updateVersion(filePath) {
99
+ if (fs.existsSync(filePath)) {
100
+ delete require.cache[require.resolve(filePath)];
101
+ const object = require(filePath);
102
+
103
+ if (object) {
104
+ const dependencies = object.dependencies || {};
105
+ const devDependencies = object.devDependencies || {};
106
+ const allDependencies = { ...dependencies, ...devDependencies };
107
+
108
+ let updated = false;
109
+ let newObject = { ...object };
110
+
111
+ for (let key of Object.keys(allDependencies)) {
112
+ if (!key.startsWith("@cocreate/")) continue;
113
+ const currentVersion = allDependencies[key];
114
+ const latestVersion = item[key];
115
+
116
+ if (latestVersion && latestVersion !== currentVersion) {
117
+ if (dependencies[key]) {
118
+ newObject.dependencies[key] = latestVersion;
119
+ }
120
+ if (devDependencies[key]) {
121
+ newObject.devDependencies[key] = latestVersion;
122
+ }
123
+
124
+ updated = true;
125
+ console.log(
126
+ `Updated ${key} from ${currentVersion} to ${latestVersion}.`
127
+ );
128
+ } else {
129
+ if (latestVersion === null) {
130
+ console.log(
131
+ `Could not update ${key}: Failed to fetch the latest version.`
132
+ );
133
+ } else {
134
+ console.log(
135
+ `Skipped updating ${key}, already at the latest version: ${currentVersion}.`
136
+ );
137
+ }
138
+ }
139
+ }
140
+
141
+ if (updated) {
142
+ fs.writeFileSync(filePath, JSON.stringify(newObject, null, 2));
143
+ console.log(`Updated ${filePath} successfully.`);
144
+ }
145
+ }
146
+ } else {
147
+ const errorMessage = `Path doesn't exist: ${filePath}`;
148
+ failed.push({
149
+ name: "update version",
150
+ error: errorMessage
151
+ });
152
+ console.error(errorMessage);
153
+ }
92
154
  }
@@ -1,28 +1,32 @@
1
- const spawn = require('../spawn');
2
- const path = require('path');
3
- let fs = require('fs');
1
+ const spawn = require("../spawn");
2
+ const path = require("path");
3
+ let fs = require("fs");
4
4
 
5
5
  module.exports = async function gitClone(repos, args) {
6
- const failed = [];
7
- const cwdPath = path.resolve(process.cwd());
6
+ const failed = [];
7
+ const cwdPath = path.resolve(process.cwd());
8
8
 
9
- for (let i = 0; i < repos.length; i++) {
10
- // TODO: Check if path exist and if git.config or package.json exist continue
11
- if (cwdPath !== repos[i].absolutePath) {
12
- if (!fs.existsSync(repos[i].directory))
13
- fs.mkdirSync(repos[i].directory);
9
+ for (let i = 0; i < repos.length; i++) {
10
+ // TODO: Check if path exist and if git.config or package.json exist continue
11
+ if (cwdPath !== repos[i].absolutePath) {
12
+ if (!fs.existsSync(repos[i].directory))
13
+ fs.mkdirSync(repos[i].directory);
14
14
 
15
- if (!repos[i].repo.startsWith('http://') && !repos[i].repo.startsWith('https://'))
16
- repos[i].repo = 'https://' + repos[i].repo
15
+ if (
16
+ !repos[i].repo.startsWith("http://") &&
17
+ !repos[i].repo.startsWith("https://")
18
+ )
19
+ repos[i].repo = "https://" + repos[i].repo;
17
20
 
18
- let exitCode = await spawn('git', ['clone', `${repos[i].repo}`], { stdio: 'inherit', cwd: repos[i].directory })
19
- if (exitCode !== 0) {
20
- failed.push({ name: repos[i].name, des: `cloning failed` })
21
- }
21
+ let exitCode = await spawn("git", ["clone", `${repos[i].repo}`], {
22
+ stdio: "inherit",
23
+ cwd: repos[i].directory
24
+ });
25
+ if (exitCode !== 0) {
26
+ failed.push({ name: repos[i].name, error: `cloning failed` });
27
+ }
28
+ }
29
+ }
22
30
 
23
- }
24
- }
25
-
26
- return failed;
27
-
28
- }
31
+ return failed;
32
+ };
@@ -137,7 +137,7 @@ jobs:
137
137
 
138
138
  // Define the directories with wildcards
139
139
  const directories = [
140
- "../../../../../CoCreate-components/*/",
140
+ "../../../../../CoCreate-modules/*/",
141
141
  "../../../../../CoCreate-apps/*/",
142
142
  "../../../../../CoCreate-plugins/*/",
143
143
  "../../../../../CoCreateCSS/",
@@ -111,7 +111,7 @@ function createOrUpdateFile(directoryPath, fileName) {
111
111
 
112
112
  // Define the directories with wildcards
113
113
  const directories = [
114
- "../../../../../CoCreate-components/*/",
114
+ "../../../../../CoCreate-modules/*/",
115
115
  "../../../../../CoCreate-apps/*/",
116
116
  "../../../../../CoCreate-plugins/*/",
117
117
  "../../../../../CoCreateCSS/",
@@ -1,41 +1,32 @@
1
1
  let glob = require("glob");
2
- let fs = require('fs');
3
- const path = require("path")
2
+ let fs = require("fs");
3
+ const path = require("path");
4
4
 
5
5
  function globUpdater(er, files) {
6
- if (er)
7
- console.log(files, 'glob resolving issue')
8
- else
9
- files.forEach(filename => update(filename))
6
+ if (er) console.log(files, "glob resolving issue");
7
+ else files.forEach((filename) => update(filename));
10
8
  }
11
9
 
12
-
13
-
14
-
15
10
  function update(Path) {
16
- let fileContent = `# ignore
11
+ let fileContent = `# ignore
17
12
  node_modules
18
13
  dist
19
14
  .npmrc
20
15
 
21
16
  `;
22
- if (fs.existsSync(Path))
23
- fs.unlinkSync(Path)
24
- fs.writeFileSync(Path, fileContent)
25
-
17
+ if (fs.existsSync(Path)) fs.unlinkSync(Path);
18
+ fs.writeFileSync(Path, fileContent);
26
19
  }
27
20
 
28
-
29
-
30
- // glob("../CoCreate-components/CoCreate-action/.gitignore", globUpdater)
21
+ // glob("../CoCreate-modules/CoCreate-action/.gitignore", globUpdater)
31
22
  // glob("./.gitignore", globUpdater)
32
23
  // glob("../CoCreate-adminUI/.gitignore", globUpdater)
33
- glob("../CoCreate-components/*/.gitignore", globUpdater)
34
- glob("../CoCreate-apps/*/.gitignore", globUpdater)
35
- glob("../CoCreate-plugins/*/.gitignore", globUpdater)
24
+ glob("../CoCreate-modules/*/.gitignore", globUpdater);
25
+ glob("../CoCreate-apps/*/.gitignore", globUpdater);
26
+ glob("../CoCreate-plugins/*/.gitignore", globUpdater);
36
27
  // glob("../CoCreate-website/.gitignore", globUpdater)
37
28
  // glob("../CoCreate-website-template/.gitignore", globUpdater)
38
- glob("../CoCreateCSS/.gitignore", globUpdater)
29
+ glob("../CoCreateCSS/.gitignore", globUpdater);
39
30
  // glob("../CoCreateJS/.gitignore", globUpdater)
40
31
 
41
- console.log('finished')
32
+ console.log("finished");
@@ -1,26 +1,21 @@
1
1
  let glob = require("glob");
2
- let fs = require('fs');
3
- const path = require("path")
2
+ let fs = require("fs");
3
+ const path = require("path");
4
4
 
5
5
  function globUpdater(er, files) {
6
-
7
- if (er)
8
- console.log(files, 'glob resolving issue')
6
+ if (er) console.log(files, "glob resolving issue");
9
7
  else
10
- files.forEach(filename => {
11
-
12
- console.log(filename + '/manual.yml', 'glob resolving issue')
13
- update(filename + '/manual.yml')
14
- })
15
-
8
+ files.forEach((filename) => {
9
+ console.log(filename + "/manual.yml", "glob resolving issue");
10
+ update(filename + "/manual.yml");
11
+ });
16
12
  }
17
13
 
18
-
19
-
20
-
21
14
  function update(Path) {
22
15
  // component name
23
- let name = path.basename(path.resolve(path.dirname(Path), '../..')).substring(9);
16
+ let name = path
17
+ .basename(path.resolve(path.dirname(Path), "../.."))
18
+ .substring(9);
24
19
  let fileContent = `name: Manual Workflow
25
20
  on:
26
21
  workflow_dispatch:
@@ -68,19 +63,14 @@ jobs:
68
63
 
69
64
  `;
70
65
 
71
-
72
- if (fs.existsSync(Path))
73
- fs.unlinkSync(Path)
74
- fs.writeFileSync(Path, fileContent)
75
-
66
+ if (fs.existsSync(Path)) fs.unlinkSync(Path);
67
+ fs.writeFileSync(Path, fileContent);
76
68
  }
77
69
 
78
-
79
-
80
- // glob("../CoCreate-components/CoCreate-action/.github/workflows", globUpdater)
81
- glob("../CoCreate-components/*/.github/workflows/", globUpdater)
82
- glob("../CoCreate-apps/*/.github/workflows/", globUpdater)
83
- glob("../CoCreate-plugins/*/.github/workflows/", globUpdater)
70
+ // glob("../CoCreate-modules/CoCreate-action/.github/workflows", globUpdater)
71
+ glob("../CoCreate-modules/*/.github/workflows/", globUpdater);
72
+ glob("../CoCreate-apps/*/.github/workflows/", globUpdater);
73
+ glob("../CoCreate-plugins/*/.github/workflows/", globUpdater);
84
74
 
85
75
  // substrin (9) removes CoCreateC leving namme as SS
86
76
  // glob("../CoCreateCSS/.github/workflows/", globUpdater)
@@ -88,4 +78,4 @@ glob("../CoCreate-plugins/*/.github/workflows/", globUpdater)
88
78
  // does not need to add name... will require for name to be removed from destination
89
79
  // glob("../CoCreateJS/.github/workflows/", globUpdater)
90
80
 
91
- console.log('finished')
81
+ console.log("finished");
@@ -77,7 +77,7 @@ function createOrUpdateFile(directoryPath, fileName) {
77
77
 
78
78
  // Define the directories with wildcards
79
79
  const directories = [
80
- "../../../../../CoCreate-components/*/",
80
+ "../../../../../CoCreate-modules/*/",
81
81
  "../../../../../CoCreate-apps/*/",
82
82
  "../../../../../CoCreate-plugins/*/",
83
83
  "../../../../../CoCreateCSS/",
@@ -1,22 +1,17 @@
1
1
  let glob = require("glob");
2
- let fs = require('fs');
2
+ let fs = require("fs");
3
3
 
4
4
  function globUpdater(er, files) {
5
- if (er)
6
- console.log(files, 'glob resolving issue')
7
- else
8
- files.forEach(filename => update(filename))
5
+ if (er) console.log(files, "glob resolving issue");
6
+ else files.forEach((filename) => update(filename));
9
7
  }
10
8
 
11
-
12
9
  function update(YmlPath) {
13
- if (fs.existsSync(YmlPath))
14
- fs.unlinkSync(YmlPath)
10
+ if (fs.existsSync(YmlPath)) fs.unlinkSync(YmlPath);
15
11
  }
16
12
 
17
-
18
- glob("../CoCreate-components/CoCreate-action/dist", globUpdater)
19
- // glob("../CoCreate-components/*/.github/workflows/automation.yml", globUpdater)
13
+ glob("../CoCreate-modules/CoCreate-action/dist", globUpdater);
14
+ // glob("../CoCreate-modules/*/.github/workflows/automation.yml", globUpdater)
20
15
  // glob("../CoCreate-apps/*/.github/workflows/automation.yml", globUpdater)
21
16
  // glob("../CoCreate-plugins/*/.github/workflows/automation.yml", globUpdater)
22
17
 
@@ -26,4 +21,4 @@ glob("../CoCreate-components/CoCreate-action/dist", globUpdater)
26
21
  // does not need to add name... will require for name to be removed from destination
27
22
  // glob("../CoCreateJS/.github/workflows/automation.yml", globUpdater)
28
23
 
29
- console.log('finished')
24
+ console.log("finished");
@@ -1,43 +1,35 @@
1
1
  let glob = require("glob");
2
- let fs = require('fs');
3
- const path = require("path")
2
+ let fs = require("fs");
3
+ const path = require("path");
4
4
 
5
5
  function globUpdater(er, files) {
6
- if (er)
7
- console.log(files, 'glob resolving issue')
8
- else
9
- files.forEach(filename => update(filename))
6
+ if (er) console.log(files, "glob resolving issue");
7
+ else files.forEach((filename) => update(filename));
10
8
  }
11
9
 
12
-
13
10
  function update(mdPath) {
14
- // component name
15
- // console.log(mdPath);
16
- let nameDir = mdPath;
17
- do{
18
- nameDir = path.dirname(nameDir);
19
- }while(! path.basename(nameDir).startsWith('CoCreate-'))
20
- let name = path.basename(nameDir).substring(9);
21
- // console.log(name);
22
- // process.exit();
23
- let replaceContent = fs.readFileSync(mdPath).toString()
24
-
25
- console.log(replaceContent, name);
26
- let replaced = replaceContent.replace(/boilerplate/ig, name)
27
-
28
-
29
- if (fs.existsSync(mdPath))
30
- fs.unlinkSync(mdPath)
31
- fs.writeFileSync(mdPath, replaced)
32
-
33
-
11
+ // component name
12
+ // console.log(mdPath);
13
+ let nameDir = mdPath;
14
+ do {
15
+ nameDir = path.dirname(nameDir);
16
+ } while (!path.basename(nameDir).startsWith("CoCreate-"));
17
+ let name = path.basename(nameDir).substring(9);
18
+ // console.log(name);
19
+ // process.exit();
20
+ let replaceContent = fs.readFileSync(mdPath).toString();
21
+
22
+ console.log(replaceContent, name);
23
+ let replaced = replaceContent.replace(/boilerplate/gi, name);
24
+
25
+ if (fs.existsSync(mdPath)) fs.unlinkSync(mdPath);
26
+ fs.writeFileSync(mdPath, replaced);
34
27
  }
35
28
 
36
-
37
- glob("./docs/", globUpdater)
29
+ glob("./docs/", globUpdater);
38
30
  // glob("../CoCreate-docs/docs/*.html", globUpdater)
39
- // glob("../CoCreate-components/*/docs/*.html", globUpdater)
31
+ // glob("../CoCreate-modules/*/docs/*.html", globUpdater)
40
32
  // glob("../CoCreate-apps/*/docs/*.html", globUpdater)
41
33
  // glob("../CoCreate-plugins/*/docs/*.html", globUpdater)
42
34
 
43
- console.log('finished')
35
+ console.log("finished");