@nutin/cli 1.2.0 → 1.2.1

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 (79) hide show
  1. package/CHANGELOG.md +63 -30
  2. package/README.md +9 -8
  3. package/lib/index.mjs +6 -6
  4. package/lib/src/file-generator.mjs +18 -5
  5. package/lib/src/package-manager.mjs +33 -21
  6. package/lib/src/prompts.mjs +2 -2
  7. package/lib/src/utils.mjs +2 -0
  8. package/package.json +4 -3
  9. package/templates/base/.dockerignore.hbs +2 -1
  10. package/templates/base/builder.config.js.hbs +28 -0
  11. package/templates/base/src/app/components/common/anchor/anchor.component.ts.hbs +11 -12
  12. package/templates/base/src/app/dom.test.js.hbs +8 -1
  13. package/templates/base/src/core/base-classes/base-component/helpers/event.helper.ts.hbs +3 -0
  14. package/templates/base/src/core/base-classes/base-component/helpers/pipe.helper.ts.hbs +3 -0
  15. package/templates/base/src/core/base-classes/base-component/helpers/token.helper.ts.hbs +2 -2
  16. package/templates/base/src/core/services/router/helpers/navigation-manager.helper.ts.hbs +3 -3
  17. package/templates/base/src/core/services/router/helpers/route-guard-manager.helper.ts.hbs +2 -2
  18. package/templates/base/src/core/utils/anchor-manager/anchor-manager.utils.ts.hbs +4 -3
  19. package/templates/base/src/core/utils/button-manager/button-manager.utils.test.js.hbs +1 -1
  20. package/templates/base/src/index.html.hbs +1 -0
  21. package/templates/base/src/styles/main.scss.hbs +2 -0
  22. package/templates/base/tools/builder/builder.js.hbs +10 -7
  23. package/templates/base/tools/builder/core/copy-static.js.hbs +27 -2
  24. package/templates/base/tools/builder/core/esbuild.js.hbs +5 -15
  25. package/templates/base/tools/builder/core/finalize-build.js.hbs +2 -2
  26. package/templates/base/tools/builder/core/minify-html.js.hbs +2 -2
  27. package/templates/base/tools/builder/core/{sass.config.js.hbs → sass.js.hbs} +5 -7
  28. package/templates/base/tools/builder/core/tsc.js.hbs +8 -4
  29. package/templates/base/tools/builder/core/validate-html.js.hbs +19 -14
  30. package/templates/base/tools/deployment/Dockerfile.hbs +22 -0
  31. package/templates/base/tools/deployment/gzip.conf.hbs +19 -0
  32. package/templates/base/tools/deployment/nginx.conf.hbs +78 -0
  33. package/templates/base/tools/dev/dev-serve.js.hbs +32 -0
  34. package/templates/base/tools/{watcher.js.hbs → dev/watcher.js.hbs} +1 -1
  35. package/templates/base/tools/generator/generator.js.hbs +13 -5
  36. package/templates/base/tools/generator/handle-file.js.hbs +15 -8
  37. package/templates/base/tools/utils/export-flags.js.hbs +2 -1
  38. package/templates/base/tools/utils/index.js.hbs +4 -1
  39. package/templates/base/tools/utils/run-command.js.hbs +10 -3
  40. package/templates/base/tools/utils/run-script.js.hbs +1 -1
  41. package/templates/features/i18n/src/core/config.ts.hbs +3 -0
  42. package/templates/features/i18n/src/core/services/i18n/i18n.test.js.hbs +2 -0
  43. package/templates/features/i18n/src/core/services/i18n/i18n.ts.hbs +10 -1
  44. package/templates/features/i18n/src/core/services/i18n/languages.ts.hbs +7 -0
  45. package/templates/features/i18n/tools/builder/core/build-i18n.js.hbs +2 -2
  46. package/templates/features/i18n/tools/utils/languages.js.hbs +7 -0
  47. package/templates/features/stylinNutin/src/styles/components/_index.scss.hbs +0 -3
  48. package/templates/features/stylinNutin/src/styles/views/_index.scss.hbs +0 -0
  49. package/templates/features/template/tools/builder/core/merge-templates.js.hbs +1 -1
  50. package/templates/features/testinNutin/{test → testin-nutin}/core/index.js.hbs +1 -1
  51. package/templates/features/testinNutin/testin-nutin/core/src/globals/assertion-lib.js.hbs +136 -0
  52. package/templates/features/testinNutin/testin-nutin/core/src/globals/jsdom-setup.js.hbs +101 -0
  53. package/templates/features/testinNutin/{test → testin-nutin}/core/src/globals/register-test-globals.js.hbs +15 -1
  54. package/templates/features/testinNutin/testin-nutin/core/src/globals/spyon.js.hbs +59 -0
  55. package/templates/features/testinNutin/{test → testin-nutin}/core/src/utils/print.js.hbs +3 -1
  56. package/templates/features/testinNutin/{test → testin-nutin}/core/src/utils/test-discovery.js.hbs +5 -1
  57. package/templates/features/testinNutin/{test → testin-nutin}/core/src/utils/test-queue.js.hbs +3 -1
  58. package/templates/features/testinNutin/{test → testin-nutin}/core/tests/assertions.test.js.hbs +26 -2
  59. package/templates/features/testinNutin/testin-nutin/runner.js.hbs +35 -0
  60. package/templates/features/testinNutin/{test → testin-nutin}/watch-tests.js.hbs +1 -1
  61. package/templates/features/testinNutin/testin-nutin.config.js.hbs +14 -0
  62. package/templates/base/Dockerfile.hbs +0 -33
  63. package/templates/base/nginx.conf.hbs +0 -43
  64. package/templates/base/tools/builder/docs.md.hbs +0 -9
  65. package/templates/base/tools/dev.js.hbs +0 -43
  66. package/templates/features/testinNutin/test/core/src/globals/assertion-lib.js.hbs +0 -118
  67. package/templates/features/testinNutin/test/core/src/globals/spyon.js.hbs +0 -22
  68. package/templates/features/testinNutin/test/core/src/jsdom-setup.js.hbs +0 -12
  69. package/templates/features/testinNutin/test/docs.md.hbs +0 -39
  70. package/templates/features/testinNutin/test/runner.js.hbs +0 -36
  71. /package/templates/base/tools/{serve.js.hbs → dev/serve.js.hbs} +0 -0
  72. /package/templates/features/testinNutin/{test → testin-nutin}/core/src/utils/queue.js.hbs +0 -0
  73. /package/templates/features/testinNutin/{test → testin-nutin}/core/tests/globals-each-all.test.js.hbs +0 -0
  74. /package/templates/features/testinNutin/{test → testin-nutin}/mocks/create-mock-method.js.hbs +0 -0
  75. /package/templates/features/testinNutin/{test → testin-nutin}/mocks/mock-event-bus.js.hbs +0 -0
  76. /package/templates/features/testinNutin/{test → testin-nutin}/mocks/mock-http-client.js.hbs +0 -0
  77. /package/templates/features/testinNutin/{test → testin-nutin}/mocks/mock-i18n.js.hbs +0 -0
  78. /package/templates/features/testinNutin/{test → testin-nutin}/mocks/mock-router.js.hbs +0 -0
  79. /package/templates/features/testinNutin/{test → testin-nutin}/mocks/mock-store.js.hbs +0 -0
@@ -1,118 +0,0 @@
1
- global.expect = (actual) => {
2
- const expectObj = {
3
- toBe(expected) {
4
- if (actual != expected) {
5
- throw new Error(`Expected ${actual} to be ${expected}`);
6
- }
7
- },
8
- toEqual(expected) {
9
- if (actual !== expected) {
10
- throw new Error(`Expected ${actual} to be ${expected}`);
11
- }
12
- },
13
- toContain(substring) {
14
- if (!actual.includes(substring)) {
15
- throw new Error(`Expected '${actual}' to contain '${substring}'`);
16
- }
17
- },
18
- toBeDefined() {
19
- if (actual === null || actual === undefined) {
20
- throw new Error(`Expected value to be defined, but got ${actual}`);
21
- }
22
- },
23
- toBeUndefined() {
24
- if (actual !== null && actual !== undefined) {
25
- throw new Error(`Expected value to be undefined, but got ${actual}`);
26
- }
27
- },
28
- toBeInstanceOf(constructor) {
29
- if (!(actual instanceof constructor)) {
30
- throw new Error(`Expected ${actual} to be instance of ${constructor.name}`);
31
- }
32
- },
33
- toHaveBeenCalled() {
34
- if (!actual?.calls || actual.calls.length === 0) {
35
- throw new Error(`Expected function to have been called, but it was not`);
36
- }
37
- },
38
- toHaveBeenCalledWith(...expectedArgs) {
39
- const matched = actual?.calls?.some(args =>
40
- args.length === expectedArgs.length &&
41
- args.every((arg, i) => arg === expectedArgs[i])
42
- );
43
- if (!matched) {
44
- throw new Error(`Expected function to have been called with ${JSON.stringify(expectedArgs)}, but it was not`);
45
- }
46
- },
47
- toBeLessThan(expected) {
48
- if (actual > expected) {
49
- throw new Error(`Expected ${actual} to be less than ${expected}`)
50
- }
51
- },
52
- toBeGreaterThan(expected) {
53
- if (actual < expected) {
54
- throw new Error(`Expected ${actual} to be greater than ${expected}`)
55
- }
56
- }
57
- };
58
-
59
- // 'not' variants
60
- expectObj.not = {
61
- toBe(expected) {
62
- if (actual == expected) {
63
- throw new Error(`Expected ${actual} not to be ${expected}`);
64
- }
65
- },
66
- toEqual(expected) {
67
- if (actual === expected) {
68
- throw new Error(`Expected ${actual} not to be ${expected}`);
69
- }
70
- },
71
- toContain(substring) {
72
- if (actual.includes(substring)) {
73
- throw new Error(`Expected '${actual}' not to contain '${substring}'`);
74
- }
75
- },
76
- toBeDefined() {
77
- if (actual !== null && actual !== undefined) {
78
- throw new Error(`Expected value to be undefined, but got ${actual}`);
79
- }
80
- },
81
- toBeUndefined() {
82
- if (actual === null || actual === undefined) {
83
- throw new Error(`Expected value to be defined, but got ${actual}`);
84
- }
85
- },
86
- toBeInstanceOf(constructor) {
87
- if (actual instanceof constructor) {
88
- throw new Error(`Expected ${actual} not to be instance of ${constructor.name}`);
89
- }
90
- },
91
- toHaveBeenCalled() {
92
- if (actual?.calls && actual.calls.length > 0) {
93
- throw new Error(`Expected function not to have been called, but it was`);
94
- }
95
- },
96
- toHaveBeenCalledWith(...expectedArgs) {
97
- const matched = actual?.calls?.some(args =>
98
- args.length === expectedArgs.length &&
99
- args.every((arg, i) => arg === expectedArgs[i])
100
- );
101
- if (matched) {
102
- throw new Error(`Expected function not to have been called with ${JSON.stringify(expectedArgs)}, but it was`);
103
- }
104
- },
105
- toBeLessThan(expected) {
106
- if (actual < expected) {
107
- throw new Error(`Expected ${actual} not to be less than ${expected}`)
108
- }
109
- },
110
- toBeGreaterThan(expected) {
111
- if (actual > expected) {
112
- throw new Error(`Expected ${actual} not to be greater than ${expected}`)
113
- }
114
- }
115
- };
116
-
117
- return expectObj;
118
- };
@@ -1,22 +0,0 @@
1
- global.spyOn = (obj, methodName) => {
2
- const originalFn = obj[methodName];
3
-
4
- const calls = [];
5
- const spy = function (...args) {
6
- calls.push(args);
7
- return originalFn.apply(this, args);
8
- };
9
-
10
- spy.calls = calls;
11
-
12
- obj[methodName] = spy;
13
-
14
- return {
15
- restore() {
16
- obj[methodName] = originalFn;
17
- },
18
- get calls() {
19
- return calls;
20
- }
21
- };
22
- };
@@ -1,12 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { JSDOM } from 'jsdom';
4
-
5
- export function setupJsdomEnvironment(htmlPath = 'dist/src/index.html') {
6
- const html = fs.readFileSync(path.resolve(process.cwd(), htmlPath), 'utf8');
7
- const dom = new JSDOM(html, { url: 'http://localhost' });
8
-
9
- global.window = dom.window;
10
- global.document = dom.window.document;
11
- global.localStorage = dom.window.localStorage;
12
- }
@@ -1,39 +0,0 @@
1
- # testin-nutin
2
-
3
- ***The test runner uses a Queue data structure, for which all credit goes to ThePrimeagen and his [amazing Data Structures and Algorithms course on frontendmasters.com](https://frontendmasters.com/courses/algorithms/)***
4
-
5
- ## Run tests
6
-
7
- The code needs to be compiled for the tests to run.
8
-
9
- ```sh
10
- npm run test
11
- npm run test:watch # NOTE: will rerun all tests on change.
12
- npm run test--rebuild # = npm run build && npm run test
13
- ```
14
- Accepts a filter argument *ex: e2e, unit, file-name*.
15
-
16
- ## Built-in features (minimalistic)
17
-
18
- - *Test globals* : describe, it, beforeEach/All, afterEach/All.
19
-
20
- - *Assertions library* : toBe(), toContain(string), toBeDefined, toBeUndefined, toBeInstanceOf(instance).
21
- All assertions can be used with `not.` prefix.
22
-
23
- - *JSDOM initial setup for DOM testing*.
24
-
25
- - *HTTP client mock* (In progress)
26
-
27
- - *Automated tests discovery* : Recursively scans e2e/ unit/ and utils/ folders for .test.js files.
28
-
29
- It is always possible to add new paths in test/runner.js `testFiles` array (`...getTestFiles('path/to/folder')`) or remove one to disable its tests.
30
-
31
- - *mini-chalk* to color console outputs.
32
-
33
- ## How to use
34
-
35
- Syntax is very similar to Jest, only with way less features.
36
- Import statements from 'dist' folder can be simplified by using `#root/dist/src` and by regrouping exports in indexes.
37
- Please refer to examples in utils/\*.test.js and unit/i18n.test.js.
38
-
39
- [**Back to index**](../README.md)
@@ -1,36 +0,0 @@
1
- import { setupJsdomEnvironment, registerTestGlobals, getTestFiles, runQueuedTests, print } from './core/index.js';
2
-
3
- setupJsdomEnvironment();
4
- registerTestGlobals();
5
-
6
- let testFiles = [
7
- // globals & assertions
8
- // ...getTestFiles('core/tests'),
9
- // toolkit core logic
10
- // ...getTestFiles('../src/core'),
11
- // built-in libs
12
- // ...getTestFiles('../src/libs'),
13
- // actual application code
14
- ...getTestFiles('../src/app')
15
- ];
16
-
17
- const args = process.argv.slice(2);
18
- if (args.length) {
19
- testFiles = testFiles.filter(file => args.some(f => file.includes(f)));
20
- }
21
-
22
- async function runTests() {
23
- print.head('Test suites :');
24
- for (const file of testFiles) {
25
- try {
26
- await import(file);
27
- } catch (error) {
28
- print.boldError(`✗ ${file} failed to load:`);
29
- print.grayError(error.stack);
30
- }
31
- }
32
-
33
- await runQueuedTests();
34
- }
35
-
36
- runTests();