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 {
|
|
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
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
{
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
123
|
-
|
|
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(
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
|
149
|
-
console.log("\
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
141
|
+
let customization = (await import(customizationFile)).default;
|
|
161
142
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
177
|
-
|
|
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
|
-
|
|
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
|
"(" +
|
package/lib/commands/deploy.js
CHANGED
|
@@ -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 {
|
|
6
|
+
const { checkRepoVersion } = require("../commands/upgradeRepo");
|
|
7
7
|
|
|
8
8
|
async function deploy(args) {
|
|
9
9
|
try {
|
|
10
|
-
|
|
10
|
+
checkRepoVersion()
|
|
11
11
|
const cmdEnv = await getCurrentCommandEnviroment(args)
|
|
12
12
|
if(args.resync) args.force = true;
|
|
13
13
|
|
package/lib/commands/test.js
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
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 {
|
|
5
|
+
const { checkRepoVersion } = require("../commands/upgradeRepo");
|
|
6
6
|
|
|
7
7
|
async function updateFromServer(args) {
|
|
8
8
|
try {
|
|
9
|
-
|
|
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
|
|
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.
|
|
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.
|
|
33
|
-
name: '
|
|
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