@nzz/q-cli 2.0.0-beta.10 → 2.0.0-beta.14
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/dist/createCustomCodeItem.js +5 -1
- package/dist/enums.js +1 -0
- package/dist/index.js +4 -34
- package/dist/updateItem.js +53 -9
- package/package.json +2 -2
@@ -15,7 +15,11 @@ export default function (command) {
|
|
15
15
|
const qConfigPath = resolve(command.config);
|
16
16
|
if (!existsSync(qConfigPath)) {
|
17
17
|
logError(`Couldn't find config file: '${qConfigPath}'.\nCreate a config file in the current directory or pass the path to the config file with the option -c <path>`);
|
18
|
-
|
18
|
+
process.exit(1);
|
19
|
+
}
|
20
|
+
if (!command.environment) {
|
21
|
+
logError('Environment is required');
|
22
|
+
process.exit(1);
|
19
23
|
}
|
20
24
|
// Get the Q server URL and access token from the environment variables or 1Password
|
21
25
|
const qServerUrl = getQServerUrl(command.environment);
|
package/dist/enums.js
CHANGED
package/dist/index.js
CHANGED
@@ -21,34 +21,12 @@ function main() {
|
|
21
21
|
program.version(version).description('Q Toolbox cli');
|
22
22
|
program
|
23
23
|
.command('new-custom-code')
|
24
|
-
.
|
24
|
+
.argument('<path>', 'the base directory to bootstrap the new custom code project in')
|
25
25
|
.description('bootstrap a new custom code project')
|
26
|
-
.action((
|
27
|
-
|
26
|
+
.action(() => {
|
27
|
+
const dir = program.args[1];
|
28
|
+
newCustomCode({ dir });
|
28
29
|
});
|
29
|
-
program
|
30
|
-
.command('new-et-utils-package')
|
31
|
-
.option('-d, --dir [path]', 'the base directory to bootstrap the new tool in, defaults to the tools name')
|
32
|
-
.description('bootstrap a new ed-tech utility package')
|
33
|
-
.action(() => __awaiter(this, void 0, void 0, function* () {
|
34
|
-
// const name = program.args[1];
|
35
|
-
// const author = program.args[2] || 'TODO: Set package author name';
|
36
|
-
// const description = program.args[3] || 'TODO: Write a package description';
|
37
|
-
// if (!name) {
|
38
|
-
// console.error(errorColor('no package name given'));
|
39
|
-
// process.exit(1);
|
40
|
-
// }
|
41
|
-
// const baseDir = program.dir || name;
|
42
|
-
// const textReplacements = [
|
43
|
-
// { regex: new RegExp('<package-name>', 'g'), replaceWith: name },
|
44
|
-
// { regex: new RegExp('<author-name>', 'g'), replaceWith: author },
|
45
|
-
// {
|
46
|
-
// regex: new RegExp('<package-description>', 'g'),
|
47
|
-
// replaceWith: description,
|
48
|
-
// },
|
49
|
-
// ];
|
50
|
-
// await bootstrap('et-utils-package', baseDir, textReplacements);
|
51
|
-
}));
|
52
30
|
program
|
53
31
|
.command('update-item')
|
54
32
|
.description('update q item')
|
@@ -57,14 +35,6 @@ function main() {
|
|
57
35
|
.action((command) => __awaiter(this, void 0, void 0, function* () {
|
58
36
|
yield updateItem(command);
|
59
37
|
}));
|
60
|
-
program
|
61
|
-
.command('copy-item')
|
62
|
-
.description('copies an existing q item')
|
63
|
-
.option('-c, --config [path]', 'set config path which defines the q items to be copied. defaults to ./q.config.json', `${process.cwd()}/q.config.json`)
|
64
|
-
.option('-e, --environment [env]', 'set environment where the existing q item is found, defaults to copy all items of all environments defined in config')
|
65
|
-
.action((command) => __awaiter(this, void 0, void 0, function* () {
|
66
|
-
// await copyItem(command);
|
67
|
-
}));
|
68
38
|
program
|
69
39
|
.command('create-custom-code-item')
|
70
40
|
.description('creates a new q custom code item in the db and adds it to the q config file')
|
package/dist/updateItem.js
CHANGED
@@ -14,6 +14,39 @@ import FormData from 'form-data';
|
|
14
14
|
import fetch from 'node-fetch'; // Use node-fetch instead of native fetch, because native fetch seems to have issues with FormData/uploading files
|
15
15
|
import { getAccessToken, getQServerUrl, logError, logSuccess, updateItem } from './utils.js';
|
16
16
|
import updateSchemaJson from './assets/updateSchema.json' with { type: 'json' };
|
17
|
+
import { Environment } from './enums.js';
|
18
|
+
const envCredentials = {
|
19
|
+
[Environment.LOCAL]: {
|
20
|
+
qServerUrl: '',
|
21
|
+
accessToken: '',
|
22
|
+
},
|
23
|
+
[Environment.TEST]: {
|
24
|
+
qServerUrl: '',
|
25
|
+
accessToken: '',
|
26
|
+
},
|
27
|
+
[Environment.STAGING]: {
|
28
|
+
qServerUrl: '',
|
29
|
+
accessToken: '',
|
30
|
+
},
|
31
|
+
[Environment.PRODUCTION]: {
|
32
|
+
qServerUrl: '',
|
33
|
+
accessToken: '',
|
34
|
+
},
|
35
|
+
};
|
36
|
+
/**
|
37
|
+
* Get the Q server URL and access token from the environment variables or 1Password
|
38
|
+
* @param environment The environment to get the credentials for
|
39
|
+
* @returns The Q server URL and access token
|
40
|
+
*/
|
41
|
+
function getEnvCredentials(environment) {
|
42
|
+
if (envCredentials[environment].qServerUrl === '' || envCredentials[environment].accessToken === '') {
|
43
|
+
envCredentials[environment] = {
|
44
|
+
qServerUrl: getQServerUrl(environment),
|
45
|
+
accessToken: getAccessToken(environment),
|
46
|
+
};
|
47
|
+
}
|
48
|
+
return envCredentials[environment];
|
49
|
+
}
|
17
50
|
function validateConfig(metaSchema, qConfig) {
|
18
51
|
const ajv = new Ajv({ allErrors: true });
|
19
52
|
let isValid = true;
|
@@ -107,16 +140,27 @@ export default function (command) {
|
|
107
140
|
logError(`A problem occurred while validating the config file: ${validationResult.errorsText}`);
|
108
141
|
process.exit(1);
|
109
142
|
}
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
console.log(`Updating items on server ${qServerUrl}...`);
|
143
|
+
let qServerUrl;
|
144
|
+
let accessToken;
|
145
|
+
let environmentToUpdate;
|
114
146
|
for (const item of qConfig.items) {
|
115
147
|
for (const environment of item.environments) {
|
116
|
-
//
|
117
|
-
if (command.environment
|
118
|
-
|
119
|
-
|
148
|
+
// If the environment is specified, use that environment
|
149
|
+
if (command.environment) {
|
150
|
+
// Skip if the environment is not the one we want to update
|
151
|
+
if (command.environment !== environment.name)
|
152
|
+
continue;
|
153
|
+
environmentToUpdate = command.environment;
|
154
|
+
}
|
155
|
+
else {
|
156
|
+
// Otherwise, use the environment from the config
|
157
|
+
environmentToUpdate = environment.name;
|
158
|
+
}
|
159
|
+
// Get the credentials for the current environment
|
160
|
+
const credentials = getEnvCredentials(environmentToUpdate);
|
161
|
+
qServerUrl = credentials.qServerUrl;
|
162
|
+
accessToken = credentials.accessToken;
|
163
|
+
console.log(`Updating item ${environment.id} on ${environmentToUpdate} environment (${qServerUrl})...`);
|
120
164
|
let qDoc = structuredClone(item.item);
|
121
165
|
qDoc._id = environment.id;
|
122
166
|
// Process the 'path' properties and upload files
|
@@ -128,7 +172,7 @@ export default function (command) {
|
|
128
172
|
// Update the item on the Q server
|
129
173
|
const result = yield updateItem(qDoc, qServerUrl, accessToken);
|
130
174
|
if (result.success) {
|
131
|
-
logSuccess(`Successfully updated item with id ${environment.id} on ${
|
175
|
+
logSuccess(`Successfully updated item with id ${environment.id} on ${environmentToUpdate} environment`);
|
132
176
|
}
|
133
177
|
else {
|
134
178
|
logError(result.msg);
|
package/package.json
CHANGED