@nzz/q-cli 1.8.2 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. package/bin/commands/bootstrap.js +0 -1
  2. package/bin/q.js +28 -3
  3. package/package.json +2 -2
  4. package/skeletons/et-utils-package-skeleton/README.md +5 -0
  5. package/skeletons/et-utils-package-skeleton/package.json +13 -10
  6. package/skeletons/et-utils-package-skeleton/scripts/package-fixup.sh +13 -0
  7. package/skeletons/et-utils-package-skeleton/test/tsconfig.json +4 -1
  8. package/skeletons/et-utils-package-skeleton/tsconfig-base.json +10 -0
  9. package/skeletons/et-utils-package-skeleton/tsconfig-cjs.json +8 -0
  10. package/skeletons/et-utils-package-skeleton/tsconfig.json +4 -5
  11. package/skeletons/toolv2-skeleton/.husky/pre-commit +6 -0
  12. package/skeletons/toolv2-skeleton/.nvmrc +1 -0
  13. package/skeletons/toolv2-skeleton/.prettierrc.cjs +15 -0
  14. package/skeletons/toolv2-skeleton/.travis.yml +30 -0
  15. package/skeletons/toolv2-skeleton/.vscode/settings.json +6 -0
  16. package/skeletons/toolv2-skeleton/Dockerfile +19 -0
  17. package/skeletons/toolv2-skeleton/LICENSE +21 -0
  18. package/skeletons/toolv2-skeleton/README.md +99 -0
  19. package/skeletons/toolv2-skeleton/dev.js +7 -0
  20. package/skeletons/toolv2-skeleton/index.js +39 -0
  21. package/skeletons/toolv2-skeleton/jest.config.ts +39 -0
  22. package/skeletons/toolv2-skeleton/nodemon.json +4 -0
  23. package/skeletons/toolv2-skeleton/package-lock.json +21382 -0
  24. package/skeletons/toolv2-skeleton/package.json +80 -0
  25. package/skeletons/toolv2-skeleton/resources/display-options-schema.json +11 -0
  26. package/skeletons/toolv2-skeleton/resources/locales/de/translation.json +8 -0
  27. package/skeletons/toolv2-skeleton/resources/locales/en/translation.json +10 -0
  28. package/skeletons/toolv2-skeleton/resources/locales/fr/translation.json +10 -0
  29. package/skeletons/toolv2-skeleton/resources/schema.json +66 -0
  30. package/skeletons/toolv2-skeleton/rollup.config.js +48 -0
  31. package/skeletons/toolv2-skeleton/scripts/postinstall.sh +5 -0
  32. package/skeletons/toolv2-skeleton/src/.eslintrc.cjs +52 -0
  33. package/skeletons/toolv2-skeleton/src/components/Main.spec.ts +15 -0
  34. package/skeletons/toolv2-skeleton/src/components/Main.svelte +32 -0
  35. package/skeletons/toolv2-skeleton/src/enums.ts +11 -0
  36. package/skeletons/toolv2-skeleton/src/helpers/fixture-generators.ts +38 -0
  37. package/skeletons/toolv2-skeleton/src/helpers/toolRuntimeConfig.ts +15 -0
  38. package/skeletons/toolv2-skeleton/src/interfaces.ts +82 -0
  39. package/skeletons/toolv2-skeleton/src/modules.d.ts +8 -0
  40. package/skeletons/toolv2-skeleton/src/routes/dynamic-schemas/exampleDynamicSchema.ts +49 -0
  41. package/skeletons/toolv2-skeleton/src/routes/dynamic-schemas/index.ts +5 -0
  42. package/skeletons/toolv2-skeleton/src/routes/health.ts +14 -0
  43. package/skeletons/toolv2-skeleton/src/routes/locales.ts +31 -0
  44. package/skeletons/toolv2-skeleton/src/routes/notifications/exampleNotification.ts +46 -0
  45. package/skeletons/toolv2-skeleton/src/routes/option-availability.ts +27 -0
  46. package/skeletons/toolv2-skeleton/src/routes/rendering-info/web.ts +150 -0
  47. package/skeletons/toolv2-skeleton/src/routes/routes.ts +21 -0
  48. package/skeletons/toolv2-skeleton/src/routes/schema.ts +21 -0
  49. package/skeletons/toolv2-skeleton/src/routes/stylesheet.ts +31 -0
  50. package/skeletons/toolv2-skeleton/src/styles/main.scss +6 -0
  51. package/skeletons/toolv2-skeleton/svelte.config.cjs +6 -0
  52. package/skeletons/toolv2-skeleton/tasks/compileStyleFiles.cjs +101 -0
  53. package/skeletons/toolv2-skeleton/tests/e2e-tests.spec.ts +158 -0
  54. package/skeletons/toolv2-skeleton/tests/helpers.ts +21 -0
  55. package/skeletons/toolv2-skeleton/tsconfig.json +48 -0
  56. package/skeletons/et-utils-package-skeleton/rollup.config.js +0 -17
@@ -2,7 +2,6 @@ const fs = require("fs-extra");
2
2
  const path = require("path");
3
3
  const replaceInFile = require("replace-in-file");
4
4
  const chalk = require("chalk");
5
- const { replace } = require("nunjucks/src/filters");
6
5
  const errorColor = chalk.red;
7
6
  const successColor = chalk.green;
8
7
  const warningColor = chalk.yellow;
package/bin/q.js CHANGED
@@ -61,17 +61,42 @@ async function main() {
61
61
  )
62
62
  .description("bootstrap a new tool")
63
63
  .action(async (command) => {
64
- const name = command.args[0];
64
+ let name = command.args[0];
65
+
65
66
  if (!name) {
66
67
  console.error(errorColor("no toolname given"));
67
68
  process.exit(1);
68
69
  }
70
+
71
+ // Make sure the name matches the spec.
72
+ if (!name.match(/^(Q-|q-)\w+/g)) {
73
+ console.error(errorColor("Tool must be named according to this format: Q-[a-z+]"));
74
+ process.exit(1);
75
+ }
76
+
77
+ // Capitalize first letter.
78
+ name = name[0].toUpperCase() + name.substring(1).toLowerCase();
79
+
80
+ let nameNodashes = name.replace(/\-/g, '');
81
+ toolnameCamelCase = nameNodashes[0].toUpperCase() + nameNodashes[1].toUpperCase() + nameNodashes.substring(2);
82
+
69
83
  const baseDir = program.dir || name;
70
84
  const textReplacements = [
71
- { regex: new RegExp(`tool-skeleton`, "g"), replaceWith: name },
85
+ // deprecated.
86
+ { regex: /tool-skeleton/g, replaceWith: name },
87
+
88
+ // Replace all instance of tool name with underscore.
89
+ { regex: /\[tool_name\]/g, replaceWith: name.toLowerCase().replace(/\-/g, '_') },
90
+
91
+ // Replace all instances with minuses.
92
+ { regex: /\[Tool-name\]/g, replaceWith: name },
93
+ { regex: /\[tool-name\]/g, replaceWith: name.toLowerCase() },
94
+
95
+ // Replace all CamelCase instances.
96
+ { regex: /\[ToolName\]/g, replaceWith: toolnameCamelCase},
72
97
  ];
73
98
 
74
- await bootstrap("tool", baseDir, textReplacements);
99
+ await bootstrap("toolv2", baseDir, textReplacements);
75
100
  });
76
101
 
77
102
  program
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nzz/q-cli",
3
- "version": "1.8.2",
3
+ "version": "1.9.0",
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": {
@@ -40,4 +40,4 @@
40
40
  "promptly": "^3.2.0",
41
41
  "replace-in-file": "^3.4.4"
42
42
  }
43
- }
43
+ }
@@ -5,3 +5,8 @@
5
5
  ## Content
6
6
 
7
7
  TODO: Package documentation
8
+
9
+ ## Modules & Node support
10
+
11
+ The package follows a hybrid module structure, supporting ES6 & CommonJS Module imports.
12
+ Node support can be implemented by changing the internal, relative import statements to include the file type suffix `.js` (not `.ts`!). This however breaks the CommonJS Module imports (`require()`), which should not be an issue if Node 12+ is used in the project.
@@ -8,16 +8,21 @@
8
8
  "directory": "<package-name>"
9
9
  },
10
10
  "scripts": {
11
- "prepublishOnly": "npm run test && npm run clean && npm run build && rollup -c",
12
- "clean": "rimraf dist && rimraf index.js && rimraf index.d.ts",
13
- "build": "tsc -p .",
14
- "start": "npm run build -- -w",
11
+ "prepublishOnly": "npm run test && npm run clean && npm run buildMjs && npm run buildCjs && ./scripts/package-fixup.sh",
12
+ "clean": "rimraf dist",
13
+ "buildMjs": "tsc -p tsconfig.json",
14
+ "buildCjs": "tsc -p tsconfig-cjs.json",
15
+ "start": "npm run buildMjs -- -w",
15
16
  "test": "jest --config jest.config.ts"
16
17
  },
17
- "files": [
18
- "index.js",
19
- "index.d.ts"
20
- ],
18
+ "main": "dist/cjs/index.js",
19
+ "module": "dist/mjs/index.js",
20
+ "exports": {
21
+ ".": {
22
+ "import": "./dist/mjs/index.js",
23
+ "require": "./dist/cjs/index.js"
24
+ }
25
+ },
21
26
  "publishConfig": {
22
27
  "access": "public"
23
28
  },
@@ -26,8 +31,6 @@
26
31
  "@types/node": "^16.11.36",
27
32
  "jest": "^28.1.0",
28
33
  "rimraf": "^3.0.2",
29
- "rollup": "^2.75.0",
30
- "rollup-plugin-dts": "^4.2.2",
31
34
  "ts-jest": "^28.0.3",
32
35
  "ts-node": "^10.8.0",
33
36
  "typescript": "^4.6.4"
@@ -0,0 +1,13 @@
1
+ #Add external dependencies under 'dependencies'
2
+ cat >dist/cjs/package.json <<!EOF
3
+ {
4
+ "type": "commonjs"
5
+ }
6
+ !EOF
7
+
8
+ #Add external dependencies under 'dependencies'
9
+ cat >dist/mjs/package.json <<!EOF
10
+ {
11
+ "type": "module"
12
+ }
13
+ !EOF
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "types": ["jest", "node"]
3
+ "moduleResolution": "node",
4
+ "types": ["jest", "node"],
5
+ "esModuleInterop": true,
6
+ "allowSyntheticDefaultImports": true
4
7
  }
5
8
  }
@@ -0,0 +1,10 @@
1
+ {
2
+ "include": ["src/**/*"],
3
+ "exclude": ["test/**/*"],
4
+ "compilerOptions": {
5
+ "declaration": true,
6
+ "moduleResolution": "node"
7
+ // "esModuleInterop": true,
8
+ // "allowSyntheticDefaultImports": true,
9
+ }
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "outDir": "dist/cjs",
6
+ "target": "es2015"
7
+ }
8
+ }
@@ -1,9 +1,8 @@
1
1
  {
2
- "include": ["src/**/*"],
3
- "exclude": ["test/**/*"],
2
+ "extends": "./tsconfig-base.json",
4
3
  "compilerOptions": {
5
- "target": "es6",
6
- "outDir": "dist",
7
- "declaration": true
4
+ "module": "esnext",
5
+ "outDir": "dist/mjs",
6
+ "target": "es6"
8
7
  }
9
8
  }
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npm run build
5
+
6
+ npm run prettier-format && npm run lint:all && npm run jest
@@ -0,0 +1 @@
1
+ 16
@@ -0,0 +1,15 @@
1
+ module.exports = {
2
+ arrowParens: 'avoid',
3
+ bracketSameLine: true,
4
+ bracketSpacing: true,
5
+ plugins: [require('prettier-plugin-svelte')],
6
+ printWidth: 160,
7
+ semi: true,
8
+ singleQuote: true,
9
+ svelteIndentScriptAndStyle: false,
10
+ svelteSortOrder: 'options-scripts-markup-styles',
11
+ svelteStrictMode: false,
12
+ tabWidth: 2,
13
+ trailingComma: 'all',
14
+ useTabs: false,
15
+ };
@@ -0,0 +1,30 @@
1
+ dist: trusty
2
+ sudo: true
3
+ services:
4
+ - docker
5
+ language: node_js
6
+ node_js:
7
+ - '16'
8
+ cache:
9
+ directories:
10
+ - node_modules
11
+ install:
12
+ - npm set-script postinstall ""
13
+ - npm install
14
+ before_script:
15
+ - DOCKER_IMAGE_NAME="[tool-name]"
16
+ - DOCKER_TAG=${TRAVIS_BRANCH//[^a-zA-Z0-9\_\-\.]/_}
17
+ script:
18
+ - npm run lint
19
+ - npm run ts-check
20
+ - npm run svelte-check
21
+ - npm run build
22
+ - npm run jest
23
+ - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then docker build -t $DOCKER_IMAGE_NAME:$DOCKER_TAG .; fi'
24
+ after_success:
25
+ - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then echo $DOCKER_PASSWORD | docker login -u="$DOCKER_USERNAME" --password-stdin; docker tag $DOCKER_IMAGE_NAME:$DOCKER_TAG nzzonline/$DOCKER_IMAGE_NAME:$DOCKER_TAG; docker push nzzonline/$DOCKER_IMAGE_NAME:$DOCKER_TAG; fi'
26
+
27
+ # TODO: Create token for slack notifications, then insert below & uncomment lines
28
+ #notifications:
29
+ #slack:
30
+ #secure: <Slack-Token>
@@ -0,0 +1,6 @@
1
+ {
2
+ "editor.tabSize": 2,
3
+ "[svelte]": {
4
+ "editor.defaultFormatter": "svelte.svelte-vscode"
5
+ }
6
+ }
@@ -0,0 +1,19 @@
1
+ # Use following version of node alpine as the base image
2
+ FROM node:16-alpine
3
+
4
+ # Set work directory for run/cmd
5
+ WORKDIR /app
6
+
7
+ # Copy package.json and package-lock.json into work directory and install dependencies
8
+ COPY package.json /app/package.json
9
+ COPY package-lock.json /app/package-lock.json
10
+ RUN npm install --production
11
+
12
+ # Copy everthing else in work directory
13
+ COPY . /app
14
+
15
+ # Expose server port
16
+ EXPOSE 3000
17
+
18
+ # Run node
19
+ CMD node index.js
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) NZZ Management AG
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,99 @@
1
+ # [tool-name] <travis-badge>
2
+
3
+ **maintainer**: <maintainer>
4
+
5
+ Short description of tool and link to either [demo](https://editor.q.tools/) or [playground](https://q-playground.st.nzz.ch).
6
+
7
+ ## Table of contents
8
+
9
+ - [Installation](#installation)
10
+ - [Configuration](#configuration)
11
+ - [Development](#development)
12
+ - [Watching files](#watching-files-dev)
13
+ - [Testing](#testing)
14
+ - [Deployment](#deployment)
15
+ - [Functionality](#functionality)
16
+ - [License](#license)
17
+
18
+ ## Installation
19
+
20
+ ```
21
+ nvm use
22
+ npm install
23
+ npm start
24
+ ```
25
+
26
+ [to the top](#table-of-contents)
27
+
28
+ ## Configuration
29
+
30
+ If env variables, explained here
31
+
32
+ ## Development
33
+
34
+ Start the Q dev server:
35
+
36
+ ```
37
+ npx @nzz/q-cli server
38
+ ```
39
+
40
+ Run the Q tool:
41
+
42
+ ```
43
+ npm start
44
+ ```
45
+
46
+ ## Watching files (DEV)
47
+
48
+ Please see nodemon.json for a specific list of extension that trigger a rebuilt when changed in development. You can extend this list at your liking.
49
+
50
+ [to the top](#table-of-contents)
51
+
52
+ ## Testing
53
+
54
+ Run the tests:
55
+
56
+ ```
57
+ npm run test
58
+ ```
59
+
60
+ ### Implementing a new test
61
+
62
+ When changing or implementing...
63
+
64
+ - A `route`, it needs to be tested in the `tests/e2e-tests.js` file.
65
+ - Something on the frontend, it needs to be tested in it's own `***.spec.ts` file.
66
+
67
+ [to the top](#table-of-contents)
68
+
69
+ ## Deployment
70
+
71
+ We provide automatically built docker images at https://hub.docker.com/r/nzzonline/[tool-name]/.
72
+ There are three options for deployment:
73
+
74
+ - Use the provided images
75
+ - Build your own docker images
76
+ - Deploy the service using another technology
77
+
78
+ ### Use the provided docker images
79
+
80
+ 1. Deploy `nzzonline/[tool-name]` to a docker environment
81
+ 2. Set the ENV variables as described in the [configuration section](#configuration)
82
+
83
+ [to the top](#table-of-contents)
84
+
85
+ ## Functionality
86
+
87
+ The tool structure follows the general structure of each Q tool. Further information can be found in [Q server documentation - Developing tools](https://nzzdev.github.io/Q-server/developing-tools.html).
88
+
89
+ [to the top](#table-of-contents)
90
+
91
+ ### Options
92
+
93
+ All options should be listed and explained. The varieties should be listed. If there's a visual aspect, a printscreen would be nice. The options should be listed as they are named in the `schema`
94
+
95
+ [to the top](#table-of-contents)
96
+
97
+ ## License (if open source)
98
+
99
+ Adding the license + updating the year.
@@ -0,0 +1,7 @@
1
+ process.env.METHOD_BOX_ARTICLE = `{
2
+ "title": "Mehr zur Datenberechnung der NZZ",
3
+ "url": "https://www.nzz.ch/ld.1580452"
4
+ }`;
5
+
6
+
7
+ import './index.js';
@@ -0,0 +1,39 @@
1
+ import Hapi from '@hapi/hapi';
2
+ import routes from './dist/routes.js';
3
+
4
+ // Because the package is set as module we cannot directly call require
5
+ // in js files. We must import and create it.
6
+ import { createRequire } from 'module';
7
+ const require = createRequire(import.meta.url);
8
+
9
+ const server = Hapi.server({
10
+ port: process.env.PORT || 3000,
11
+ });
12
+
13
+ async function init() {
14
+ await server.register(require('@hapi/inert'));
15
+ server.validator(require('joi'));
16
+
17
+ server.route(routes);
18
+
19
+ await server.start();
20
+ console.log('server running ', server.info.uri);
21
+ }
22
+
23
+ init();
24
+
25
+ async function gracefullyStop() {
26
+ console.log('stopping hapi server');
27
+ try {
28
+ await server.stop({ timeout: 10000 });
29
+ console.log('hapi server stopped');
30
+ } catch (err) {
31
+ console.log(err);
32
+ process.exit(1);
33
+ }
34
+ process.exit(0);
35
+ }
36
+
37
+ // listen on SIGINT and SIGTERM signal and gracefully stop the server.
38
+ process.on('SIGINT', gracefullyStop);
39
+ process.on('SIGTERM', gracefullyStop);
@@ -0,0 +1,39 @@
1
+ // Testing with Svelte + TS + ESM + Jest requires quite the setup.
2
+ // https://github.com/svelteness/svelte-jester/issues/72#issuecomment-1021356664
3
+
4
+ import type { Config } from '@jest/types';
5
+
6
+ const config: Config.InitialOptions = {
7
+ preset: 'ts-jest/presets/default-esm',
8
+ testEnvironment: 'jsdom',
9
+ verbose: true,
10
+ transform: {
11
+ '^.+\\.ts$': 'ts-jest',
12
+ '^.+\\.svelte$': [
13
+
14
+ // This line is very important for it to work with ESM modules
15
+ './node_modules/svelte-jester/dist/transformer.mjs',
16
+ {
17
+ preprocess: true,
18
+ },
19
+ ],
20
+ },
21
+ extensionsToTreatAsEsm: ['.svelte', '.ts'],
22
+ moduleFileExtensions: ['js', 'ts', 'svelte'],
23
+ globals: {
24
+ 'ts-jest': {
25
+ useESM: true,
26
+ },
27
+ },
28
+ moduleNameMapper: {
29
+ '^(\\.{1,2}/.*)\\.js$': '$1',
30
+ '^@rs(.*)$': '<rootDir>/resources$1',
31
+ '^@src(.*)$': '<rootDir>/src$1',
32
+ },
33
+ testPathIgnorePatterns: ['node_modules'],
34
+ transformIgnorePatterns: ['node_modules'],
35
+ bail: false,
36
+ setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
37
+ };
38
+
39
+ export default config;
@@ -0,0 +1,4 @@
1
+ {
2
+ "watch": ["src/**/*", "resources/**/*"],
3
+ "ext": "ts, js, css, svelte, json"
4
+ }