@nzz/q-cli 1.5.1 → 1.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/.vscode/settings.json +5 -0
  2. package/README.md +16 -1
  3. package/bin/commands/bootstrap.js +6 -0
  4. package/bin/commands/updateItem/helpers.js +52 -18
  5. package/bin/commands/updateItem/resourcesHelpers.js +4 -2
  6. package/dev-server/routes/rendering-info.js +0 -1
  7. package/dev-server/routes/tool-default.js +0 -2
  8. package/dev-server/server.js +3 -0
  9. package/package.json +1 -1
  10. package/skeletons/custom-code-skeleton/.nvmrc +1 -1
  11. package/skeletons/custom-code-skeleton/.vscode/settings.json +5 -0
  12. package/skeletons/custom-code-skeleton/package-lock.json +5335 -627
  13. package/skeletons/custom-code-skeleton/package.json +10 -7
  14. package/skeletons/custom-code-skeleton/rollup.config.js +63 -17
  15. package/skeletons/custom-code-skeleton/src/App.scss +3 -0
  16. package/skeletons/custom-code-skeleton/src/App.svelte +1 -7
  17. package/skeletons/custom-code-skeleton/src/main-prod.js +1 -0
  18. package/skeletons/custom-code-skeleton/src/main.js +1 -0
  19. package/skeletons/custom-code-skeleton/src/main.scss +1 -0
  20. package/skeletons/server-skeleton/auth/routes.js +0 -9
  21. package/skeletons/server-skeleton/index.js +1 -3
  22. package/skeletons/tool-skeleton/.nvmrc +1 -1
  23. package/skeletons/tool-skeleton/.travis.yml +26 -0
  24. package/skeletons/tool-skeleton/.vscode/settings.json +5 -0
  25. package/skeletons/tool-skeleton/Dockerfile +1 -1
  26. package/skeletons/tool-skeleton/LICENSE +20 -0
  27. package/skeletons/tool-skeleton/README.md +1 -1
  28. package/skeletons/tool-skeleton/index.js +1 -6
  29. package/skeletons/tool-skeleton/package-lock.json +8540 -2741
  30. package/skeletons/tool-skeleton/package.json +24 -12
  31. package/skeletons/tool-skeleton/rollup.config.js +75 -0
  32. package/skeletons/tool-skeleton/routes/fixtures/data.js +1 -3
  33. package/skeletons/tool-skeleton/routes/rendering-info/web.js +43 -20
  34. package/skeletons/tool-skeleton/routes/routes.js +1 -1
  35. package/skeletons/tool-skeleton/routes/script.js +4 -5
  36. package/skeletons/tool-skeleton/routes/stylesheet.js +4 -5
  37. package/skeletons/tool-skeleton/sass.config.js +66 -0
  38. package/skeletons/tool-skeleton/scripts_src/default.js +3 -0
  39. package/skeletons/tool-skeleton/styles_src/_variables.scss +1 -0
  40. package/skeletons/tool-skeleton/styles_src/main.scss +2 -0
  41. package/skeletons/tool-skeleton/test/e2e-tests.js +4 -6
  42. package/skeletons/tool-skeleton/views/dynamic/YourTool.scss +5 -0
  43. package/skeletons/tool-skeleton/views/dynamic/YourTool.svelte +19 -0
  44. package/skeletons/tool-skeleton/views/static/App.scss +5 -0
  45. package/skeletons/tool-skeleton/views/static/App.svelte +21 -0
  46. package/skeletons/tool-skeleton/views/static/components/Footer.svelte +31 -0
  47. package/skeletons/tool-skeleton/views/static/components/Header.svelte +7 -0
  48. package/skeletons/tool-skeleton/styles_src/default.scss +0 -4
  49. package/skeletons/tool-skeleton/tasks/build.js +0 -98
@@ -0,0 +1,5 @@
1
+ {
2
+ "[svelte]": {
3
+ "editor.defaultFormatter": "svelte.svelte-vscode"
4
+ }
5
+ }
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Q cli [![Build Status](https://travis-ci.com/nzzdev/Q-cli.svg?branch=dev)](https://travis-ci.com/nzzdev/Q-cli)
2
2
 
3
- **Maintainer**: [manuelroth](https://github.com/manuelroth)
3
+ **Maintainer**: [Nicolas Staub](https://github.com/fromdusttilldawn)
4
4
 
5
5
  ## Table of contents
6
6
 
@@ -26,6 +26,21 @@ nvm use
26
26
  npm install
27
27
  ```
28
28
 
29
+ For testing local changes of Q-cli, one can link the local package to the global installation of Q-cli:
30
+
31
+ ```bash
32
+ cd Q-cli
33
+ npm link
34
+ ```
35
+
36
+ Q commands will now use the local Q-cli.
37
+
38
+ To unlink, simply install Q-cli again globally:
39
+
40
+ ```bash
41
+ npm install @nzz/q-cli -g
42
+ ```
43
+
29
44
  [to the top](#table-of-contents)
30
45
 
31
46
  ## Functionality
@@ -4,6 +4,7 @@ const replaceInFile = require("replace-in-file");
4
4
  const chalk = require("chalk");
5
5
  const errorColor = chalk.red;
6
6
  const successColor = chalk.green;
7
+ const warningColor = chalk.yellow;
7
8
 
8
9
  module.exports = async function (type, name, basedir) {
9
10
  if (fs.existsSync(basedir)) {
@@ -31,6 +32,11 @@ module.exports = async function (type, name, basedir) {
31
32
  );
32
33
  await replaceInFile(replaceOptions);
33
34
  console.log(successColor(`Q ${type} is now bootstrapped in ${basedir}`));
35
+
36
+ if (type === "tool")
37
+ console.log(
38
+ warningColor("Search for 'TODO:' inside the new tool to get started!")
39
+ );
34
40
  } catch (error) {
35
41
  console.error(
36
42
  errorColor(
@@ -84,20 +84,49 @@ async function getUpdatedItem(
84
84
  environment
85
85
  );
86
86
 
87
- const updatedItem = deepmerge(existingItem, item, {
87
+ // Merge options:
88
+ // File of files property will be updated (if file exists on destination)
89
+ // If it doesn't exist it is appended to the files array
90
+ // All other properties are overwritten from source config
91
+ const options = {
88
92
  arrayMerge: (destArr, srcArr) => srcArr,
89
- });
90
-
91
- const validationResult = validateItem(toolSchema, updatedItem);
92
- if (validationResult.isValid) {
93
- return deepmerge(existingItem, updatedItem, {
94
- arrayMerge: (destArr, srcArr) => srcArr,
95
- });
96
- } else {
97
- throw new Error(
98
- `A problem occured while validating item with id ${environment.id} on ${environment.name} environment: ${validationResult.errorsText}`
99
- );
100
- }
93
+ customMerge: (key) => {
94
+ if (key === "files") {
95
+ return (destArr, srcArr) => {
96
+ if (destArr.length <= 0) {
97
+ return srcArr;
98
+ }
99
+
100
+ srcArr.forEach((fileObj) => {
101
+ let destIndex = destArr.findIndex(
102
+ (destFileObj) =>
103
+ destFileObj.file.originalName === fileObj.file.originalName
104
+ );
105
+
106
+ if (destIndex !== -1) {
107
+ destArr[destIndex] = fileObj;
108
+ } else {
109
+ destArr.push(fileObj);
110
+ }
111
+ });
112
+ return destArr;
113
+ };
114
+ }
115
+ },
116
+ };
117
+
118
+ // merges existing item with the item defined in q.config.json
119
+ const updatedItem = deepmerge(existingItem, item, options);
120
+ // normalizes the item which removes additional properties not defined in the schema
121
+ // and validates the item against the schema
122
+ const normalizedItem = getNormalizedItem(
123
+ toolSchema,
124
+ updatedItem,
125
+ environment
126
+ );
127
+ // the normalized item is merged with the existing item. This is done because properties such as _id and _rev
128
+ // defined in the existing item are removed during normalization, because they are not defined in the schema
129
+ return deepmerge(existingItem, normalizedItem, options);
101
130
  } catch (error) {
102
131
  console.error(errorColor(error.message));
103
132
  process.exit(1);
@@ -168,12 +197,17 @@ function validateConfig(config) {
168
197
  };
169
198
  }
170
199
 
171
- function validateItem(schema, item) {
200
+ function getNormalizedItem(schema, item, environment) {
172
201
  const isValid = ajv.validate(schema, item);
173
- return {
174
- isValid: isValid,
175
- errorsText: ajv.errorsText(),
176
- };
202
+ if (!isValid) {
203
+ throw new Error(
204
+ `A problem occured while validating item with id ${environment.id} on ${
205
+ environment.name
206
+ } environment: ${ajv.errorsText()}`
207
+ );
208
+ }
209
+
210
+ return item;
177
211
  }
178
212
 
179
213
  function getEnvironments(qConfig, environmentFilter) {
@@ -223,11 +223,13 @@ async function uploadResource(qServer, accessToken, cookie, resourcePath) {
223
223
  headers: headers,
224
224
  body: form,
225
225
  });
226
+ const body = await response.json();
227
+
226
228
  if (response.ok) {
227
- return await response.json();
229
+ return body;
228
230
  } else {
229
231
  throw new Error(
230
- `Error occured while uploading the resource at ${resourcePath}. Please check your connection and try again.\nResponse: ${response.status} - ${response.statusText}`
232
+ `Error occured while uploading the resource at ${resourcePath}. Please check your connection and try again.\nResponse: ${body.statusCode} ${body.error} - ${body.message}`
231
233
  );
232
234
  }
233
235
  } else {
@@ -47,7 +47,6 @@ module.exports = {
47
47
  allowUnknown: true,
48
48
  },
49
49
  },
50
- cors: true,
51
50
  },
52
51
  handler: async function (request, h) {
53
52
  try {
@@ -52,7 +52,6 @@ module.exports = {
52
52
  allowUnknown: true,
53
53
  },
54
54
  },
55
- cors: true,
56
55
  },
57
56
  handler: async (request, h) => {
58
57
  let payload = null;
@@ -89,7 +88,6 @@ module.exports = {
89
88
  allowUnknown: true,
90
89
  },
91
90
  },
92
- cors: true,
93
91
  },
94
92
  handler: async (request, h) => {
95
93
  if (request.query.appendItemToPayload) {
@@ -5,6 +5,9 @@ const Path = require("path");
5
5
  const server = new Hapi.Server({
6
6
  port: process.env.PORT || 5000,
7
7
  routes: {
8
+ cors: {
9
+ origin: ["*"],
10
+ },
8
11
  files: {
9
12
  relativeTo: Path.join(__dirname, "public"),
10
13
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nzz/q-cli",
3
- "version": "1.5.1",
3
+ "version": "1.5.6",
4
4
  "description": "Cli tool to setup new Q tools, new Q server implementations and start Q dev server to test developing Q tools",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1 +1 @@
1
- 14
1
+ 16
@@ -0,0 +1,5 @@
1
+ {
2
+ "[svelte]": {
3
+ "editor.defaultFormatter": "svelte.svelte-vscode"
4
+ }
5
+ }