@cocreate/cli 1.14.30 → 1.16.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,17 @@
1
+ # [1.16.0](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.15.0...v1.16.0) (2023-02-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * run symlink on coc install ([c4bdf15](https://github.com/CoCreate-app/CoCreate-cli/commit/c4bdf15d7b7f6c6cbe90a68904ca6042f2d6db38))
7
+
8
+ # [1.15.0](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.14.30...v1.15.0) (2023-02-18)
9
+
10
+
11
+ ### Features
12
+
13
+ * auto detects your chosen package manager, Currently supports npm and yarn ([c3349b3](https://github.com/CoCreate-app/CoCreate-cli/commit/c3349b3f3448ff27a1efd98e3b6d3eb14b09aced))
14
+
1
15
  ## [1.14.30](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.14.29...v1.14.30) (2023-02-02)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/cli",
3
- "version": "1.14.30",
3
+ "version": "1.16.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",
@@ -77,7 +77,6 @@
77
77
  "colors": "latest",
78
78
  "glob": "^7.1.7",
79
79
  "got": "latest",
80
- "minimist": "latest",
81
80
  "prettier": "^2.3.2",
82
81
  "prompt": "^1.2.0"
83
82
  }
package/repositories.js CHANGED
@@ -87,7 +87,7 @@ module.exports = [
87
87
  'repo': 'github.com/CoCreate-app/CoCreate-elements.git'
88
88
  },
89
89
  {
90
- 'path': '../CoCreate-components/CoCreate-events',
90
+ 'path': '/home/ubuntu/CoCreateServer/CoCreate-components/CoCreate-events',
91
91
  'repo': 'github.com/CoCreate-app/CoCreate-events.git'
92
92
  },
93
93
  {
@@ -214,10 +214,6 @@ module.exports = [
214
214
  'path': '/home/ubuntu/CoCreateServer/CoCreate-components/CoCreate-select',
215
215
  'repo': 'github.com/CoCreate-app/CoCreate-select.git'
216
216
  },
217
- {
218
- 'path': '/home/ubuntu/CoCreateServer/CoCreate-components/CoCreate-selected',
219
- 'repo': 'github.com/CoCreate-app/CoCreate-selected.git'
220
- },
221
217
  {
222
218
  'path': '/home/ubuntu/CoCreateServer/CoCreate-components/CoCreate-selection',
223
219
  'repo': 'github.com/CoCreate-app/CoCreate-selection.git'
@@ -238,10 +234,6 @@ module.exports = [
238
234
  'path': '/home/ubuntu/CoCreateServer/CoCreate-components/CoCreate-text',
239
235
  'repo': 'github.com/CoCreate-app/CoCreate-text.git'
240
236
  },
241
- // {
242
- // 'path': '/home/ubuntu/CoCreateServer/CoCreate-components/CoCreate-toggle',
243
- // 'repo': 'github.com/CoCreate-app/CoCreate-toggle.git'
244
- // },
245
237
  {
246
238
  'path': '/home/ubuntu/CoCreateServer/CoCreate-components/CoCreate-toolbar',
247
239
  'repo': 'github.com/CoCreate-app/CoCreate-toolbar.git'
@@ -350,10 +342,6 @@ module.exports = [
350
342
  'path': '/home/ubuntu/CoCreateServer/CoCreate-plugins/CoCreate-linkedin',
351
343
  'repo': 'github.com/CoCreate-app/CoCreate-linkedin.git'
352
344
  },
353
- // {
354
- // 'path': '/home/ubuntu/CoCreateServer/CoCreate-plugins/CoCreate-monaco',
355
- // 'repo': 'github.com/CoCreate-app/CoCreate-monaco.git'
356
- // },
357
345
  {
358
346
  'path': '/home/ubuntu/CoCreateServer/CoCreate-plugins/CoCreate-pickr',
359
347
  'repo': 'github.com/CoCreate-app/CoCreate-pickr.git'
@@ -370,10 +358,6 @@ module.exports = [
370
358
  'path': '/home/ubuntu/CoCreateServer/CoCreate-plugins/CoCreate-prism',
371
359
  'repo': 'github.com/CoCreate-app/CoCreate-prism.git'
372
360
  },
373
- // {
374
- // 'path': '/home/ubuntu/CoCreateServer/CoCreate-plugins/CoCreate-quill',
375
- // 'repo': 'github.com/CoCreate-app/CoCreate-quill.git'
376
- // },
377
361
  {
378
362
  'path': '/home/ubuntu/CoCreateServer/CoCreate-plugins/CoCreate-s3',
379
363
  'repo': 'github.com/CoCreate-app/CoCreate-s3.git'
@@ -409,14 +393,14 @@ module.exports = [
409
393
 
410
394
 
411
395
 
412
- // {
413
- // 'path': '/home/ubuntu/CoCreateServer/CoCreateWS',
414
- // 'repo': 'github.com/CoCreate-app/CoCreateWS.git'
415
- // },
416
- // {
417
- // 'path': '/home/ubuntu/CoCreateServer/CoCreateApi',
418
- // 'repo': 'github.com/CoCreate-app/CoCreateApi.git'
419
- // },
396
+ {
397
+ 'path': '/home/ubuntu/CoCreateServer/CoCreateWS',
398
+ 'repo': 'github.com/CoCreate-app/CoCreateWS.git'
399
+ },
400
+ {
401
+ 'path': '/home/ubuntu/CoCreateServer/CoCreateApi',
402
+ 'repo': 'github.com/CoCreate-app/CoCreateApi.git'
403
+ },
420
404
 
421
405
  {
422
406
  'path': '/home/ubuntu/CoCreateServer/CoCreateLB',
@@ -479,14 +463,6 @@ module.exports = [
479
463
  'path': '/home/ubuntu/CoCreateServer/CoCreate-components/CoCreate-keepalived',
480
464
  'repo': 'github.com/CoCreate-app/CoCreate-keepalived.git'
481
465
  },
482
- // {
483
- // 'path': '/home/ubuntu/CoCreateServer/CoCreate-components/CoCreate-mongodb',
484
- // 'repo': 'github.com/CoCreate-app/CoCreate-mongodb.git'
485
- // },
486
- // {
487
- // 'path': '/home/ubuntu/CoCreateServer/CoCreate-components/CoCreate-openebs',
488
- // 'repo': 'github.com/CoCreate-app/CoCreate-openebs.git'
489
- // },
490
466
  {
491
467
  'path': '/home/ubuntu/CoCreateServer/CoCreate-components/CoCreate-ide',
492
468
  'repo': 'github.com/CoCreate-app/CoCreate-ide.git'
package/src/addMeta.js CHANGED
@@ -1,60 +1,65 @@
1
1
  const fs = require('fs')
2
2
  const path = require("path")
3
+ const util = require('node:util');
4
+ const exec = util.promisify(require('node:child_process').exec);
5
+
6
+ module.exports = async function addMeta(repos, failed, directory) {
7
+ let packageManager;
8
+ for (let i = 0; i < repos.length; i++) {
9
+ repos[i].name = path.basename(repos[i].path);
10
+ repos[i].plainName = repos[i].name.substr(9);
11
+
12
+ if (directory) {
13
+ repos[i].ppath = path.resolve(directory, repos[i].path);
14
+ repos[i].absolutePath = path.resolve(directory, repos[i].path);
15
+ repos[i].directory = directory;
16
+ }
3
17
 
4
- module.exports = function addMeta(repos, failed) {
5
- return repos.map(repo => {
6
- let {
7
- name,
8
- ppath
9
- } = repo;
10
-
11
-
12
-
13
- let packagejson = path.resolve(ppath, 'package.json');
18
+ let packagejson = path.resolve(repos[i].absolutePath, 'package.json');
14
19
  if (!fs.existsSync(packagejson)) {
15
- console.error('package json not found for', name);
20
+ console.error('package json not found for', repos[i].name);
16
21
  failed.push({
17
- name,
22
+ name: repos[i].name,
18
23
  des: 'package json not found'
19
24
  })
20
- return false;
21
25
  }
26
+
22
27
  let packageObj
23
28
  try {
24
29
  packageObj = require(packagejson);
25
-
26
30
  }
27
31
  catch (err) {
28
- console.error(err.message)
29
- return false;
32
+ console.error('packageObj', err.message)
30
33
  }
31
34
 
32
35
 
33
- let packageName = name.startsWith('cocreate-') ?
34
- '@cocreate/' + name.substr(9) : packageObj.name;
36
+ repos[i].packageName = packageObj.name;
35
37
 
36
- let deps = Object.keys(packageObj['dependencies'] || {})
38
+ repos[i].deps = Object.keys(packageObj['dependencies'] || {})
37
39
  .filter(packageName => packageName.startsWith('@cocreate/'));
38
- let devDeps = Object.keys(packageObj['devDependencies'] || {})
40
+ repos[i].devDeps = Object.keys(packageObj['devDependencies'] || {})
39
41
  .filter(packageName => packageName.startsWith('@cocreate/'));
40
-
41
- // let nodeModulePath = path.resolve(ppath, './node_modules/@cocreate');
42
-
43
- // let deps = fs.existsSync(nodeModulePath) ?
44
- // fs.readdirSync(nodeModulePath).map(name => '@cocreate/' + name):
45
- // [];
46
-
47
- return { ...repo,
48
- name,
49
- packageName,
50
- ppath,
51
- deps,
52
- devDeps
53
-
42
+
43
+ if (!repos[i].packageManager) {
44
+ if (packageManager)
45
+ repos[i].packageManager = packageManager
46
+ else {
47
+ repos[i].packageManager = 'npm'
48
+ let lockFile = path.resolve(repos[i].absolutePath, 'package-lock.json');
49
+ if (!fs.existsSync(lockFile)) {
50
+ lockFile = path.resolve(repos[i].absolutePath, 'yarn.lock');
51
+ if (fs.existsSync(lockFile))
52
+ repos[i].packageManager = 'yarn'
53
+ else {
54
+ const { error } = await exec('yarn --version');
55
+ if (!error)
56
+ repos[i].packageManager = 'yarn'
57
+ }
58
+ packageManager = repos[i].packageManager
59
+ }
60
+ }
54
61
  }
62
+ }
55
63
 
56
-
57
-
58
- })
59
-
64
+ return repos
60
65
  }
package/src/coc.js CHANGED
@@ -1,32 +1,30 @@
1
1
  #!/usr/bin/env node
2
-
3
- const minimist = require('minimist');
4
-
5
2
  const path = require("path");
6
3
  const fs = require("fs");
7
4
  const execute = require('./execute');
8
5
  const argv = process.argv.slice(2);
9
- console.log('bumper')
6
+ const addMeta = require('./addMeta');
7
+
10
8
 
11
9
  if (argv.length < 1) {
12
10
  console.error("enter some command to do something");
13
11
  process.exit(1);
14
12
  }
13
+ let repos, command, config = {};
14
+
15
+ const options = ['-self']
16
+ for (let option of options) {
17
+ if (argv.includes(option)) {
18
+ config.self = true
19
+ const index = argv.indexOf(option);
20
+ delete argv[index];
21
+ }
22
+ }
15
23
 
16
-
17
- let config = minimist(argv, {
18
- alias: { config: 'c', absolutePath: 'cf', hideMessage: 'h' },
19
- stopEarly: true
20
- });
21
-
22
-
23
- let repos, command;
24
-
25
- command = config['_']
24
+ command = argv
26
25
  .map((part) => part.match(/ |'|"/) ? `'${part.replace(/'/,'\\\'')}'` : part)
27
26
  .join(" ");
28
27
 
29
-
30
28
  function getRepositories(path) {
31
29
  try {
32
30
  return require(path);
@@ -38,23 +36,18 @@ function getRepositories(path) {
38
36
  }
39
37
 
40
38
  const currentRepoPath = path.resolve(process.cwd(), "./repositories.js");
41
- // let cliRepoPath = path.resolve(__dirname, '..', 'repositories.js');
42
39
  let packageJsonPath = path.resolve(process.cwd(), './package.json');
43
- let repoDir, doAllRepo;
40
+ let directory
44
41
 
45
- if (fs.existsSync(config['c'])) {
42
+ if (config['c'] && fs.existsSync(config['c'])) {
46
43
  repos = getRepositories(config['c']);
47
- repoDir = path.dirname(config['c']);
48
- doAllRepo = false;
49
- console.warn(`using ${config['c']} configuration`.yellow);
50
- }
51
- else if (fs.existsSync(currentRepoPath)) {
44
+ directory = path.dirname(config['c']);
45
+ console.warn(`using ${config['c']} configuration`.yellow);
46
+ } else if (!config['self'] && fs.existsSync(currentRepoPath)) {
52
47
  repos = getRepositories(currentRepoPath);
53
- repoDir = path.dirname(currentRepoPath);
54
- doAllRepo = true;
48
+ directory = path.dirname(currentRepoPath);
55
49
  console.warn(`using ${currentRepoPath} configuration`.yellow);
56
- }
57
- else if (fs.existsSync(packageJsonPath)) {
50
+ } else if (fs.existsSync(packageJsonPath)) {
58
51
  let repoPath = path.resolve(process.cwd());
59
52
  let packageObj = require(packageJsonPath);
60
53
  let repoUrl = packageObj.repository.url.substr(12);
@@ -62,53 +55,18 @@ else if (fs.existsSync(packageJsonPath)) {
62
55
  path: `${repoPath}`,
63
56
  repo: `${repoUrl}`
64
57
  }];
65
- repoDir = path.dirname(packageJsonPath);
66
- doAllRepo = false;
58
+ directory = path.dirname(packageJsonPath);
67
59
  console.warn(`using ${packageJsonPath} configuration`.yellow);
68
- }
69
- // else if (fs.existsSync(cliRepoPath)) {
70
-
71
- // repos = getRepositories(cliRepoPath)
72
- // repoDir = path.dirname(cliRepoPath);
73
- // doAllRepo = false;
74
- // console.warn(`using ${cliRepoPath} configuration`.yellow)
75
-
76
- // }
77
- else {
60
+ } else {
78
61
  console.error(`a configuration file can not be found`.red);
79
62
  process.exit(1);
80
63
  }
81
- config = {hideMessage: false, ...config, repoDir, doAllRepo };
82
-
83
- let repoFullMeta = repos.map(meta => {
84
- let name = path.basename(meta.path).toLowerCase();
85
- let plainName = name.substr(9);
86
- let ppath = path.resolve(repoDir, meta.path);
87
- try {
88
- if (!fs.existsSync(ppath))
89
- console.error(`${ppath} not found`.red);
90
-
91
- return { ...meta, name, ppath, plainName };
92
- }
93
- catch (err) {
94
- console.error(name.red, err.message.red, ppath);
95
- // process.exit(1)
96
- }
97
-
98
- });
64
+ config = {hideMessage: false, ...config };
99
65
 
100
66
  (async() => {
101
- if (command == 'bump'){
102
- console.log('bumping')
103
- let predefined = path.resolve(__dirname, 'commands', command + '.js');
104
- require(predefined)(repos, repos )
105
- }
106
- if (command == 'gitConfig'){
107
- let predefined = path.resolve(__dirname, 'commands', command + '.js');
108
- require(predefined)(repos, repos )
109
- }
110
- else {
111
- let failed = await execute(command, repoFullMeta, config);
67
+ repos = await addMeta(repos, [], directory)
68
+ let failed = await execute(command, repos, config);
69
+ if (failed) {
112
70
  if (failed.length === 0)
113
71
  process.exit(0);
114
72
  else {
@@ -118,5 +76,4 @@ let repoFullMeta = repos.map(meta => {
118
76
 
119
77
  }
120
78
  }
121
- // console.log(`success: ${report.success}`.green, `failed: ${report.fail}`.red);
122
79
  })();
@@ -1,126 +1,85 @@
1
-
2
1
  let fs = require('fs');
3
- const prettier = require("prettier");
4
- let list = require('../../../repositories.js');
5
2
  const path = require("path")
6
-
7
- const spawn = require('../spawn');
8
3
  const colors = require('colors');
9
- const addMeta = require('../addMeta');
10
-
11
- let pathList = list.map(o => o.path)
12
- let nameList = pathList.map(fn => path.basename(fn).toLowerCase());
13
- console.log('pathList', pathList)
14
- console.log('pathList', nameList)
15
- let item = {}
16
-
17
- // ToDo: excute using command coc bump. when executed it will check for a repository.js file. same as other commands/
18
- // (async() => {
19
-
20
- // for (let [index, name] of nameList.entries()) {
21
- // getVersions(pathList[index] + '/package.json', name).
22
- // }
23
- // // console.log('bump versions', item)
24
- // // for (let [index, name] of nameList.entries()) {
25
- // // await bumpVersion(pathList[index] + '/package.json', name)
26
- // // }
27
-
28
-
29
- // })();
30
-
31
- // module.exports = async function run() {
32
- // try {
33
- // for (let [index, name] of nameList.entries()) {
34
- // getVersions(pathList[index] + '/package.json', `@${name}`)
35
- // }
36
- // console.log('bump versions', item)
37
-
38
- // for (let [index, name] of nameList.entries()) {
39
- // await bumpVersion(pathList[index] + '/package.json', name)
40
- // }
41
- // } catch (err) {
42
- // failed.push({ name: 'GENERAL', des: err.message })
43
- // }
44
-
45
- // console.log('completed')
46
- // return failed
47
- // // process.exit()
48
- // }
49
-
50
-
51
- async function run() {
52
- // let failed = [];
53
-
54
- // try {
55
- // repos = addMeta(repos, failed)
56
-
57
- // }
58
- // catch (err) {
59
- // failed.push({
60
- // name: 'GENERAL',
61
- // des: err.message
62
- // })
4
+ const util = require('node:util');
5
+ const exec = util.promisify(require('node:child_process').exec);
6
+
7
+
8
+ let pathList, nameList, item = {}, failed = [];
9
+
10
+ module.exports = async function bump(repos) {
11
+ pathList = repos.map(o => o.path)
12
+ if (repos.length === 1) {
13
+ let packageJsonPath = path.resolve(process.cwd(), './package.json');
14
+
15
+ if (fs.existsSync(packageJsonPath)) {
16
+ let object = require(packageJsonPath)
17
+ if (object.dependencies) {
18
+ for (let key of Object.keys(object.dependencies)) {
19
+ if (key.startsWith("@cocreate/")) {
20
+ const version = await exec(`npm view ${key} version`);
21
+ item[key] = `^${version.stdout}`.trim()
22
+ }
23
+ }
24
+ console.log('bump versions', item)
25
+
26
+ for (let name of Object.keys(item)) {
27
+ bumpVersion(packageJsonPath, name)
28
+ }
29
+ }
30
+ }
63
31
 
64
- // }
32
+ } else {
33
+ nameList = pathList.map(fn => path.basename(fn).toLowerCase());
65
34
 
66
- // // console.log(repos)
67
- // // return [];
68
- // for (let repo of repos) {
69
- // await reAdd(repo.deps, repo, failed, '')
70
- // await reAdd(repo.devDeps, repo, failed, '-D ')
71
- // }
72
- // return failed;
35
+ for (let [index, name] of nameList.entries()) {
36
+ getVersions(pathList[index] + '/package.json', `@${name}`)
37
+ }
73
38
 
74
- // }
39
+ console.log('bump versions', item)
75
40
 
76
- for (let [index, name] of nameList.entries()) {
77
- getVersions(pathList[index] + '/package.json', `@${name}`)
78
- }
79
- console.log('bump versions', item)
41
+ for (let [index, name] of nameList.entries()) {
42
+ bumpVersion(pathList[index] + '/package.json', name)
43
+ }
80
44
 
81
- for (let [index, name] of nameList.entries()) {
82
- await bumpVersion(pathList[index] + '/package.json', name)
83
45
  }
84
46
 
85
47
  console.log('completed')
86
- // process.exit()
48
+ return failed;
87
49
  }
88
50
 
89
- function getVersions(path, name) {
90
- if (!fs.existsSync(path))
91
- return console.error('path doesn\'t exist:', path)
92
- let object = require(path)
93
- if (object.name && object.version) {
94
- item[object.name] = `^${object.version}`
51
+ function getVersions(filePath) {
52
+ if (fs.existsSync(filePath)) {
53
+ let object = require(filePath)
54
+ if (object.name && object.version) {
55
+ item[object.name] = `^${object.version}`
56
+ }
57
+ } else {
58
+ failed.push({name: 'get version', des: 'path doesn\'t exist:' + filePath})
95
59
  }
96
60
  }
97
61
 
98
62
  function bumpVersion(filePath, name) {
99
- if (!fs.existsSync(filePath))
100
- return console.error('path doesn\'t exist:', path)
101
63
  let object = require(filePath)
102
- let newObject = {...object}
103
-
104
- if (!object.dependencies)
105
- return console.log(name, 'not updated')
106
- else {
107
- for (const name of Object.keys(object.dependencies)) {
108
- if (item[name]) {
109
- newObject.dependencies[name] = item[name]
64
+ if (object) {
65
+ let newObject = {...object}
66
+
67
+ if (!object.dependencies)
68
+ return console.log(name, 'not updated')
69
+ else {
70
+ for (const name of Object.keys(object.dependencies)) {
71
+ if (item[name]) {
72
+ newObject.dependencies[name] = item[name]
73
+ }
110
74
  }
111
- }
112
-
113
- // let str = JSON.stringify(object, null, 2)
114
- // let formated = prettier.format(str, { semi: false, parser: "json" });
115
75
 
116
- filePath = filePath.replace('/package.json', '')
117
- let Path = path.resolve(filePath, 'package.json')
118
- if (fs.existsSync(Path)){
119
- fs.unlinkSync(Path)
76
+ if (fs.existsSync(filePath)){
77
+ fs.unlinkSync(filePath)
78
+ }
79
+
80
+ fs.writeFileSync(filePath, JSON.stringify(object, null, 2))
120
81
  }
121
-
122
- fs.writeFileSync(Path, JSON.stringify(object, null, 2))
82
+ } else {
83
+ failed.push({name: 'bump version', des: 'path doesn\'t exist:' + filePath})
123
84
  }
124
85
  }
125
-
126
- // run()
@@ -5,22 +5,21 @@ const path = require('path');
5
5
 
6
6
  module.exports = async function gitClone(repos) {
7
7
  const failed = [];
8
- for (let meta of repos) {
9
-
10
- let { repo, path: ppath, name } = meta;
11
- let usernamePrompt = true;
12
-
13
- let dirPath = path.dirname(ppath);
14
- let exitCode = await spawn('mkdir', ['-p', dirPath], { stdio: 'inherit', cwd: process.cwd() })
15
- if (exitCode !== 0) {
16
- failed.push({ name, des: `creating directory failed` })
17
-
18
- }
19
-
20
- exitCode = await spawn('git', ['clone', `https://${repo}`], { stdio: 'inherit', cwd: dirPath })
21
- if (exitCode !== 0) {
22
- failed.push({ name, des: `cloning ${name} failed` })
23
-
8
+ const cwdPath = path.resolve(process.cwd());
9
+
10
+ for (let i = 0; i < repos.length; i++) {
11
+ if (cwdPath !== repos[i].absolutePath) {
12
+ let exitCode = await spawn('mkdir', ['-p', repos[i].directory], { stdio: 'inherit', cwd: process.cwd() })
13
+ if (exitCode !== 0) {
14
+ failed.push({ name: repos[i].name, des: `creating directory failed` })
15
+ }
16
+
17
+ exitCode = await spawn('git', ['clone', `https://${repos[i].repo}`], { stdio: 'inherit', cwd: repos[i].directory })
18
+ if (exitCode !== 0) {
19
+ failed.push({ name: repos[i].name, des: `cloning failed` })
20
+
21
+ }
22
+
24
23
  }
25
24
  }
26
25