@cocreate/cli 1.29.3 → 1.31.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ # [1.31.0](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.30.0...v1.31.0) (2023-06-09)
2
+
3
+
4
+ ### Features
5
+
6
+ * exposed functions to module.exports ([1a11a4a](https://github.com/CoCreate-app/CoCreate-cli/commit/1a11a4a49041e10b31e4aa9ad358da3da0ec4c01))
7
+ * Refactor configuration loading logic, add prompts for env variables, and allow nested choices ([63c8567](https://github.com/CoCreate-app/CoCreate-cli/commit/63c8567bfb1cd700d1f921685fe7812cb3dc1919))
8
+
9
+ # [1.30.0](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.29.3...v1.30.0) (2023-06-07)
10
+
11
+
12
+ ### Features
13
+
14
+ * Add @cocreate/file dependency, remove @cocreate/docs and prompt from the dependencies section, and refactor code inside the upload.js file. ([8fa20cd](https://github.com/CoCreate-app/CoCreate-cli/commit/8fa20cdbde1ab3e1d4397f41673d0d9b17c4966c))
15
+ * Install "coc" globally if not already installed ([cad848b](https://github.com/CoCreate-app/CoCreate-cli/commit/cad848bfefe2f66fb323eca3eac292d9547e6cc6))
16
+
1
17
  ## [1.29.3](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.29.2...v1.29.3) (2023-06-04)
2
18
 
3
19
 
@@ -1,9 +1,7 @@
1
1
  module.exports = {
2
- "config": {
3
- "organization_id": "",
4
- "key": "",
5
- "host": ""
6
- },
2
+ "organization_id": "",
3
+ "key": "",
4
+ "host": "",
7
5
  "sources": [
8
6
  {
9
7
  "collection": "files",
package/check-coc.js ADDED
@@ -0,0 +1,16 @@
1
+ const { execSync } = require('child_process');
2
+
3
+ try {
4
+ // Try to run "coc" command
5
+ execSync('coc --version', { stdio: 'ignore' });
6
+ console.log('"coc" is already installed globally.');
7
+ } catch (error) {
8
+ // If "coc" command does not exist, install it globally
9
+ console.log('"coc" command not found. Installing globally...');
10
+ try {
11
+ execSync('npm install -g coc', { stdio: 'inherit' });
12
+ console.log('"coc" has been installed globally.');
13
+ } catch (error) {
14
+ console.error('Failed to install "coc" globally:', error);
15
+ }
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/cli",
3
- "version": "1.29.3",
3
+ "version": "1.31.0",
4
4
  "description": "Polyrepo management bash CLI tool. Run all git commands and yarn commands on multiple repositories. Also includes a few custom macros for cloning, installing, etc.",
5
5
  "keywords": [
6
6
  "cli",
@@ -37,7 +37,6 @@
37
37
  "replace": "nodejs src/commands/replace.js",
38
38
  "webpack": "nodejs src/commands/fs/webpack.js",
39
39
  "docs": "node ./node_modules/@cocreate/docs/src/index.js",
40
- "hosting": "node ./node_modules/@cocreate/hosting/src/index.js",
41
40
  "permissions": "chmod +rwx /home/ubuntu/.nvm/versions/node/v19.8.1/bin/coc"
42
41
  },
43
42
  "repository": {
@@ -54,16 +53,15 @@
54
53
  "type": "GitHub Sponsors ❤",
55
54
  "url": "https://github.com/sponsors/CoCreate-app"
56
55
  },
57
- "main": "index.js",
56
+ "main": "src/commands/index.js",
58
57
  "bin": {
59
58
  "coc": "src/coc.js"
60
59
  },
61
60
  "dependencies": {
62
- "@cocreate/docs": "^1.7.15",
63
- "@cocreate/hosting": "^1.10.8",
61
+ "@cocreate/docs": "^1.8.2",
62
+ "@cocreate/file": "^1.0.0",
64
63
  "colors": "latest",
65
64
  "glob": "^7.1.7",
66
- "prettier": "^2.3.2",
67
- "prompt": "^1.2.0"
65
+ "prettier": "^2.3.2"
68
66
  }
69
67
  }
package/repositories.js CHANGED
@@ -98,6 +98,10 @@ module.exports = [
98
98
  'path': '../CoCreate-fetch',
99
99
  'repo': 'github.com/CoCreate-app/CoCreate-fetch.git'
100
100
  },
101
+ {
102
+ 'path': '../CoCreate-file',
103
+ 'repo': 'github.com/CoCreate-app/CoCreate-file.git'
104
+ },
101
105
  {
102
106
  'path': '../CoCreate-filter',
103
107
  'repo': 'github.com/CoCreate-app/CoCreate-filter.git'
@@ -0,0 +1,100 @@
1
+ const readline = require('readline');
2
+ const os = require('os');
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+
6
+ module.exports = async function CoCreateConfig(items, processEnv = true, updateGlobal = true) {
7
+ async function promptForInput(question) {
8
+ const rl = readline.createInterface({
9
+ input: process.stdin,
10
+ output: process.stdout
11
+ });
12
+
13
+ return new Promise((resolve) => {
14
+ rl.question(question, (answer) => {
15
+ rl.close();
16
+ resolve(answer.trim());
17
+ });
18
+ });
19
+ }
20
+
21
+ const filterEmptyValues = (obj) => {
22
+ return Object.fromEntries(
23
+ Object.entries(obj).filter(([_, value]) => {
24
+ if (typeof value === 'object' && !Array.isArray(value)) {
25
+ return Object.keys(value).length > 0;
26
+ } else if (Array.isArray(value)) {
27
+ return value.length > 0;
28
+ } else {
29
+ return value !== '';
30
+ }
31
+ })
32
+ );
33
+ };
34
+
35
+ let config = {};
36
+ let update = false;
37
+
38
+ async function getConfig(items) {
39
+ if (!Array.isArray(items)) {
40
+ items = [items];
41
+ }
42
+ for (let i = 0; i < items.length; i++) {
43
+ const { key, prompt, choices } = items[i];
44
+ if (!key) {
45
+ if (!prompt && prompt !== '' || !choices) continue;
46
+ const answer = await promptForInput(prompt || `${key}: `);
47
+ const choice = choices[answer];
48
+ if (choice) {
49
+ await getConfig(choice);
50
+ }
51
+ } else {
52
+
53
+ if (process.env[key]) {
54
+ config[key] = process.env[key];
55
+ } else if (localConfig[key]) {
56
+ config[key] = localConfig[key];
57
+ } else if (globalConfig[key]) {
58
+ config[key] = globalConfig[key];
59
+ } else if (prompt || prompt === '') {
60
+ config[key] = await promptForInput(prompt || `${key}: `);
61
+ if (processEnv) process.env[key] = config[key];
62
+ if (updateGlobal) update = true;
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ let localConfig = {};
69
+ const localConfigPath = path.resolve(process.cwd(), 'CoCreate.config.js');
70
+ if (fs.existsSync(localConfigPath)) {
71
+ localConfig = require(localConfigPath);
72
+ }
73
+
74
+ let globalConfig = {};
75
+ const globalConfigPath = path.resolve(os.homedir(), 'CoCreate.config.js');
76
+ if (fs.existsSync(globalConfigPath)) {
77
+ globalConfig = require(globalConfigPath);
78
+ }
79
+
80
+ if (items) {
81
+ await getConfig(items);
82
+
83
+ if (update) {
84
+ const updatedGlobalConfig = {
85
+ ...filterEmptyValues(globalConfig),
86
+ ...filterEmptyValues(config)
87
+ };
88
+
89
+ const globalConfigString = `module.exports = ${JSON.stringify(updatedGlobalConfig, null, 2)};`;
90
+ fs.writeFileSync(globalConfigPath, globalConfigString);
91
+ }
92
+ } else {
93
+ config = {
94
+ ...filterEmptyValues(globalConfig),
95
+ ...filterEmptyValues(localConfig)
96
+ };
97
+ }
98
+
99
+ return config;
100
+ }
@@ -0,0 +1,3 @@
1
+ const config = require('./config.js');
2
+
3
+ module.exports = { config }
@@ -0,0 +1,8 @@
1
+ const crud = require('@cocreate/crud-client')
2
+ const mime = require('mime-types')
3
+ const fs = require('fs');
4
+ const file = require('@cocreate/file')
5
+
6
+ module.exports = async function upload(repos, args) {
7
+ await file()
8
+ }
@@ -1,71 +0,0 @@
1
- let fs = require('fs');
2
- const path = require("path");
3
-
4
- module.exports = async function linkPackages(repos, args) {
5
- const failed = []
6
- const prompt = require('prompt');
7
-
8
- prompt.start();
9
-
10
- const properties = [
11
- {
12
- name: 'email',
13
- },
14
- {
15
- name: 'name',
16
- },
17
- {
18
- name: 'username',
19
- },
20
- {
21
- name: 'password',
22
- hidden: true
23
- }
24
- ];
25
-
26
- prompt.get(properties, async function (err, result) {
27
- if (err)
28
- return [{
29
- name: 'gitConfig',
30
- des: err
31
- }]
32
-
33
- await updateConfig(result);
34
- });
35
-
36
- async function updateConfig(result){
37
- (async() => {
38
- for (let repo of repos) {
39
- await update(repo, result);
40
- }
41
- console.log('finished');
42
- return failed
43
- })();
44
- }
45
-
46
- function update(param, result) {
47
- if (!param) return;
48
- let { absoutePath, name } = param;
49
- let fileContent = `[core]
50
- repositoryformatversion = 0
51
- filemode = true
52
- bare = false
53
- logallrefupdates = true
54
- [user]
55
- name = ${result.name}
56
- email = ${result.email}
57
- [remote "origin"]
58
- url = https://${result.username}:${result.password}@github.com/CoCreate-app/${name}.git
59
- fetch = +refs/heads/*:refs/remotes/origin/*
60
- [branch "master"]
61
- remote = origin
62
- merge = refs/heads/master
63
-
64
- `;
65
-
66
- let MdPath = path.resolve(absoutePath, '.git/config');
67
- if (fs.existsSync(MdPath))
68
- fs.unlinkSync(MdPath);
69
- fs.writeFileSync(MdPath, fileContent);
70
- }
71
- }
@@ -1,72 +0,0 @@
1
- let fs = require('fs');
2
- const path = require('path');
3
- const failed = [];
4
-
5
- module.exports = async function gitConfig(repos, args) {
6
- try {
7
- await getPrompts(repos);
8
- }
9
- catch (err) {
10
- failed.push({ name: 'GENERAL', des: err.message });
11
- console.error(err.red);
12
- }
13
- }
14
-
15
- async function getPrompts(repos){
16
- const prompt = require('prompt');
17
-
18
- prompt.start();
19
-
20
- const properties = [
21
- {
22
- name: 'email',
23
- },
24
- {
25
- name: 'name',
26
- },
27
- {
28
- name: 'username',
29
- },
30
- {
31
- name: 'password',
32
- hidden: true
33
- }
34
- ];
35
-
36
- prompt.get(properties, async function (err, result) {
37
- if (err) { return console.error(err); }
38
- await updateConfig(repos, result);
39
- });
40
-
41
- }
42
-
43
- async function updateConfig(repos, result){
44
- for (let meta of repos) {
45
- if (!meta) return;
46
- let fileContent = `[core]
47
- repositoryformatversion = 0
48
- filemode = true
49
- bare = false
50
- logallrefupdates = true
51
- [user]
52
- name = ${result.name}
53
- email = ${result.email}
54
- [remote "origin"]
55
- url = https://${result.username}:${result.password}@${meta.repo}
56
- fetch = +refs/heads/*:refs/remotes/origin/*
57
- [branch "master"]
58
- remote = origin
59
- merge = refs/heads/master
60
-
61
- `;
62
-
63
- let MdPath = path.resolve(meta.path, '.git/config');
64
- if (fs.existsSync(MdPath))
65
- fs.unlinkSync(MdPath);
66
- fs.writeFileSync(MdPath, fileContent);
67
- console.log('configured: ', meta.repo);
68
- }
69
- console.log('finished');
70
- return failed
71
-
72
- }