@nzz/q-cli 1.9.2 → 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +9 -5
- package/skeletons/custom-code-skeleton/package.json +4 -2
- package/skeletons/custom-code-skeleton/rollup.config.js +59 -52
- package/skeletons/custom-code-skeleton/src/enums.ts +0 -0
- package/skeletons/custom-code-skeleton/src/main-prod.ts +2 -2
- package/skeletons/custom-code-skeleton/src/main.scss +1 -1
- package/skeletons/custom-code-skeleton/src/main.ts +6 -6
- package/skeletons/custom-code-skeleton/tsconfig.json +2 -1
- package/.history/bin/commands/qItem/itemService_20220627113036.js +0 -302
- package/.history/bin/commands/qItem/itemService_20221105174223.js +0 -304
- package/.history/bin/commands/qItem/itemService_20221105174236.js +0 -304
- package/.history/bin/commands/qItem/itemService_20221105174311.js +0 -304
- package/.history/bin/commands/qItem/itemService_20221105174605.js +0 -306
- package/.history/bin/commands/qItem/itemService_20221105174809.js +0 -309
- package/.history/bin/commands/qItem/itemService_20221107071956.js +0 -317
- package/.history/bin/commands/qItem/itemService_20221107072130.js +0 -310
- package/.history/bin/commands/qItem/itemService_20221107072222.js +0 -312
- package/.history/bin/commands/qItem/itemService_20221107072621.js +0 -316
- package/.history/bin/commands/qItem/itemService_20221107072850.js +0 -315
- package/.history/bin/commands/qItem/itemService_20221107073051.js +0 -315
- package/.history/bin/commands/qItem/itemService_20221107073244.js +0 -315
- package/.history/bin/commands/qItem/itemService_20221107075352.js +0 -323
- package/.history/bin/commands/qItem/itemService_20221107075536.js +0 -316
- package/.history/bin/commands/qItem/itemService_20221107075700.js +0 -312
- package/.history/bin/commands/qItem/itemService_20221107111951.js +0 -312
- package/.history/bin/commands/qItem/itemService_20221107113745.js +0 -310
- package/.history/bin/commands/qItem/itemService_20221107113901.js +0 -310
- package/.history/bin/commands/qItem/updateItem/updateItem_20220627113036.js +0 -64
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105173137.js +0 -66
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105173239.js +0 -68
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105173610.js +0 -69
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105173646.js +0 -74
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105174010.js +0 -74
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105174054.js +0 -75
- package/.history/package_20220808135115.json +0 -43
- package/.history/package_20221105171707.json +0 -43
- package/.history/package_20221105173355.json +0 -43
- package/.history/package_20221107112303.json +0 -43
package/package.json
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nzz/q-cli",
|
3
|
-
"version": "1.9.
|
3
|
+
"version": "1.9.3",
|
4
|
+
"prettier": "@nzz/et-utils-config-prettier",
|
4
5
|
"description": "Cli tool to setup new Q tools, new Q server implementations and start Q dev server to test developing Q tools",
|
5
6
|
"main": "index.js",
|
6
7
|
"scripts": {
|
@@ -21,7 +22,7 @@
|
|
21
22
|
"homepage": "https://github.com/nzzdev/Q-cli#readme",
|
22
23
|
"dependencies": {
|
23
24
|
"@hapi/boom": "^9.1.1",
|
24
|
-
"@hapi/hapi": "^20.
|
25
|
+
"@hapi/hapi": "^20.3.0",
|
25
26
|
"@hapi/inert": "^6.0.3",
|
26
27
|
"@hapi/mimos": "^5.0.0",
|
27
28
|
"@hapi/vision": "^6.1.0",
|
@@ -30,14 +31,17 @@
|
|
30
31
|
"chalk": "^4.1.1",
|
31
32
|
"commander": "^5.1.0",
|
32
33
|
"configstore": "^5.0.1",
|
33
|
-
"deepmerge": "^4.
|
34
|
+
"deepmerge": "^4.3.1",
|
34
35
|
"form-data": "^3.0.0",
|
35
36
|
"fs-extra": "^9.0.1",
|
36
37
|
"image-size": "^0.8.3",
|
37
|
-
"joi": "^17.
|
38
|
-
"node-fetch": "^2.6.
|
38
|
+
"joi": "^17.9.1",
|
39
|
+
"node-fetch": "^2.6.9",
|
39
40
|
"nunjucks": "^3.2.2",
|
40
41
|
"promptly": "^3.2.0",
|
41
42
|
"replace-in-file": "^3.4.4"
|
43
|
+
},
|
44
|
+
"devDependencies": {
|
45
|
+
"@nzz/et-utils-config-prettier": "^1.0.6"
|
42
46
|
}
|
43
47
|
}
|
@@ -1,7 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "custom-code-skeleton",
|
3
3
|
"version": "1.0.0",
|
4
|
+
"prettier": "@nzz/et-utils-config-prettier",
|
4
5
|
"devDependencies": {
|
6
|
+
"@nzz/et-utils-config-prettier": "^1.0.6",
|
5
7
|
"@nzz/nzz.ch-static": "github:nzzdev/ed-tech-nzz.ch-static#v1.0.0",
|
6
8
|
"@nzz/q-cli": "^1.4.11",
|
7
9
|
"@rollup/plugin-alias": "^3.1.9",
|
@@ -23,7 +25,7 @@
|
|
23
25
|
"rollup-plugin-terser": "^7.0.2",
|
24
26
|
"sass": "^1.43.4",
|
25
27
|
"sirv-cli": "^1.0.12",
|
26
|
-
"svelte": "^3.
|
28
|
+
"svelte": "^3.57.0",
|
27
29
|
"svelte-preprocess": "^4.10.7",
|
28
30
|
"typescript": "^4.6.4"
|
29
31
|
},
|
@@ -40,4 +42,4 @@
|
|
40
42
|
"rollup": "rollup -c -w",
|
41
43
|
"serve": "sirv public --dev --port 5555 --host 0.0.0.0"
|
42
44
|
}
|
43
|
-
}
|
45
|
+
}
|
@@ -1,22 +1,28 @@
|
|
1
|
-
import * as fs from
|
2
|
-
import * as path from
|
3
|
-
import nodeResolve from
|
4
|
-
import commonjs from
|
5
|
-
import json from
|
6
|
-
import html from
|
7
|
-
import svelte from
|
8
|
-
import { terser } from
|
9
|
-
import livereload from
|
10
|
-
import scss from
|
11
|
-
import postcss from
|
12
|
-
import cssnano from
|
13
|
-
import autoprefixer from
|
14
|
-
import qConfig from
|
1
|
+
import * as fs from 'fs';
|
2
|
+
import * as path from 'path';
|
3
|
+
import nodeResolve from '@rollup/plugin-node-resolve';
|
4
|
+
import commonjs from '@rollup/plugin-commonjs';
|
5
|
+
import json from '@rollup/plugin-json';
|
6
|
+
import html from '@rollup/plugin-html';
|
7
|
+
import svelte from 'rollup-plugin-svelte';
|
8
|
+
import { terser } from 'rollup-plugin-terser';
|
9
|
+
import livereload from 'rollup-plugin-livereload';
|
10
|
+
import scss from 'rollup-plugin-scss';
|
11
|
+
import postcss from 'postcss';
|
12
|
+
import cssnano from 'cssnano';
|
13
|
+
import autoprefixer from 'autoprefixer';
|
14
|
+
import qConfig from './q.config.json';
|
15
15
|
import typescript from '@rollup/plugin-typescript';
|
16
16
|
import image from '@rollup/plugin-image';
|
17
17
|
import alias from '@rollup/plugin-alias';
|
18
18
|
import sveltePreprocess from 'svelte-preprocess';
|
19
|
-
import {
|
19
|
+
import {
|
20
|
+
createContentWidthQElement,
|
21
|
+
createFullwidthQElement,
|
22
|
+
getHtml,
|
23
|
+
createSubtitle,
|
24
|
+
createParagraph,
|
25
|
+
} from '@nzz/nzz.ch-static';
|
20
26
|
|
21
27
|
// Which nzz layout to use?
|
22
28
|
const LAYOUT = process.env.LAYOUT;
|
@@ -29,10 +35,10 @@ function getOutputConfigs() {
|
|
29
35
|
const outputConfigs = [];
|
30
36
|
for (let item of qConfig.items) {
|
31
37
|
for (let environment of item.environments) {
|
32
|
-
if (environment.id !==
|
38
|
+
if (environment.id !== '') {
|
33
39
|
outputConfigs.push({
|
34
40
|
sourcemap: production ? false : true,
|
35
|
-
format:
|
41
|
+
format: 'iife',
|
36
42
|
name: `window._q_custom_code_${environment.id}.App`,
|
37
43
|
file: `public/bundle-${environment.id}.js`,
|
38
44
|
});
|
@@ -45,40 +51,40 @@ function getOutputConfigs() {
|
|
45
51
|
|
46
52
|
function getHtmlOptions() {
|
47
53
|
return {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
fileName: 'index.html',
|
55
|
+
template: function (options) {
|
56
|
+
return getHtml({
|
57
|
+
// These 3 options are the most important. Without them the static website will not function.
|
58
|
+
layout: LAYOUT, // Type of layout.
|
59
|
+
builtCssFilename, // Will be appended at the end of <head>.
|
60
|
+
builtJsFilename: options.files.js[0].fileName, // Will appended to the end of <body>.
|
61
|
+
|
62
|
+
// Create mock elements to simulate your article.
|
63
|
+
content: `
|
58
64
|
${createSubtitle('Test Subtitle')}
|
59
65
|
${createParagraph('Test paragraph')}
|
60
66
|
${createFullwidthQElement('custom-code-fw')}
|
61
67
|
${createContentWidthQElement('custom-code-cw')}
|
62
68
|
`,
|
63
69
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
// Other options.
|
71
|
+
author: 'Max Musterman',
|
72
|
+
lead: 'Test lead.',
|
73
|
+
title: 'Test title',
|
74
|
+
|
75
|
+
// Links to other css files that need to be loaded.
|
76
|
+
// Will be appended to <head> but before the bundled css file of your app.
|
77
|
+
customCssLinks: [
|
78
|
+
'https://service.sophie.nzz.ch/bundle/sophie-q@^1,sophie-input@^1,sophie-font@^1,sophie-color@^1,sophie-viz-color@^1,sophie-legend@^1.css',
|
79
|
+
],
|
80
|
+
|
81
|
+
// Links to other js filed that need to be loaded.
|
82
|
+
// Will be appended at the end of the body, but before the built js file for the app.
|
83
|
+
customJsLinks: [
|
84
|
+
'https://cdn.polyfill.io/v2/polyfill.min.js?features=Map,URL,Promise,fetch,URLSearchParams,Array.prototype.find,Array.prototype.findIndex,Object.entries,Array.prototype.includes,CustomEvent,Array.from,String.prototype.startsWith&flags=gated&unknown=polyfill',
|
85
|
+
],
|
86
|
+
});
|
87
|
+
},
|
82
88
|
};
|
83
89
|
}
|
84
90
|
|
@@ -94,7 +100,7 @@ function getPostcssPlugins(isProduction) {
|
|
94
100
|
|
95
101
|
function createOutputCssFunction() {
|
96
102
|
const outputCssFunction = (styles, styleNodes) => {
|
97
|
-
const publicDir =
|
103
|
+
const publicDir = 'public';
|
98
104
|
|
99
105
|
if (!fs.existsSync(publicDir)) {
|
100
106
|
fs.mkdirSync(publicDir);
|
@@ -108,14 +114,14 @@ function createOutputCssFunction() {
|
|
108
114
|
|
109
115
|
function getSassConfig(isProduction) {
|
110
116
|
const config = {
|
111
|
-
outputStyle: isProduction ?
|
117
|
+
outputStyle: isProduction ? 'compressed' : 'expanded',
|
112
118
|
// Sourcemap generation (specifically writing the file to system) is currently not supported by rollup-plugin-sass (but soon!)
|
113
119
|
// See: https://github.com/thgh/rollup-plugin-scss/issues/7
|
114
120
|
// outFile: path.join(__dirname, "/public/default.css"), // <- Uncomment after: https://github.com/thgh/rollup-plugin-scss/issues/7
|
115
121
|
sourceMap: !isProduction,
|
116
122
|
sourceMapEmbed: !isProduction, // Remove after: https://github.com/thgh/rollup-plugin-scss/issues/7
|
117
123
|
failOnError: !isProduction,
|
118
|
-
watch: [path.join(__dirname,
|
124
|
+
watch: [path.join(__dirname, '/src')],
|
119
125
|
processor: (css) =>
|
120
126
|
postcss(getPostcssPlugins(isProduction))
|
121
127
|
.process(css, {
|
@@ -131,14 +137,15 @@ function getSassConfig(isProduction) {
|
|
131
137
|
}
|
132
138
|
|
133
139
|
export default {
|
134
|
-
input: production ?
|
140
|
+
input: production ? 'src/main-prod.ts' : 'src/main.ts',
|
135
141
|
output: getOutputConfigs(),
|
136
142
|
plugins: [
|
137
143
|
alias({
|
138
144
|
entries: [
|
139
145
|
{ find: '@src', replacement: path.resolve(projectRootDir, 'src') },
|
140
146
|
{ find: '@interfaces', replacement: path.resolve(projectRootDir, 'src/interfaces.ts') },
|
141
|
-
|
147
|
+
{ find: '@enums', replacement: path.resolve(projectRootDir, 'src/enums.ts') },
|
148
|
+
],
|
142
149
|
}),
|
143
150
|
|
144
151
|
typescript({ sourceMap: !production }),
|
@@ -171,14 +178,14 @@ export default {
|
|
171
178
|
|
172
179
|
// Watch the `public` directory and refresh the
|
173
180
|
// browser on changes when not in production
|
174
|
-
!production && livereload({ watch: [
|
181
|
+
!production && livereload({ watch: ['public'], delay: 800 }),
|
175
182
|
production && terser(),
|
176
183
|
],
|
177
184
|
watch: {
|
178
185
|
clearScreen: false,
|
179
186
|
},
|
180
187
|
onwarn: function (warning, warn) {
|
181
|
-
if (warning.code ===
|
188
|
+
if (warning.code === 'CIRCULAR_DEPENDENCY') return;
|
182
189
|
warn(warning);
|
183
190
|
},
|
184
191
|
};
|
File without changes
|
@@ -1 +1 @@
|
|
1
|
-
@use
|
1
|
+
@use 'App.scss';
|
@@ -1,17 +1,17 @@
|
|
1
|
-
import App from
|
2
|
-
import
|
1
|
+
import App from './App.svelte';
|
2
|
+
import './main.scss';
|
3
3
|
|
4
4
|
const app = new App({
|
5
|
-
target: document.querySelector(
|
5
|
+
target: document.querySelector('#custom-code-fw'),
|
6
6
|
props: {
|
7
|
-
name:
|
7
|
+
name: 'custom-code-skeleton - Fullwidth',
|
8
8
|
},
|
9
9
|
});
|
10
10
|
|
11
11
|
new App({
|
12
|
-
target: document.querySelector(
|
12
|
+
target: document.querySelector('#custom-code-cw'),
|
13
13
|
props: {
|
14
|
-
name:
|
14
|
+
name: 'custom-code-skeleton - Content Width',
|
15
15
|
},
|
16
16
|
});
|
17
17
|
|
@@ -1,302 +0,0 @@
|
|
1
|
-
const resourcesService = require("./resourcesService.js");
|
2
|
-
const schemaService = require("./schemaService.js");
|
3
|
-
const deepmerge = require("deepmerge");
|
4
|
-
const fetch = require("node-fetch");
|
5
|
-
const chalk = require("chalk");
|
6
|
-
const errorColor = chalk.red;
|
7
|
-
|
8
|
-
async function createItem(item, environment, config) {
|
9
|
-
const qServer = config.get(`${environment.name}.qServer`);
|
10
|
-
const accessToken = config.get(`${environment.name}.accessToken`);
|
11
|
-
const cookie = config.get(`${environment.name}.cookie`);
|
12
|
-
|
13
|
-
try {
|
14
|
-
const response = await fetch(`${qServer}item`, {
|
15
|
-
method: "POST",
|
16
|
-
body: JSON.stringify(item),
|
17
|
-
headers: {
|
18
|
-
"user-agent": "Q Command-line Tool",
|
19
|
-
Authorization: `Bearer ${accessToken}`,
|
20
|
-
"Content-Type": "application/json",
|
21
|
-
Cookie: cookie ? cookie : "",
|
22
|
-
},
|
23
|
-
});
|
24
|
-
if (response.ok) {
|
25
|
-
return await response.json();
|
26
|
-
} else {
|
27
|
-
throw new Error(
|
28
|
-
`A problem occured while creating item on ${environment.name} environment. Please check your connection and try again.`
|
29
|
-
);
|
30
|
-
}
|
31
|
-
} catch (error) {
|
32
|
-
console.error(errorColor(error.message));
|
33
|
-
process.exit(1);
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
async function getItem(qServer, environment, accessToken, cookie) {
|
38
|
-
try {
|
39
|
-
const response = await fetch(`${qServer}item/${environment.id}`, {
|
40
|
-
headers: {
|
41
|
-
"user-agent": "Q Command-line Tool",
|
42
|
-
Authorization: `Bearer ${accessToken}`,
|
43
|
-
Cookie: cookie ? cookie : "",
|
44
|
-
},
|
45
|
-
});
|
46
|
-
if (response.ok) {
|
47
|
-
return await response.json();
|
48
|
-
} else {
|
49
|
-
throw new Error(
|
50
|
-
`A problem occured while getting item with id ${environment.id} on ${environment.name} environment. Please make sure that the id is correct, you have an internet connection and try again.`
|
51
|
-
);
|
52
|
-
}
|
53
|
-
} catch (error) {
|
54
|
-
console.error(errorColor(error.message));
|
55
|
-
process.exit(1);
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
function getItems(qConfig, environmentFilter) {
|
60
|
-
const items = qConfig.items
|
61
|
-
.filter((item) => {
|
62
|
-
if (environmentFilter) {
|
63
|
-
return item.environments.some(
|
64
|
-
(environment) => environment.name === environmentFilter
|
65
|
-
);
|
66
|
-
}
|
67
|
-
|
68
|
-
return true;
|
69
|
-
})
|
70
|
-
.map((item) => {
|
71
|
-
if (environmentFilter) {
|
72
|
-
item.environments = item.environments.filter(
|
73
|
-
(environment) => environment.name === environmentFilter
|
74
|
-
);
|
75
|
-
}
|
76
|
-
|
77
|
-
return item;
|
78
|
-
});
|
79
|
-
|
80
|
-
return items;
|
81
|
-
}
|
82
|
-
|
83
|
-
function getDefaultOrNull(schema) {
|
84
|
-
if (schema.hasOwnProperty("default")) {
|
85
|
-
if (typeof schema.default === "object") {
|
86
|
-
return JSON.parse(JSON.stringify(schema.default));
|
87
|
-
}
|
88
|
-
return schema.default;
|
89
|
-
}
|
90
|
-
return null;
|
91
|
-
}
|
92
|
-
|
93
|
-
// Returns a default item based on the tool schema
|
94
|
-
// The default item is used to derive the file properties of a certain file type
|
95
|
-
// These file properties are specified by the tool and are specific to the file type
|
96
|
-
// For example an image file has height/width file properties
|
97
|
-
function getDefaultItem(schema) {
|
98
|
-
schema = JSON.parse(JSON.stringify(schema));
|
99
|
-
if (schema.type === "array") {
|
100
|
-
let array = [];
|
101
|
-
schema.minItems = 1;
|
102
|
-
for (let i = 0; i < schema.minItems; i++) {
|
103
|
-
let value = getDefaultItem(schema.items);
|
104
|
-
if (value) {
|
105
|
-
if (
|
106
|
-
schema["Q:type"] &&
|
107
|
-
schema["Q:type"] === "files" &&
|
108
|
-
schema["Q:options"] &&
|
109
|
-
schema["Q:options"].fileProperties
|
110
|
-
) {
|
111
|
-
array.push(Object.assign(value, schema["Q:options"].fileProperties));
|
112
|
-
} else {
|
113
|
-
array.push(value);
|
114
|
-
}
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
const defaultValue = getDefaultOrNull(schema);
|
119
|
-
if (array === null && defaultValue !== null) {
|
120
|
-
array = defaultValue;
|
121
|
-
}
|
122
|
-
return array;
|
123
|
-
} else if (schema.type === "object") {
|
124
|
-
const defaultValue = getDefaultOrNull(schema);
|
125
|
-
if (defaultValue !== null) {
|
126
|
-
return defaultValue;
|
127
|
-
}
|
128
|
-
|
129
|
-
if (
|
130
|
-
schema["Q:type"] &&
|
131
|
-
schema["Q:type"] === "files" &&
|
132
|
-
schema["Q:options"] &&
|
133
|
-
schema["Q:options"].fileProperties
|
134
|
-
) {
|
135
|
-
return schema["Q:options"].fileProperties;
|
136
|
-
}
|
137
|
-
|
138
|
-
if (!schema.hasOwnProperty("properties")) {
|
139
|
-
return undefined;
|
140
|
-
}
|
141
|
-
let object = {};
|
142
|
-
Object.keys(schema.properties).forEach((propertyName) => {
|
143
|
-
const property = schema.properties[propertyName];
|
144
|
-
let value = getDefaultItem(property);
|
145
|
-
if (value !== undefined) {
|
146
|
-
object[propertyName] = value;
|
147
|
-
} else if (
|
148
|
-
property["Q:type"] &&
|
149
|
-
property["Q:type"] === "files" &&
|
150
|
-
property["Q:options"] &&
|
151
|
-
property["Q:options"].fileProperties
|
152
|
-
) {
|
153
|
-
object[propertyName] = property["Q:options"].fileProperties;
|
154
|
-
}
|
155
|
-
});
|
156
|
-
return object;
|
157
|
-
}
|
158
|
-
|
159
|
-
// if this is not an array or object, we just get the default if any
|
160
|
-
const defaultValue = getDefaultOrNull(schema);
|
161
|
-
if (defaultValue !== null) {
|
162
|
-
return defaultValue;
|
163
|
-
}
|
164
|
-
return undefined;
|
165
|
-
}
|
166
|
-
|
167
|
-
async function updateItem(item, environment, config, qConfigPath) {
|
168
|
-
const qServer = config.get(`${environment.name}.qServer`);
|
169
|
-
const accessToken = config.get(`${environment.name}.accessToken`);
|
170
|
-
const cookie = config.get(`${environment.name}.cookie`);
|
171
|
-
const existingItem = await getItem(qServer, environment, accessToken, cookie);
|
172
|
-
const updatedItem = await getUpdatedItem(
|
173
|
-
qServer,
|
174
|
-
accessToken,
|
175
|
-
cookie,
|
176
|
-
existingItem,
|
177
|
-
item,
|
178
|
-
environment,
|
179
|
-
qConfigPath
|
180
|
-
);
|
181
|
-
return await saveItem(qServer, environment, accessToken, cookie, updatedItem);
|
182
|
-
}
|
183
|
-
|
184
|
-
async function getUpdatedItem(
|
185
|
-
qServer,
|
186
|
-
accessToken,
|
187
|
-
cookie,
|
188
|
-
existingItem,
|
189
|
-
item,
|
190
|
-
environment,
|
191
|
-
qConfigPath
|
192
|
-
) {
|
193
|
-
try {
|
194
|
-
const toolSchema = await schemaService.getToolSchema(
|
195
|
-
qServer,
|
196
|
-
existingItem.tool
|
197
|
-
);
|
198
|
-
// Removes additional properties not defined in the schema on the top level object of the item
|
199
|
-
toolSchema.additionalProperties = false;
|
200
|
-
// If options object is available additional properties not defined in the schema are removed
|
201
|
-
if (toolSchema.properties && toolSchema.properties.options) {
|
202
|
-
toolSchema.properties.options.additionalProperties = false;
|
203
|
-
}
|
204
|
-
const defaultItem = getDefaultItem(toolSchema);
|
205
|
-
item = JSON.parse(JSON.stringify(item));
|
206
|
-
item = await resourcesService.handleResources(
|
207
|
-
qServer,
|
208
|
-
accessToken,
|
209
|
-
cookie,
|
210
|
-
item,
|
211
|
-
defaultItem,
|
212
|
-
qConfigPath,
|
213
|
-
environment
|
214
|
-
);
|
215
|
-
|
216
|
-
// Merge options:
|
217
|
-
// File of files property will be updated (if file exists on destination)
|
218
|
-
// If it doesn't exist it is appended to the files array
|
219
|
-
// All other properties are overwritten from source config
|
220
|
-
const options = {
|
221
|
-
arrayMerge: (destArr, srcArr) => srcArr,
|
222
|
-
customMerge: (key) => {
|
223
|
-
if (key === "files") {
|
224
|
-
return (destArr, srcArr) => {
|
225
|
-
if (destArr.length <= 0) {
|
226
|
-
return srcArr;
|
227
|
-
}
|
228
|
-
|
229
|
-
srcArr.forEach((fileObj) => {
|
230
|
-
let destIndex = destArr.findIndex(
|
231
|
-
(destFileObj) =>
|
232
|
-
destFileObj.file.originalName === fileObj.file.originalName
|
233
|
-
);
|
234
|
-
|
235
|
-
if (destIndex !== -1) {
|
236
|
-
destArr[destIndex] = fileObj;
|
237
|
-
} else {
|
238
|
-
destArr.push(fileObj);
|
239
|
-
}
|
240
|
-
});
|
241
|
-
return destArr;
|
242
|
-
};
|
243
|
-
}
|
244
|
-
},
|
245
|
-
};
|
246
|
-
|
247
|
-
// merges existing item with the item defined in q.config.json
|
248
|
-
const updatedItem = deepmerge(existingItem, item, options);
|
249
|
-
// normalizes the item which removes additional properties not defined in the schema
|
250
|
-
// and validates the item against the schema
|
251
|
-
const normalizedItem = schemaService.getNormalizedItem(
|
252
|
-
toolSchema,
|
253
|
-
updatedItem,
|
254
|
-
environment
|
255
|
-
);
|
256
|
-
// the normalized item is merged with the existing item. This is done because properties such as _id and _rev
|
257
|
-
// defined in the existing item are removed during normalization, because they are not defined in the schema
|
258
|
-
return deepmerge(existingItem, normalizedItem, options);
|
259
|
-
} catch (error) {
|
260
|
-
console.error(errorColor(error.message));
|
261
|
-
process.exit(1);
|
262
|
-
}
|
263
|
-
}
|
264
|
-
|
265
|
-
async function saveItem(
|
266
|
-
qServer,
|
267
|
-
environment,
|
268
|
-
accessToken,
|
269
|
-
cookie,
|
270
|
-
updatedItem
|
271
|
-
) {
|
272
|
-
try {
|
273
|
-
delete updatedItem.updatedDate;
|
274
|
-
const response = await fetch(`${qServer}item`, {
|
275
|
-
method: "PUT",
|
276
|
-
body: JSON.stringify(updatedItem),
|
277
|
-
headers: {
|
278
|
-
"user-agent": "Q Command-line Tool",
|
279
|
-
Authorization: `Bearer ${accessToken}`,
|
280
|
-
"Content-Type": "application/json",
|
281
|
-
Cookie: cookie ? cookie : "",
|
282
|
-
},
|
283
|
-
});
|
284
|
-
if (response.ok) {
|
285
|
-
return await response.json();
|
286
|
-
} else {
|
287
|
-
throw new Error(
|
288
|
-
`A problem occured while saving item with id ${environment.id} on ${environment.name} environment. Please check your connection and try again.`
|
289
|
-
);
|
290
|
-
}
|
291
|
-
} catch (error) {
|
292
|
-
console.error(errorColor(error.message));
|
293
|
-
process.exit(1);
|
294
|
-
}
|
295
|
-
}
|
296
|
-
|
297
|
-
module.exports = {
|
298
|
-
createItem: createItem,
|
299
|
-
getItem: getItem,
|
300
|
-
getItems: getItems,
|
301
|
-
updateItem: updateItem,
|
302
|
-
};
|