cob-cli 2.32.0 → 2.33.1

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,7 +1,7 @@
1
1
  const inquirer = require('inquirer');
2
2
  const colors = require("colors");
3
3
  const path = require("path");
4
- const { checkVersion } = require("./upgradeRepo");
4
+ const { checkRepoVersion } = require("./upgradeRepo");
5
5
  const { checkWorkingCopyCleanliness } = require("../task_lists/common_helpers");
6
6
  const axios = require("axios");
7
7
  const git = require("simple-git");
@@ -16,23 +16,26 @@ const customizationsVersionsFile = "customizations.json";
16
16
  async function customize(filter, args) {
17
17
  try {
18
18
  console.log("Customize...");
19
- if (!args.cache) checkVersion();
20
- if (!args.force && !args.cache) await checkWorkingCopyCleanliness();
21
-
22
- if (args.cache) {
23
- await cacheAllCustomizations(filter, args);
24
-
25
- } else if (args.update) {
26
- await updatePreviouslyAppliedCostumizations(filter, args);
27
-
28
- } else {
29
- const customizationRepo = await getCustomizationRepo(filter, args);
30
- await applyCustomization(customizationRepo, args);
31
-
32
- console.log( colors.green("\nDone"), "\nCheck changes to your git working tree and try:" );
33
- console.log( "\tcob-cli test\n" );
19
+
20
+ if (args.cache && (filter || args.local || args.update)) throw new Error("\nError: ".red + " incompatible options. Use --cache as single argument\n");
21
+ if (args.update && filter ) throw new Error("\nError: ".red + " incompatible options. Use --update without a <filter> \n");
22
+
23
+ if (!args.cache) checkRepoVersion();
24
+ if (!args.cache && !args.force) await checkWorkingCopyCleanliness();
25
+
26
+ const customizations = await getCustomizationsList(filter, args)
27
+ if(!args.local) {
28
+ await downloadCustomizationFiles(customizations,args)
29
+ if(args.cache) {
30
+ console.log( colors.green("\nDone"), " - All configuration were downloaded to your local cache and you can now use the --local flag for any customization" );
31
+ // For --cache argument all work is done, just return
32
+ return
33
+ }
34
34
  }
35
+ await applyCustomizations(customizations)
35
36
 
37
+ console.log( colors.green("\nDone"), "\nCheck changes to your git working tree and try:" );
38
+ console.log( "\tcob-cli test\n" );
36
39
  } catch (err) {
37
40
  console.error("\n", err.message);
38
41
  }
@@ -40,50 +43,7 @@ async function customize(filter, args) {
40
43
  module.exports = customize;
41
44
 
42
45
  /* ************************************************************************ */
43
- async function updatePreviouslyAppliedCostumizations(filter, args) {
44
- if (filter || args.cache) {
45
- throw new Error("\nError: ".red + " incompatible options. Use of --update with filter or --cache.\n");
46
- }
47
- console.log("Updating all installed customizations...");
48
-
49
- let customizationsVersions = {};
50
- if(fs.existsSync(customizationsVersionsFile)) {
51
- const customizationsVersionsRawData = fs.readFileSync(customizationsVersionsFile);
52
- customizationsVersions = JSON.parse(customizationsVersionsRawData);
53
- }
54
-
55
- const customizationRepos = await getCustomizationRepo(null, args);
56
- for (let customizationRepo of customizationRepos) {
57
- if(customizationsVersions[customizationRepo.name]) {
58
- await applyCustomization(customizationRepo, args);
59
- }
60
- }
61
- }
62
-
63
- /* ************************************************************************ */
64
- async function cacheAllCustomizations(filter, args) {
65
- if (filter || args.local || args.update) {
66
- throw new Error("\nError: ".red + " incompatible options. Use --cache as single argument\n");
67
- }
68
-
69
- console.log("Caching all customizations...");
70
- const customizationRepos = await getCustomizationRepo(null, args);
71
- for (let customizationRepo of customizationRepos) {
72
- await downloadCustomizationFiles(customizationRepo);
73
- }
74
-
75
- const { xdgData } = await import("xdg-basedir");
76
- const cacheCustomizationsFile = path.resolve(xdgData, "cob-cli", "customizations.json")
77
- fs.writeFileSync(cacheCustomizationsFile,
78
- JSON.stringify(customizationRepos, null, 2),
79
- (err) => {
80
- if(err) throw new Error("\nError: ".red + " problem writing " + cacheCustomizationsFile + ":", err.message);
81
- }
82
- );
83
- }
84
-
85
- /* ************************************************************************ */
86
- async function getCustomizationRepo(filter, args) {
46
+ async function getCustomizationsList(filter, args) {
87
47
  const { xdgData } = await import("xdg-basedir");
88
48
  const cacheCustomizationsFile = path.resolve(xdgData,"cob-cli","customizations.json")
89
49
 
@@ -100,100 +60,108 @@ async function getCustomizationRepo(filter, args) {
100
60
  customizationRepos = response.data.items
101
61
  }
102
62
 
103
- //If the goal is to cache or update customizations just return all customizations
104
- if (args.cache || args.update) {
105
- return customizationRepos;
106
- }
107
-
108
-
109
63
  // Throw error if there's no customization
110
64
  if (customizationRepos.length == 0) throw new Error("\nError: ".red + " no customization found\n");
65
+
66
+ //Filter customizations according to argument flags
67
+ let relevantRepoNames = [];
111
68
 
112
- // Otherwise asks for customization to apply
113
- let answer = await inquirer.prompt([
114
- {
115
- type: "list",
116
- name: "customization",
117
- message: "What customization do you want to apply?",
118
- choices: customizationRepos.map((customizationRepo) => customizationRepo.name).sort(),
119
- },
120
- ]);
69
+ if (args.update) {
70
+ // If --update then filter is existing customizations
71
+ let customizationsVersions = {};
72
+ if(fs.existsSync(customizationsVersionsFile)) {
73
+ const customizationsVersionsRawData = fs.readFileSync(customizationsVersionsFile);
74
+ customizationsVersions = JSON.parse(customizationsVersionsRawData);
75
+ }
76
+ relevantRepoNames = Object.keys(customizationsVersions)
121
77
 
122
- //Return the full customizationRepo info
123
- return customizationRepos.find((customizationRepo) => customizationRepo.name == answer.customization);
78
+ } else if (!args.cache) {
79
+ // Otherwise, if not --cache, asks for customizations to apply
80
+ let answer = await inquirer.prompt([
81
+ {
82
+ type: "checkbox",
83
+ name: "customizations",
84
+ message: "What customization do you want to apply?",
85
+ choices: customizationRepos.map((customizationRepo) => customizationRepo.name).sort(),
86
+ validate: (answers) => answers.length > 0
87
+ },
88
+ ]);
89
+ relevantRepoNames = answer.customizations
90
+ }
91
+
92
+ //Return the full customizationRepo info for relevant repos
93
+ return customizationRepos
94
+ .sort( (c1, c2) => c1.name > c2.name)
95
+ .filter( customizationRepo => relevantRepoNames.length == 0 || relevantRepoNames.indexOf(customizationRepo.name) >= 0);
124
96
  }
125
97
 
126
98
  /* ************************************************************************ */
127
- async function downloadCustomizationFiles(customizationRepo) {
99
+ async function downloadCustomizationFiles(customizationRepos, args) {
128
100
  const { xdgData } = await import("xdg-basedir");
129
101
  const baseDir = process.cwd();
130
102
  const cacheDir = path.resolve(xdgData,"cob-cli")
131
103
  if (!fs.existsSync(cacheDir)) fs.mkdirSync(cacheDir, { recursive: true });
132
104
 
133
- process.chdir(cacheDir);
134
- if (!fs.existsSync(path.resolve(cacheDir,customizationRepo.name))) {
135
- console.log(" git clone " + customizationRepo.clone_url);
136
- await git().clone(customizationRepo.clone_url);
137
- } else {
138
- console.log(" git pull " + customizationRepo.clone_url);
139
- process.chdir(customizationRepo.name);
140
- try {
141
- await git().pull();
142
- } catch (error) { }
105
+ if(args.cache) {
106
+ const cacheCustomizationsFile = path.resolve(cacheDir, "customizations.json")
107
+ fs.writeFileSync(cacheCustomizationsFile, JSON.stringify(customizationRepos, null, 2), (err) => {
108
+ if(err) throw new Error("\nError: ".red + " problem writing " + cacheCustomizationsFile + ":", err.message);
109
+ }
110
+ );
111
+ }
112
+
113
+ for (const customizationRepo of customizationRepos) {
114
+ process.chdir(cacheDir);
115
+ if (!fs.existsSync(path.resolve(cacheDir,customizationRepo.name))) {
116
+ console.log(" git clone " + customizationRepo.clone_url);
117
+ await git().clone(customizationRepo.clone_url);
118
+
119
+ } else {
120
+ console.log(" git pull " + customizationRepo.clone_url);
121
+ process.chdir(customizationRepo.name);
122
+ try {
123
+ await git().pull();
124
+ } catch (error) { }
125
+ }
143
126
  }
144
127
  process.chdir(baseDir);
128
+
145
129
  }
146
130
 
147
131
  /* ************************************************************************ */
148
- async function applyCustomization(customizationRepo, args) {
149
- console.log("\nApplying " + customizationRepo.name + " customization ...");
150
-
151
- // Get customization info from convention defined file (customize.js)
152
- if (!args.local) await downloadCustomizationFiles(customizationRepo);
132
+ async function applyCustomizations(customizationRepos) {
133
+ console.log("\n Applying " + customizationRepos.map( c => colors.blue(c.name)) + " customization ...");
153
134
 
154
135
  const { xdgData } = await import("xdg-basedir");
155
- const customizationPath = path.resolve( xdgData, "cob-cli", customizationRepo.name);
156
- const customizationFile = path.resolve( customizationPath, "customize.js");
157
- if (!fs.existsSync(customizationFile))
158
- throw new Error("\nError: ".red + " no customize.js file found\n");
136
+ for (let customizationRepo of customizationRepos) {
137
+ const customizationDir = path.resolve( xdgData, "cob-cli", customizationRepo.name);
138
+ const customizationFile = path.resolve( customizationDir, "customize.js");
139
+ if (!fs.existsSync(customizationFile)) throw new Error("\nError: ".red + " no customize.js file found\n");
159
140
 
160
- let customization = (await import(customizationFile)).default;
141
+ let customization = (await import(customizationFile)).default;
161
142
 
162
- // Asks questions, if configuration exists
163
- let answers = {};
164
- if (customization.questions) {
165
- answers = await inquirer.prompt(customization.questions);
166
- }
143
+ // Asks questions, if question configuration exists
144
+ let answers = {};
145
+ if (customization.questions) {
146
+ answers = await inquirer.prompt(customization.questions);
147
+ }
167
148
 
168
- // Apply specific customization, if it exists, otherwise use default actions
169
- if (customization.actions) {
170
- customization.actions(customizationRepo.name, answers, copyAndMerge);
171
- } else {
172
- // Default actions
173
- await copyAndMerge(customizationRepo.name, answers);
174
- }
149
+ // Apply specific customization, if actions exist, otherwise use default actions
150
+ if (customization.actions) {
151
+ customization.actions(customizationRepo.name, answers, copyAndMerge);
152
+ } else {
153
+ // Default actions
154
+ await copyAndMerge(customizationRepo.name, customizationDir, answers);
155
+ }
175
156
 
176
- // Update customizations.json file
177
- updateCustomizationsVersions(customizationRepo.name, customization.version);
157
+ // Update customizations.json file
158
+ updateCustomizationsVersions(customizationRepo.name, customization.version);
159
+ }
178
160
  }
179
161
 
180
162
  /* ************************************************************************ */
181
- async function copyAndMerge(customizationRepoName, substitutions = {}) {
182
- // https://www.npmtrends.com/copyfiles-vs-cpx-vs-ncp-vs-npm-build-tools
183
- // https://www.npmjs.com/package/ncp
184
- // https://www.npmjs.com/package/copyfiles
185
-
186
- let source
187
- if(customizationRepoName.indexOf("/") == 0) {
188
- // Based of customizationRepoName starting with "/" we assume this is already a fullpath
189
- source = customizationRepoName;
190
- } else {
191
- // Otherwise assume customizationRepoName on standard cob-cli xdgData path
192
- const { xdgData } = await import("xdg-basedir");
193
- source = path.resolve( xdgData, "cob-cli", customizationRepoName);
194
- }
195
-
196
- console.log(" Copying template files ...");
163
+ async function copyAndMerge(customizationRepoName, source, substitutions = {}) {
164
+ console.log("\n Copying template files for " + colors.blue(customizationRepoName) + "...");
197
165
 
198
166
  let excludedFiles = RegExp(
199
167
  "(" +
@@ -3,11 +3,11 @@ const { getCurrentCommandEnviroment } = require("../task_lists/common_enviroment
3
3
  const { confirmExecutionOfChanges } = require("../task_lists/common_syncFiles");
4
4
  const { validateDeployConditions } = require("../task_lists/deploy_validate");
5
5
  const { executeTasks } = require("../task_lists/deploy_execute");
6
- const { checkVersion } = require("../commands/upgradeRepo");
6
+ const { checkRepoVersion } = require("../commands/upgradeRepo");
7
7
 
8
8
  async function deploy(args) {
9
9
  try {
10
- checkVersion()
10
+ checkRepoVersion()
11
11
  const cmdEnv = await getCurrentCommandEnviroment(args)
12
12
  if(args.resync) args.force = true;
13
13
 
@@ -5,13 +5,13 @@ const { customUIsContinuosReload } = require("../task_lists/test_customUIsContin
5
5
  const { otherFilesContiousReload } = require("../task_lists/test_otherFilesContiousReload");
6
6
  const { getCurrentCommandEnviroment } = require("../task_lists/common_enviromentHandler");
7
7
  const { getKeypress } = require("../task_lists/common_helpers");
8
- const { checkVersion } = require("../commands/upgradeRepo");
8
+ const { checkRepoVersion } = require("../commands/upgradeRepo");
9
9
 
10
10
  async function test (args) {
11
11
  let restoreChanges, error = "";
12
12
  let cmdEnv
13
13
  try {
14
- checkVersion()
14
+ checkRepoVersion()
15
15
  console.log("Start testing… ")
16
16
  cmdEnv = await getCurrentCommandEnviroment(args)
17
17
 
@@ -2,11 +2,11 @@ require('colors');
2
2
  const { getCurrentCommandEnviroment } = require("../task_lists/common_enviromentHandler");
3
3
  const { copyFiles } = require("../task_lists/common_syncFiles");
4
4
  const { validateUpdateFromServerConditions } = require("../task_lists/updateFromServer_validate");
5
- const { checkVersion } = require("../commands/upgradeRepo");
5
+ const { checkRepoVersion } = require("../commands/upgradeRepo");
6
6
 
7
7
  async function updateFromServer(args) {
8
8
  try {
9
- checkVersion()
9
+ checkRepoVersion()
10
10
  const cmdEnv = await getCurrentCommandEnviroment(args)
11
11
 
12
12
  await validateUpdateFromServerConditions(cmdEnv).run()
@@ -36,7 +36,7 @@ async function upgradeRepo() {
36
36
  exports.upgradeRepo = upgradeRepo;
37
37
 
38
38
  /* ************************************ */
39
- function checkVersion() {
39
+ function checkRepoVersion() {
40
40
  let repoVersion = _getRepoVersion();
41
41
  if(repoVersion == 9999 ) {
42
42
  throw new Error("Error:".red + " not on a root of a cob-cli repo. Check your path. \n")
@@ -50,7 +50,7 @@ function checkVersion() {
50
50
  throw new Error("Error:".red + " your cob-cli repo is outdated. Run " + "cob-cli upgradeRepo".bold.blue + "\n")
51
51
  }
52
52
  }
53
- exports.checkVersion = checkVersion;
53
+ exports.checkRepoVersion = checkRepoVersion;
54
54
 
55
55
  /* ************************************ */
56
56
  function setVersion() {
@@ -23,21 +23,12 @@ module.exports = env => {
23
23
  hot:false,
24
24
  port: 8040,
25
25
  host: "0.0.0.0",
26
- devMiddleware: {
27
- stats: {
28
- maxModules: 0 // Set the maximum number of modules to be shown
29
- }
30
- },
31
26
  setupMiddlewares: (middlewares, devServer) => {
32
- middlewares.push({
33
- name: 'hello-world-test-one',
34
- // `path` is optional
35
- path: '*',
27
+ middlewares.unshift({
28
+ name: 'redirect-localhost:8080/-to-localhost:8080/record/',
36
29
  middleware: (req, res, next) => {
37
30
  // Permite usar / ou /DASH_BOARD/ quando acedido directamente
38
- if(req.url != "/") {
39
- return next();
40
- }
31
+ if(req.url != "/") return next();
41
32
  res.redirect(`/recordm/`);
42
33
  },
43
34
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cob-cli",
3
- "version": "2.32.0",
3
+ "version": "2.33.1",
4
4
  "description": "A command line utility to help Cult of Bits partners develop with higher speed and reusing common code and best practices.",
5
5
  "preferGlobal": true,
6
6
  "repository": {