@nzz/q-cli 1.10.3 → 2.0.0-beta.7

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.
Files changed (163) hide show
  1. package/dist/index.js +79 -0
  2. package/dist/interfaces.js +1 -0
  3. package/dist/newCustomCode.js +106 -0
  4. package/dist/updateItem.js +191 -0
  5. package/dist/utils.js +11 -0
  6. package/package.json +27 -36
  7. package/.nvmrc +0 -1
  8. package/.travis.yml +0 -17
  9. package/.vscode/launch.json +0 -36
  10. package/.vscode/settings.json +0 -5
  11. package/LICENSE +0 -21
  12. package/README.md +0 -360
  13. package/bin/commands/bootstrap.js +0 -68
  14. package/bin/commands/qItem/configStore.js +0 -144
  15. package/bin/commands/qItem/copyItem/copyItem.js +0 -103
  16. package/bin/commands/qItem/copyItem/copySchema.json +0 -37
  17. package/bin/commands/qItem/createCustomCodeItem/createCustomCodeItem.js +0 -81
  18. package/bin/commands/qItem/createCustomCodeItem/schema.json +0 -41
  19. package/bin/commands/qItem/helpers.js +0 -102
  20. package/bin/commands/qItem/itemService.js +0 -310
  21. package/bin/commands/qItem/resourcesService.js +0 -148
  22. package/bin/commands/qItem/schemaService.js +0 -65
  23. package/bin/commands/qItem/updateItem/updateItem.js +0 -64
  24. package/bin/commands/server.js +0 -80
  25. package/bin/q.js +0 -213
  26. package/dev-server/config/default.js +0 -51
  27. package/dev-server/public/favicon.ico +0 -0
  28. package/dev-server/public/style.css +0 -64
  29. package/dev-server/routes/dev-view.js +0 -52
  30. package/dev-server/routes/file.js +0 -10
  31. package/dev-server/routes/rendering-info.js +0 -130
  32. package/dev-server/routes/routes.js +0 -6
  33. package/dev-server/routes/tool-default.js +0 -108
  34. package/dev-server/server-plugins.js +0 -1
  35. package/dev-server/server.js +0 -18
  36. package/dev-server/views/index.html +0 -184
  37. package/skeletons/custom-code-skeleton/.nvmrc +0 -1
  38. package/skeletons/custom-code-skeleton/.vscode/settings.json +0 -5
  39. package/skeletons/custom-code-skeleton/README.md +0 -26
  40. package/skeletons/custom-code-skeleton/index.d.ts +0 -3
  41. package/skeletons/custom-code-skeleton/package-lock.json +0 -7355
  42. package/skeletons/custom-code-skeleton/package.json +0 -46
  43. package/skeletons/custom-code-skeleton/q.config.json +0 -60
  44. package/skeletons/custom-code-skeleton/rollup.config.js +0 -185
  45. package/skeletons/custom-code-skeleton/src/App.scss +0 -5
  46. package/skeletons/custom-code-skeleton/src/App.svelte +0 -7
  47. package/skeletons/custom-code-skeleton/src/enums.ts +0 -0
  48. package/skeletons/custom-code-skeleton/src/interfaces.ts +0 -0
  49. package/skeletons/custom-code-skeleton/src/main-prod.ts +0 -4
  50. package/skeletons/custom-code-skeleton/src/main.scss +0 -1
  51. package/skeletons/custom-code-skeleton/src/main.ts +0 -18
  52. package/skeletons/custom-code-skeleton/tsconfig.json +0 -16
  53. package/skeletons/et-utils-package-skeleton/.nvmrc +0 -1
  54. package/skeletons/et-utils-package-skeleton/README.md +0 -12
  55. package/skeletons/et-utils-package-skeleton/jest.config.ts +0 -17
  56. package/skeletons/et-utils-package-skeleton/package-lock.json +0 -3969
  57. package/skeletons/et-utils-package-skeleton/package.json +0 -40
  58. package/skeletons/et-utils-package-skeleton/scripts/package-fixup.sh +0 -13
  59. package/skeletons/et-utils-package-skeleton/src/Service.ts +0 -8
  60. package/skeletons/et-utils-package-skeleton/src/index.ts +0 -4
  61. package/skeletons/et-utils-package-skeleton/test/Service.spec.ts +0 -10
  62. package/skeletons/et-utils-package-skeleton/test/tsconfig.json +0 -8
  63. package/skeletons/et-utils-package-skeleton/tsconfig-base.json +0 -10
  64. package/skeletons/et-utils-package-skeleton/tsconfig-cjs.json +0 -8
  65. package/skeletons/et-utils-package-skeleton/tsconfig.json +0 -8
  66. package/skeletons/server-skeleton/.nvmrc +0 -1
  67. package/skeletons/server-skeleton/Dockerfile +0 -19
  68. package/skeletons/server-skeleton/auth/routes.js +0 -85
  69. package/skeletons/server-skeleton/auth/strategyOptions.js +0 -28
  70. package/skeletons/server-skeleton/config/base.js +0 -45
  71. package/skeletons/server-skeleton/config/db.js +0 -6
  72. package/skeletons/server-skeleton/config/editor.js +0 -105
  73. package/skeletons/server-skeleton/config/rendering-info.js +0 -70
  74. package/skeletons/server-skeleton/config/screenshot.js +0 -80
  75. package/skeletons/server-skeleton/config/targets.js +0 -31
  76. package/skeletons/server-skeleton/config/tools.js +0 -65
  77. package/skeletons/server-skeleton/files/favicon.png +0 -0
  78. package/skeletons/server-skeleton/files/system.js +0 -3612
  79. package/skeletons/server-skeleton/index.js +0 -106
  80. package/skeletons/server-skeleton/package-lock.json +0 -1825
  81. package/skeletons/server-skeleton/package.json +0 -29
  82. package/skeletons/tool-skeleton/.dockerignore +0 -1
  83. package/skeletons/tool-skeleton/.nvmrc +0 -1
  84. package/skeletons/tool-skeleton/.travis.yml +0 -26
  85. package/skeletons/tool-skeleton/.vscode/settings.json +0 -5
  86. package/skeletons/tool-skeleton/Dockerfile +0 -19
  87. package/skeletons/tool-skeleton/LICENSE +0 -20
  88. package/skeletons/tool-skeleton/README.md +0 -104
  89. package/skeletons/tool-skeleton/index.js +0 -32
  90. package/skeletons/tool-skeleton/package-lock.json +0 -10108
  91. package/skeletons/tool-skeleton/package.json +0 -45
  92. package/skeletons/tool-skeleton/resources/display-options-schema.json +0 -11
  93. package/skeletons/tool-skeleton/resources/fixtures/data/basic.json +0 -4
  94. package/skeletons/tool-skeleton/resources/locales/de/translation.json +0 -1
  95. package/skeletons/tool-skeleton/resources/locales/en/translation.json +0 -1
  96. package/skeletons/tool-skeleton/resources/locales/fr/translation.json +0 -1
  97. package/skeletons/tool-skeleton/resources/schema.json +0 -16
  98. package/skeletons/tool-skeleton/rollup.config.js +0 -75
  99. package/skeletons/tool-skeleton/routes/fixtures/data.js +0 -15
  100. package/skeletons/tool-skeleton/routes/health.js +0 -10
  101. package/skeletons/tool-skeleton/routes/locales.js +0 -21
  102. package/skeletons/tool-skeleton/routes/rendering-info/web.js +0 -97
  103. package/skeletons/tool-skeleton/routes/routes.js +0 -8
  104. package/skeletons/tool-skeleton/routes/schema.js +0 -19
  105. package/skeletons/tool-skeleton/routes/script.js +0 -17
  106. package/skeletons/tool-skeleton/routes/stylesheet.js +0 -17
  107. package/skeletons/tool-skeleton/sass.config.js +0 -66
  108. package/skeletons/tool-skeleton/scripts_src/default.js +0 -3
  109. package/skeletons/tool-skeleton/styles_src/_variables.scss +0 -1
  110. package/skeletons/tool-skeleton/styles_src/main.scss +0 -2
  111. package/skeletons/tool-skeleton/test/e2e-tests.js +0 -162
  112. package/skeletons/tool-skeleton/views/dynamic/YourTool.scss +0 -5
  113. package/skeletons/tool-skeleton/views/dynamic/YourTool.svelte +0 -19
  114. package/skeletons/tool-skeleton/views/static/App.scss +0 -5
  115. package/skeletons/tool-skeleton/views/static/App.svelte +0 -21
  116. package/skeletons/tool-skeleton/views/static/components/Footer.svelte +0 -31
  117. package/skeletons/tool-skeleton/views/static/components/Header.svelte +0 -7
  118. package/skeletons/toolv2-skeleton/.husky/pre-commit +0 -6
  119. package/skeletons/toolv2-skeleton/.nvmrc +0 -1
  120. package/skeletons/toolv2-skeleton/.prettierrc.cjs +0 -15
  121. package/skeletons/toolv2-skeleton/.travis.yml +0 -30
  122. package/skeletons/toolv2-skeleton/.vscode/settings.json +0 -6
  123. package/skeletons/toolv2-skeleton/Dockerfile +0 -19
  124. package/skeletons/toolv2-skeleton/LICENSE +0 -21
  125. package/skeletons/toolv2-skeleton/README.md +0 -99
  126. package/skeletons/toolv2-skeleton/dev.js +0 -7
  127. package/skeletons/toolv2-skeleton/index.js +0 -39
  128. package/skeletons/toolv2-skeleton/jest.config.ts +0 -39
  129. package/skeletons/toolv2-skeleton/nodemon.json +0 -4
  130. package/skeletons/toolv2-skeleton/package-lock.json +0 -21382
  131. package/skeletons/toolv2-skeleton/package.json +0 -80
  132. package/skeletons/toolv2-skeleton/resources/display-options-schema.json +0 -11
  133. package/skeletons/toolv2-skeleton/resources/locales/de/translation.json +0 -8
  134. package/skeletons/toolv2-skeleton/resources/locales/en/translation.json +0 -10
  135. package/skeletons/toolv2-skeleton/resources/locales/fr/translation.json +0 -10
  136. package/skeletons/toolv2-skeleton/resources/schema.json +0 -66
  137. package/skeletons/toolv2-skeleton/rollup.config.js +0 -48
  138. package/skeletons/toolv2-skeleton/scripts/postinstall.sh +0 -5
  139. package/skeletons/toolv2-skeleton/src/.eslintrc.cjs +0 -52
  140. package/skeletons/toolv2-skeleton/src/components/Main.spec.ts +0 -15
  141. package/skeletons/toolv2-skeleton/src/components/Main.svelte +0 -32
  142. package/skeletons/toolv2-skeleton/src/enums.ts +0 -11
  143. package/skeletons/toolv2-skeleton/src/helpers/fixture-generators.ts +0 -38
  144. package/skeletons/toolv2-skeleton/src/helpers/toolRuntimeConfig.ts +0 -15
  145. package/skeletons/toolv2-skeleton/src/interfaces.ts +0 -82
  146. package/skeletons/toolv2-skeleton/src/modules.d.ts +0 -8
  147. package/skeletons/toolv2-skeleton/src/routes/dynamic-schemas/exampleDynamicSchema.ts +0 -49
  148. package/skeletons/toolv2-skeleton/src/routes/dynamic-schemas/index.ts +0 -5
  149. package/skeletons/toolv2-skeleton/src/routes/health.ts +0 -14
  150. package/skeletons/toolv2-skeleton/src/routes/locales.ts +0 -31
  151. package/skeletons/toolv2-skeleton/src/routes/notifications/exampleNotification.ts +0 -46
  152. package/skeletons/toolv2-skeleton/src/routes/option-availability.ts +0 -27
  153. package/skeletons/toolv2-skeleton/src/routes/rendering-info/web.ts +0 -150
  154. package/skeletons/toolv2-skeleton/src/routes/routes.ts +0 -21
  155. package/skeletons/toolv2-skeleton/src/routes/schema.ts +0 -21
  156. package/skeletons/toolv2-skeleton/src/routes/stylesheet.ts +0 -31
  157. package/skeletons/toolv2-skeleton/src/styles/main.scss +0 -6
  158. package/skeletons/toolv2-skeleton/svelte.config.cjs +0 -6
  159. package/skeletons/toolv2-skeleton/tasks/compileStyleFiles.cjs +0 -101
  160. package/skeletons/toolv2-skeleton/tests/e2e-tests.spec.ts +0 -158
  161. package/skeletons/toolv2-skeleton/tests/helpers.ts +0 -21
  162. package/skeletons/toolv2-skeleton/tsconfig.json +0 -48
  163. /package/{bin/commands/qItem/updateItem → dist/assets}/updateSchema.json +0 -0
package/README.md DELETED
@@ -1,360 +0,0 @@
1
- # Q cli [![Build Status](https://travis-ci.com/nzzdev/Q-cli.svg?branch=dev)](https://travis-ci.com/nzzdev/Q-cli)
2
-
3
- **Maintainer**: [Nicolas Staub](https://github.com/fromdusttilldawn)
4
-
5
- ## Table of contents
6
-
7
- - [Installation](#installation)
8
- - [Development](#development)
9
- - [Github Actions](#github-actions)
10
- - [Functionality](#functionality)
11
- - [License](#license)
12
-
13
- ## Installation
14
-
15
- ```bash
16
- npm install -g @nzz/q-cli
17
- ```
18
-
19
- ## Development
20
-
21
- ```
22
- git clone git@github.com:nzzdev/Q-cli.git
23
- cd Q-cli
24
- nvm use
25
- npm install
26
- ```
27
-
28
- For testing local changes of Q-cli, one can link the local package to the global installation of Q-cli:
29
-
30
- ```bash
31
- cd Q-cli
32
- npm link
33
- ```
34
-
35
- Q commands will now use the local Q-cli.
36
-
37
- To unlink, simply install Q-cli again globally:
38
-
39
- ```bash
40
- npm install @nzz/q-cli -g
41
- ```
42
-
43
- ## Github actions
44
-
45
- To use the q-cli in github actions there are special access tokens provided. You can find them in 1password (LivingDocs Public API Access Tokens).
46
-
47
- There is an entire [thread](https://3.basecamp.com/3500782/buckets/1333707/documents/2903809795#__recording_3878674488) in basecamp on how this solution works.
48
-
49
- Example code for a github action to update on all environments. You can check the functionality section if you only want to update a specific environment.
50
-
51
- You will need to set the secrets in github unders **settings > secrets & variables > actions > New repository secret**
52
-
53
- ```
54
- - name: Run Q cli
55
- run: Q update-item
56
- env:
57
- Q_STAGING_SERVER: ${{ secrets.Q_STAGING_SERVER }}
58
- Q_STAGING_ACCESSTOKEN: ${{ secrets.Q_STAGING_ACCESSTOKEN }}
59
- Q_PRODUCTION_SERVER: ${{ secrets.Q_PRODUCTION_SERVER }}
60
- Q_PRODUCTION_ACCESSTOKEN: ${{ secrets.Q_PRODUCTION_ACCESSTOKEN }}
61
- ```
62
-
63
- [to the top](#table-of-contents)
64
-
65
- ## Functionality
66
-
67
- ### Q dev server
68
-
69
- Once `Q` cli installed one can start Q dev server by running:
70
-
71
- ```bash
72
- Q server
73
- ```
74
-
75
- With the Q dev server running one can now test a tool with fixture data. Of course the respective tool has to be started as well.
76
-
77
- - Default port is 5000 and can be overwritten by using `-p` or `--port` as option while starting Q dev server:
78
-
79
- ```bash
80
- Q server -p 4001
81
- ```
82
-
83
- - Default base url of the tool your are currently developing is `http://localhost:3000`, this can also be changed by passing the option `-b` or `--tool-base-url` while starting Q dev server.
84
-
85
- ```bash
86
- Q server -b http://localhost:4000
87
- ```
88
-
89
- - Default target is `nzz_ch` and can be overwritten by using `-t` or `--target`.
90
-
91
- ```bash
92
- Q server -t your_target
93
- ```
94
-
95
- - One can optionally specify a path to a config file by using option `-c` or `--config`, e.g.
96
-
97
- ```bash
98
- Q server -c ./config-file-name.js
99
- ```
100
-
101
- A config file should export an async function returning a config object. The config object has to contain an object for each target. Target objects can contain
102
-
103
- - tool specific additionalRenderingInfo like additional stylesheets and scripts to load
104
- - a target specific context which can also contain stylesheets, scripts or background information
105
- - toolRuntimeConfig containing information which a tool might need at runtime
106
- Config file example:
107
-
108
- ```js
109
- async function getConfig() {
110
- return {
111
- nzz_ch: {
112
- // target name
113
- additionalRenderingInfo: {
114
- // additionalRenderingInfo is tool based
115
- stylesheets: [
116
- {
117
- url: "https://service.sophie.nzz.ch/bundle/sophie-q@1,sophie-font@1,sophie-color@1,sophie-viz-color@1,sophie-input@1.css",
118
- },
119
- ],
120
- },
121
- context: {
122
- // context is target based
123
- stylesheets: [
124
- {
125
- url: "https://context-service.st.nzz.ch/stylesheet/all/nzz.ch.css",
126
- },
127
- ],
128
- background: {
129
- color: "#fff",
130
- },
131
- },
132
- toolRuntimeConfig: {
133
- displayOptions: {
134
- hideTitle: true,
135
- },
136
- },
137
- },
138
- };
139
- }
140
-
141
- module.exports = getConfig;
142
- ```
143
-
144
- ### Creating new Q server implementation
145
-
146
- Once `Q` cli is installed one can create the skeleton of a Q server implementation by executing
147
-
148
- ```bash
149
- Q new-server my-server-name
150
- ```
151
-
152
- - The directory name where the server implementation is being created defaults to the server name and can be overwritten by using option `-d` or `--dir`
153
-
154
- ```bash
155
- Q new-server my-server-name -d my-server-directory
156
- ```
157
-
158
- ### Creating new tool
159
-
160
- Once `Q` cli is installed one can create the skeleton of a new tool by executing
161
-
162
- ```bash
163
- Q new-tool my-tool-name
164
- ```
165
-
166
- - The directory name where the new tool is being created defaults to the tool name and can be overwritten by using option `-d` or `--dir`
167
-
168
- ```bash
169
- Q new-tool my-tool-name -d my-tool-directory
170
- ```
171
-
172
- ### Creating new custom code project
173
-
174
- Once `Q` cli is installed one can create the skeleton of a new custom code project by executing
175
-
176
- ```bash
177
- Q new-custom-code my-project-name
178
- ```
179
-
180
- - The directory name where the new custom-code project is being created defaults to the project name and can be overwritten by using option `-d` or `--dir`
181
-
182
- ```bash
183
- Q new-custom-code my-project-name -d my-project-directory
184
- ```
185
-
186
- ### Creating new ed-tech utility package project
187
-
188
- Once `Q` cli is installed one can create the skeleton of a new ed-tech utility package project by executing
189
-
190
- ```bash
191
- Q new-et-utils-package package-name package-author package-description
192
- ```
193
-
194
- - The directory name where the new ed-tech utility package project is being created defaults to the project name and can be overwritten by using option `-d` or `--dir`
195
-
196
- ```bash
197
- Q new-et-utils-package package-name -d my-project-directory
198
- ```
199
-
200
- #### Notes
201
-
202
- New utility package projects should only be created inside the [ed-tech-utilities](https://github.com/nzzdev/ed-tech-utilities) repository.
203
-
204
- ### Q item actions
205
-
206
- The `Q` cli can copy and/or update existing Q items.
207
-
208
- #### Updating existing Q items
209
-
210
- Once `Q` cli installed one can update one or many Q items by executing:
211
-
212
- ```bash
213
- Q update-item
214
- ```
215
-
216
- - The path to the config file can be set by using option `-c` or `--config`. By default the `update-item` command will look for a config file called `q.config.json` in the current directory
217
-
218
- ```bash
219
- Q update-item -c [path]
220
- ```
221
-
222
- - Items of a specified environment can be updated by using the option `-e` or `--environment`. By default the `update-item` command updates all item specified in the config file
223
-
224
- ```bash
225
- Q update-item -e [env]
226
- ```
227
-
228
- - Stored configuration properties like Q-Server url or access tokens can be reset by using option `-r` or `--reset`
229
-
230
- ```bash
231
- Q update-item -r
232
- ```
233
-
234
- - Credentials can be provided as environment variables to avoid user prompts. The variable names are `Q_ENV_SERVER`, `Q_ENV_USERNAME`, `Q_ENV_PASSWORD`, `Q_ENV_ACCESSTOKEN`, where `ENV` is the uppercase version of the environment name.
235
-
236
- ```bash
237
- Q_TEST_SERVER=[server_route] Q_TEST_USERNAME=[username] Q_TEST_PASSWORD=[password] Q update-item
238
- ```
239
-
240
- or
241
-
242
- ```bash
243
- Q_TEST_SERVER=[server_route] Q_TEST_ACCESSTOKEN=[accessToken] Q update-item
244
- ```
245
-
246
- The config file has to follow [this json-schema](./bin/commands/qItem/updateItem/updateSchema.json). This schema will be extended by the respective tool schema of your Q item.
247
- Here's an example:
248
-
249
- ```json
250
- {
251
- "items": [
252
- {
253
- "environments": [
254
- // "environments" references the desired q items to be updated, at least 1 environment is required
255
- {
256
- "name": "production",
257
- "id": "6dcf203a5c5f74b61aeea0cb0eef7e0b" // Id of your q item in the production environment
258
- },
259
- {
260
- "name": "staging",
261
- "id": "6dcf203a5c5f74b61aeea0cb0ef2ca9f" // Id of your q item in the staging environment
262
- }
263
- ],
264
- "item": {
265
- // The actual content you want to update for your referenced q items listed in "environments"
266
- "title": "Der Konsum in der Schweiz springt wieder an",
267
- "subtitle": "Wöchentliche Ausgaben mittels Bankkarten in Mio. Fr. im Jahr 2020, zum Vergleich 2019",
268
- "data": [
269
- // "data" represents the data table of your q item inside the q-editor
270
- ["Datum", "2020", "2019"],
271
- ["2020-01-06", "690004302", "641528028"],
272
- ["2020-01-13", "662122373", "617653790"],
273
- ["2020-01-20", "688208667", "654303249"]
274
- ]
275
- }
276
- }
277
- ]
278
- }
279
- ```
280
-
281
- #### Copy existing Q items
282
-
283
- Once `Q` cli installed one can copy one or many Q items by executing:
284
-
285
- ```bash
286
- Q copy-item
287
- ```
288
-
289
- - The path to the config file can be set by using option `-c` or `--config`. By default the `copy-item` command will look for a config file called `q.config.json` in the current directory
290
-
291
- ```bash
292
- Q copy-item -c [path]
293
- ```
294
-
295
- - Items of a specified environment can be updated by using the option `-e` or `--environment`. By default the `copy-item` command updates all item specified in the config file
296
-
297
- ```bash
298
- Q copy-item -e [env]
299
- ```
300
-
301
- - Stored configuration properties like Q-Server url or access tokens can be reset by using option `-r` or `--reset`
302
-
303
- ```bash
304
- Q copy-item -r
305
- ```
306
-
307
- - Credentials can be provided as environment variables to avoid user prompts. The variable names are `Q_ENV_SERVER`, `Q_ENV_USERNAME`, `Q_ENV_PASSWORD`, `Q_ENV_ACCESSTOKEN`, where `ENV` is the uppercase version of the environment name.
308
-
309
- ```bash
310
- Q_TEST_SERVER=[server_route] Q_TEST_USERNAME=[username] Q_TEST_PASSWORD=[password] Q update-item
311
- ```
312
-
313
- or
314
-
315
- ```bash
316
- Q_TEST_SERVER=[server_route] Q_TEST_ACCESSTOKEN=[accessToken] Q update-item
317
- ```
318
-
319
- The config file has to follow [this json-schema](./bin/commands/qItem/updateItem/updateSchema.json). This schema will be extended by the respective tool schema of your Q item.
320
- Here's an example:
321
-
322
- ```json
323
- {
324
- "items": [
325
- {
326
- "environments": [
327
- {
328
- "name": "production",
329
- "id": "6dcf203a5c5f74b61aeea0cb0eef7e0b" // Id of your q item in the production environment
330
- },
331
- {
332
- "name": "staging",
333
- "id": "6dcf203a5c5f74b61aeea0cb0ef2ca9f" // Id of your q item in the staging environment
334
- }
335
- ],
336
- "item": {
337
- "title": "Russische Angriffe auf die Ukraine",
338
- "subtitle": "Verzeichnete Angriffe in der ganzen Ukraine",
339
- "files": [
340
- // Adds or overwrites the listed files in your q item
341
- {
342
- "loadSyncBeforeInit": false, // Has to be set for the file upload to work
343
- "file": {
344
- "path": "./angriffsFlaechen.json" // Your local path to your file. The path is relative to where you execute the command.
345
- }
346
- }
347
- ]
348
- }
349
- }
350
- ]
351
- }
352
- ```
353
-
354
- [to the top](#table-of-contents)
355
-
356
- ## License
357
-
358
- Copyright (c) Neue Zürcher Zeitung.
359
-
360
- This software is licensed under the [MIT](LICENSE) License.
@@ -1,68 +0,0 @@
1
- const fs = require("fs-extra");
2
- const path = require("path");
3
- const replaceInFile = require("replace-in-file");
4
- const chalk = require("chalk");
5
- const errorColor = chalk.red;
6
- const successColor = chalk.green;
7
- const warningColor = chalk.yellow;
8
-
9
- /**
10
- *
11
- * @param {string} type - Skeleton type
12
- * @param {string} name - Name of the project
13
- * @param {string} basedir - Base directory name to be created
14
- * @param {Array.<{regex: RegExp, replaceWith: string}>} textReplacements
15
- */
16
- module.exports = async function (type, basedir, textReplacements) {
17
- if (fs.existsSync(basedir)) {
18
- console.error(
19
- errorColor(`directory ${basedir} already exists or is not writable`)
20
- );
21
- process.exit(1);
22
- } else {
23
- fs.mkdirSync(basedir);
24
- }
25
-
26
- try {
27
- await fs.copySync(
28
- path.join(__dirname, `../../skeletons/${type}-skeleton`),
29
- basedir
30
- );
31
-
32
- if (textReplacements) {
33
- for (const txtRe of textReplacements) {
34
- await replaceText(txtRe.regex, txtRe.replaceWith, basedir);
35
- }
36
- }
37
-
38
- console.log(successColor(`Q ${type} is now bootstrapped in ${basedir}`));
39
-
40
- if (type === "tool" || type === "et-utils-package")
41
- console.log(
42
- warningColor(
43
- "Search for 'TODO' inside the new tool/package to get started!"
44
- )
45
- );
46
- } catch (error) {
47
- console.error(
48
- errorColor(
49
- `An unexpected error occurred. Please check the entered information and try again. ${JSON.stringify(
50
- error
51
- )}`
52
- )
53
- );
54
- }
55
- };
56
-
57
- async function replaceText(regex, replaceWith, basedir) {
58
- const replaceOptions = {
59
- files: `${basedir}/**`, // Replace in all files
60
- from: regex,
61
- to: replaceWith,
62
- glob: {
63
- dot: true, // Include file names starting with a dot
64
- },
65
- };
66
-
67
- return await replaceInFile(replaceOptions);
68
- }
@@ -1,144 +0,0 @@
1
- const helpers = require("./helpers.js");
2
- const promptly = require("promptly");
3
- const Configstore = require("configstore");
4
- const package = require("./../../../package.json");
5
- const configStore = new Configstore(package.name, {});
6
- const chalk = require("chalk");
7
- const errorColor = chalk.red;
8
-
9
- async function setAuthenticationConfig(environment, qServer) {
10
- const result = await authenticate(environment, qServer);
11
- configStore.set(`${environment}.accessToken`, result.accessToken);
12
- configStore.set(`${environment}.cookie`, result.cookie);
13
- }
14
-
15
- async function setupStore(qConfig, environmentFilter, reset) {
16
- if (reset) {
17
- configStore.clear();
18
- }
19
- for (const environment of helpers.getEnvironments(
20
- qConfig,
21
- environmentFilter
22
- )) {
23
- await setupConfigFromEnvVars(environment);
24
-
25
- if (!configStore.get(`${environment}.qServer`)) {
26
- const qServer = await promptly.prompt(
27
- `Enter the Q-Server url for ${environment} environment: `,
28
- {
29
- validator: (qServer) => {
30
- return new URL(qServer).toString();
31
- },
32
- retry: true,
33
- }
34
- );
35
- configStore.set(`${environment}.qServer`, qServer);
36
- }
37
-
38
- const qServer = configStore.get(`${environment}.qServer`);
39
- if (!configStore.get(`${environment}.accessToken`)) {
40
- await setAuthenticationConfig(environment, qServer);
41
- }
42
-
43
- const accessToken = configStore.get(`${environment}.accessToken`);
44
- const cookie = configStore.get(`${environment}.cookie`);
45
- const isAccessTokenValid = await helpers.checkValidityOfAccessToken(
46
- environment,
47
- qServer,
48
- accessToken,
49
- cookie
50
- );
51
-
52
- // Get a new access token in case its not valid anymore
53
- if (!isAccessTokenValid) {
54
- await setAuthenticationConfig(environment, qServer);
55
- }
56
- }
57
-
58
- return configStore;
59
- }
60
-
61
- async function setupConfigFromEnvVars(environment) {
62
- const environmentPrefix = environment.toUpperCase();
63
-
64
- const qServer = process.env[`Q_${environmentPrefix}_SERVER`];
65
- if (qServer) {
66
- configStore.set(`${environment}.qServer`, qServer);
67
- }
68
- const accessToken = process.env[`Q_${environmentPrefix}_ACCESSTOKEN`];
69
- const username = process.env[`Q_${environmentPrefix}_USERNAME`];
70
- const password = process.env[`Q_${environmentPrefix}_PASSWORD`];
71
- if (qServer && accessToken) {
72
- configStore.set(`${environment}.accessToken`, accessToken);
73
- } else if (qServer && username && password) {
74
- const cookie = configStore.get(`${environment}.cookie`);
75
- const result = await helpers.getAccessToken(
76
- environment,
77
- qServer,
78
- username,
79
- password,
80
- cookie
81
- );
82
-
83
- if (!result) {
84
- console.error(
85
- errorColor(
86
- `A problem occured while authenticating to the ${environment} environment using environment variables. Please check your credentials and try again.`
87
- )
88
- );
89
- process.exit(1);
90
- }
91
-
92
- configStore.set(`${environment}.accessToken`, result.accessToken);
93
- configStore.set(`${environment}.cookie`, result.cookie);
94
- }
95
- }
96
-
97
- async function authenticate(environment, qServer) {
98
- let username = configStore.get(`${environment}.username`);
99
- if (!username) {
100
- username = await promptly.prompt(
101
- `Enter your username on ${environment} environment: `,
102
- { validator: (username) => username.trim() }
103
- );
104
- configStore.set(`${environment}.username`, username);
105
- }
106
-
107
- const password = await promptly.password(
108
- `Enter your password on ${environment} environment: `,
109
- {
110
- validator: async (password) => password.trim(),
111
- replace: "*",
112
- }
113
- );
114
-
115
- const cookie = configStore.get(`${environment}.cookie`);
116
- let result = await helpers.getAccessToken(
117
- environment,
118
- qServer,
119
- username,
120
- password,
121
- cookie
122
- );
123
-
124
- while (!result) {
125
- console.error(
126
- errorColor(
127
- "A problem occured while authenticating. Please check your credentials and try again."
128
- )
129
- );
130
-
131
- result = await authenticate(environment, qServer);
132
-
133
- if (result.accessToken) {
134
- break;
135
- }
136
- }
137
-
138
- return result;
139
- }
140
-
141
- module.exports = {
142
- store: configStore,
143
- setupStore: setupStore,
144
- };
@@ -1,103 +0,0 @@
1
- const schemaService = require("./../schemaService.js");
2
- const configStore = require("./../configStore.js");
3
- const itemService = require("./../itemService.js");
4
- const fs = require("fs");
5
- const path = require("path");
6
- const chalk = require("chalk");
7
- const errorColor = chalk.red;
8
- const successColor = chalk.green;
9
-
10
- module.exports = async function (command) {
11
- try {
12
- const qConfigPath = path.resolve(command.config);
13
-
14
- if (fs.existsSync(qConfigPath)) {
15
- const qConfig = JSON.parse(fs.readFileSync(qConfigPath));
16
- const validationResult = schemaService.validateConfig(
17
- qConfig,
18
- "copyItem"
19
- );
20
-
21
- if (validationResult.isValid) {
22
- const config = await configStore.setupStore(
23
- qConfig,
24
- command.environment,
25
- command.reset
26
- );
27
-
28
- for (const item of itemService.getItems(qConfig, command.environment)) {
29
- for (const environment of item.environments) {
30
- const qServer = config.get(`${environment.name}.qServer`);
31
- const accessToken = config.get(`${environment.name}.accessToken`);
32
- const cookie = config.get(`${environment.name}.cookie`);
33
-
34
- const existingItem = await itemService.getItem(
35
- qServer,
36
- environment,
37
- accessToken,
38
- cookie
39
- );
40
-
41
- delete existingItem.updatedBy;
42
- delete existingItem.createdBy;
43
- delete existingItem.createdDate;
44
- delete existingItem._id;
45
- delete existingItem._rev;
46
-
47
- let newItem = await itemService.createItem(
48
- existingItem,
49
- environment,
50
- config
51
- );
52
- // Save for success message
53
- const newItemId = newItem._id;
54
- const existingItemId = environment.id;
55
-
56
- const hasOverwrites =
57
- item.item &&
58
- Object.keys(item.item).length > 0 &&
59
- Object.getPrototypeOf(item.item) === Object.prototype;
60
-
61
- if (hasOverwrites) {
62
- environment.id = newItemId;
63
-
64
- newItem = await itemService.updateItem(
65
- item.item,
66
- environment,
67
- config,
68
- qConfigPath
69
- );
70
- }
71
-
72
- if (newItem) {
73
- console.log(
74
- successColor(
75
- `Successfully copied item with id ${existingItemId} on ${environment.name} environment. Copied item id ${newItemId}`
76
- )
77
- );
78
- }
79
- }
80
- }
81
- } else {
82
- console.error(
83
- errorColor(
84
- `A problem occured while validating the config file: ${validationResult.errorsText}`
85
- )
86
- );
87
- process.exit(1);
88
- }
89
- } else {
90
- console.error(
91
- errorColor(
92
- "Couldn't find config file named q.config.json in the current directory. Create a config file in the current directory or pass the path to the config file with the option -c <path>"
93
- )
94
- );
95
- }
96
- } catch (error) {
97
- console.error(
98
- errorColor(
99
- `A problem occured while parsing the config file at ${command.config}. Please make sure it is valid JSON.`
100
- )
101
- );
102
- }
103
- };
@@ -1,37 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "title": "Q Config",
4
- "description": "Config used by the Q CLI to copy items",
5
- "type": "object",
6
- "properties": {
7
- "items": {
8
- "description": "Array of Q items",
9
- "type": "array",
10
- "minItems": 1,
11
- "items": {
12
- "type": "object",
13
- "properties": {
14
- "environments": {
15
- "type": "array",
16
- "minItems": 1,
17
- "items": {
18
- "type": "object",
19
- "properties": {
20
- "id": {
21
- "type": "string",
22
- "description": "Id of Q item"
23
- }
24
- },
25
- "required": ["id"]
26
- }
27
- },
28
- "item": {
29
- "type": "object"
30
- }
31
- },
32
- "required": ["environments", "item"]
33
- }
34
- }
35
- },
36
- "required": ["items"]
37
- }