@whook/create 9.0.1 → 10.0.0

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 (42) hide show
  1. package/README.md +2 -2
  2. package/bin/create.js +2 -2
  3. package/dist/index.js +46 -68
  4. package/dist/index.js.map +1 -1
  5. package/dist/services/author.js +46 -72
  6. package/dist/services/author.js.map +1 -1
  7. package/dist/services/author.test.js +86 -92
  8. package/dist/services/author.test.js.map +1 -1
  9. package/dist/services/createWhook.d.ts +8 -11
  10. package/dist/services/createWhook.js +124 -144
  11. package/dist/services/createWhook.js.map +1 -1
  12. package/dist/services/createWhook.test.js +392 -506
  13. package/dist/services/createWhook.test.js.map +1 -1
  14. package/dist/services/project.d.ts +2 -2
  15. package/dist/services/project.js +40 -62
  16. package/dist/services/project.js.map +1 -1
  17. package/dist/services/project.test.js +73 -80
  18. package/dist/services/project.test.js.map +1 -1
  19. package/package.json +46 -92
  20. package/src/index.ts +23 -17
  21. package/src/services/__snapshots__/author.test.ts.snap +3 -3
  22. package/src/services/__snapshots__/createWhook.test.ts.snap +4 -4
  23. package/src/services/author.test.ts +8 -6
  24. package/src/services/author.ts +2 -2
  25. package/src/services/createWhook.test.ts +197 -312
  26. package/src/services/createWhook.ts +12 -12
  27. package/src/services/project.test.ts +11 -6
  28. package/src/services/project.ts +3 -2
  29. package/dist/index.mjs +0 -47
  30. package/dist/index.mjs.map +0 -1
  31. package/dist/services/author.mjs +0 -63
  32. package/dist/services/author.mjs.map +0 -1
  33. package/dist/services/author.test.mjs +0 -94
  34. package/dist/services/author.test.mjs.map +0 -1
  35. package/dist/services/createWhook.mjs +0 -135
  36. package/dist/services/createWhook.mjs.map +0 -1
  37. package/dist/services/createWhook.test.mjs +0 -834
  38. package/dist/services/createWhook.test.mjs.map +0 -1
  39. package/dist/services/project.mjs +0 -50
  40. package/dist/services/project.mjs.map +0 -1
  41. package/dist/services/project.test.mjs +0 -80
  42. package/dist/services/project.test.mjs.map +0 -1
@@ -1,834 +0,0 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
- import initCreateWhook from './createWhook';
8
- import YError from 'yerror'; // eslint-disable-next-line
9
-
10
- const _packageJSON = require('@whook/example/package.json');
11
-
12
- describe('initCreateWhook', () => {
13
- const CWD = '/home/whoiam/projects/';
14
- const SOURCE_DIR = '/var/lib/node/node_modules/whook-example';
15
-
16
- const packageJSON = _objectSpread(_objectSpread({}, _packageJSON), {}, {
17
- dependencies: _objectSpread(_objectSpread({}, _packageJSON.dependencies), {}, {
18
- '@whook/authorization': '<current_version>',
19
- '@whook/cli': '<current_version>',
20
- '@whook/cors': '<current_version>',
21
- '@whook/http-router': '<current_version>',
22
- '@whook/http-transaction': '<current_version>',
23
- '@whook/swagger-ui': '<current_version>',
24
- '@whook/whook': '<current_version>'
25
- })
26
- });
27
-
28
- const author = {
29
- name: 'Wayne Campbell',
30
- email: 'wayne@warner.com'
31
- };
32
- const project = {
33
- name: 'super-project',
34
- directory: '/home/whoiam/projects/yolo'
35
- };
36
- const writeFile = jest.fn();
37
- const readFile = jest.fn();
38
- const readdir = jest.fn();
39
- const exec = jest.fn();
40
- const copy = jest.fn();
41
- const axios = jest.fn();
42
- const ora = jest.fn();
43
- const oraInstance = {
44
- start: jest.fn(),
45
- stopAndPersist: jest.fn()
46
- };
47
- const log = jest.fn();
48
- beforeEach(() => {
49
- axios.mockReset();
50
- writeFile.mockReset();
51
- readFile.mockReset();
52
- readdir.mockReset();
53
- exec.mockReset();
54
- copy.mockReset();
55
- log.mockReset();
56
- ora.mockReset();
57
- ora.mockReturnValue(oraInstance);
58
- oraInstance.start.mockReset();
59
- oraInstance.start.mockReturnValue(oraInstance);
60
- oraInstance.stopAndPersist.mockReset();
61
- readFile.mockResolvedValue(Buffer.from(`
62
- # test
63
- > yolo
64
-
65
- [//]: # (::contents:start)
66
-
67
- YOLO
68
-
69
- [//]: # (::contents:end)
70
-
71
- # Authors
72
- Mr Bean
73
-
74
- `));
75
- });
76
- it('should work', async () => {
77
- readFile.mockResolvedValueOnce(JSON.stringify(packageJSON));
78
- readdir.mockResolvedValueOnce(['development', 'production']);
79
- copy.mockImplementationOnce((_, _2, {
80
- filter
81
- }) => Promise.all(['package.json', 'package-lock.json', 'LICENSE', 'dist/index.js', 'src/index.js', 'coverage/index.html', 'node_modules/whook/index.js'].map(fileName => filter(`${SOURCE_DIR}/${fileName}`, `${project.directory}/${fileName}`))));
82
- axios.mockResolvedValueOnce({
83
- data: 'node_modules'
84
- });
85
- writeFile.mockResolvedValueOnce(undefined);
86
- writeFile.mockResolvedValueOnce(undefined);
87
- writeFile.mockResolvedValueOnce(undefined);
88
- exec.mockImplementationOnce((_, _2, cb) => cb(null, 'Initialized an empty git repository!'));
89
- exec.mockImplementationOnce((_, _2, cb) => cb(null, 'Installed dependencies!'));
90
- const createWhook = await initCreateWhook({
91
- CWD,
92
- SOURCE_DIR,
93
- author,
94
- project,
95
- writeFile,
96
- readFile,
97
- readdir,
98
- exec: exec,
99
- copy,
100
- axios: axios,
101
- ora: ora,
102
- log
103
- });
104
- await createWhook();
105
- expect(JSON.parse(writeFile.mock.calls.find(call => call[0].endsWith('package.json'))[1])).toMatchInlineSnapshot(`
106
- Object {
107
- "author": Object {
108
- "email": "wayne@warner.com",
109
- "name": "Wayne Campbell",
110
- },
111
- "babel": Object {
112
- "env": Object {
113
- "cjs": Object {
114
- "presets": Array [
115
- Array [
116
- "@babel/env",
117
- Object {
118
- "modules": "commonjs",
119
- "targets": Object {
120
- "node": "10",
121
- },
122
- },
123
- ],
124
- ],
125
- },
126
- "mjs": Object {
127
- "presets": Array [
128
- Array [
129
- "@babel/env",
130
- Object {
131
- "modules": false,
132
- "targets": Object {
133
- "node": "12",
134
- },
135
- },
136
- ],
137
- ],
138
- },
139
- },
140
- "plugins": Array [
141
- "@babel/proposal-class-properties",
142
- "@babel/plugin-proposal-object-rest-spread",
143
- "babel-plugin-knifecycle",
144
- ],
145
- "presets": Array [
146
- "@babel/typescript",
147
- Array [
148
- "@babel/env",
149
- Object {
150
- "targets": Object {
151
- "node": "12.19.0",
152
- },
153
- },
154
- ],
155
- ],
156
- "sourceMaps": true,
157
- },
158
- "dependencies": Object {
159
- "@whook/authorization": "<current_version>",
160
- "@whook/cli": "<current_version>",
161
- "@whook/cors": "<current_version>",
162
- "@whook/http-router": "<current_version>",
163
- "@whook/http-server": "^9.0.0",
164
- "@whook/http-transaction": "<current_version>",
165
- "@whook/swagger-ui": "<current_version>",
166
- "@whook/whook": "<current_version>",
167
- "common-services": "^10.0.2",
168
- "http-auth-utils": "^3.0.3",
169
- "jwt-service": "^8.0.1",
170
- "knifecycle": "^12.0.4",
171
- "openapi-schema-validator": "^11.0.1",
172
- "openapi-types": "^11.0.1",
173
- "strict-qs": "^6.1.5",
174
- "type-fest": "^2.13.0",
175
- "yerror": "^6.0.2",
176
- "yhttperror": "^6.0.3",
177
- },
178
- "description": "A new Whook project",
179
- "devDependencies": Object {
180
- "@babel/cli": "^7.17.10",
181
- "@babel/core": "^7.18.2",
182
- "@babel/eslint-parser": "^7.18.2",
183
- "@babel/node": "^7.13.13",
184
- "@babel/plugin-proposal-class-properties": "^7.17.12",
185
- "@babel/plugin-proposal-object-rest-spread": "^7.18.0",
186
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
187
- "@babel/plugin-syntax-import-meta": "^7.10.4",
188
- "@babel/preset-env": "^7.18.2",
189
- "@babel/preset-typescript": "^7.17.12",
190
- "@babel/register": "^7.17.7",
191
- "@types/jest": "^27.0.2",
192
- "@typescript-eslint/eslint-plugin": "^5.26.0",
193
- "@typescript-eslint/parser": "^5.26.0",
194
- "axios": "^0.27.2",
195
- "babel-plugin-knifecycle": "^5.0.3",
196
- "chokidar": "^3.5.1",
197
- "eslint": "^8.16.0",
198
- "eslint-plugin-prettier": "^4.0.0",
199
- "jest": "^28.1.0",
200
- "jsarch": "^5.0.1",
201
- "parse-gitignore": "^1.0.1",
202
- "prettier": "^2.6.2",
203
- "rimraf": "^3.0.2",
204
- "schema2dts": "^4.1.1",
205
- "typescript": "^4.7.2",
206
- },
207
- "engines": Object {
208
- "node": ">=12.19.0",
209
- },
210
- "eslintConfig": Object {
211
- "env": Object {
212
- "es6": true,
213
- "jest": true,
214
- "mocha": true,
215
- "node": true,
216
- },
217
- "extends": Array [
218
- "eslint:recommended",
219
- "plugin:@typescript-eslint/eslint-recommended",
220
- "plugin:@typescript-eslint/recommended",
221
- ],
222
- "ignorePatterns": Array [
223
- "*.d.ts",
224
- ],
225
- "parser": "@typescript-eslint/parser",
226
- "parserOptions": Object {
227
- "ecmaVersion": 2018,
228
- "modules": true,
229
- "sourceType": "module",
230
- },
231
- "plugins": Array [
232
- "prettier",
233
- ],
234
- "rules": Object {
235
- "prettier/prettier": "error",
236
- },
237
- },
238
- "files": Array [
239
- "bin",
240
- "dist",
241
- "src",
242
- "LICENSE",
243
- "README.md",
244
- "CHANGELOG.md",
245
- ],
246
- "jest": Object {
247
- "coverageReporters": Array [
248
- "lcov",
249
- "html",
250
- ],
251
- "roots": Array [
252
- "<rootDir>/src",
253
- ],
254
- "testEnvironment": "node",
255
- "testPathIgnorePatterns": Array [
256
- "/node_modules/",
257
- ],
258
- },
259
- "keywords": Array [
260
- "whook",
261
- ],
262
- "license": "SEE LICENSE",
263
- "main": "dist/index",
264
- "module": "dist/index.mjs",
265
- "name": "super-project",
266
- "prettier": Object {
267
- "printWidth": 80,
268
- "proseWrap": "always",
269
- "semi": true,
270
- "singleQuote": true,
271
- "trailingComma": "all",
272
- },
273
- "private": true,
274
- "scripts": Object {
275
- "apitypes": "npm run --silent whook -- generateOpenAPISchema --authenticated=true | npm run --silent whook -- generateOpenAPITypes > src/openAPISchema.d.ts",
276
- "architecture": "jsarch 'src/**/*.ts' > ARCHITECTURE.md && git add ARCHITECTURE.md",
277
- "build": "npm run compile && NODE_ENV=\${NODE_ENV:-development} node bin/build",
278
- "compile": "rimraf -f 'dist' && npm run compile:cjs && npm run compile:mjs",
279
- "compile:cjs": "babel --env-name=cjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
280
- "compile:mjs": "babel --env-name=mjs --out-file-extension=.mjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
281
- "cover": "npm run jest -- --coverage",
282
- "debug": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 DEBUG=\${DEBUG:-whook} babel-node --extensions '.ts,.js' --inspect bin/dev",
283
- "dev": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/dev",
284
- "genPackagelock": "npm i --package-lock-only",
285
- "jest": "NODE_ENV=test jest",
286
- "lint": "eslint 'src/**/*.ts'",
287
- "prettier": "prettier --write 'src/**/*.ts'",
288
- "start": "NODE_ENV=\${NODE_ENV:-development} node bin/start",
289
- "test": "npm run jest",
290
- "types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist",
291
- "watch": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/watch",
292
- "whook": "NODE_ENV=\${NODE_ENV:-development} whook",
293
- "whook-dev": "PROJECT_SRC=\\"$PWD/src\\" NODE_ENV=\${NODE_ENV:-development} babel-node --extensions '.ts,.js' -- node_modules/@whook/cli/bin/whook.js",
294
- "whook-repl": "PROJECT_SRC=\\"$PWD/src\\" NODE_ENV=\${NODE_ENV:-development} babel-node --extensions '.ts,.js' -- bin/repl.js",
295
- },
296
- "types": "dist/index.d.ts",
297
- "version": "0.0.0",
298
- }
299
- `);
300
- expect({
301
- copyCalls: copy.mock.calls,
302
- writeFileCalls: writeFile.mock.calls,
303
- readFileCalls: readFile.mock.calls,
304
- execCalls: exec.mock.calls,
305
- oraCalls: ora.mock.calls,
306
- oraStartCalls: oraInstance.start.mock.calls,
307
- oraStopAndPersistCalls: oraInstance.stopAndPersist.mock.calls,
308
- logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
309
- readdirCalls: readFile.mock.calls
310
- }).toMatchSnapshot();
311
- });
312
- it('should handle network issues', async () => {
313
- readFile.mockResolvedValueOnce(JSON.stringify(packageJSON));
314
- readdir.mockResolvedValueOnce(['development', 'production']);
315
- copy.mockImplementationOnce((_, _2, {
316
- filter
317
- }) => Promise.all(['package.json', 'package-lock.json', 'LICENSE', 'dist/index.js', 'src/index.js', 'coverage/index.html', 'node_modules/whook/index.js'].map(fileName => filter(`${SOURCE_DIR}/${fileName}`, `${project.directory}/${fileName}`))));
318
- axios.mockRejectedValueOnce(new YError('E_NETWORK'));
319
- writeFile.mockResolvedValueOnce(undefined);
320
- writeFile.mockResolvedValueOnce(undefined);
321
- writeFile.mockResolvedValueOnce(undefined);
322
- exec.mockImplementationOnce((_, _2, cb) => cb(new YError('E_ACCESS')));
323
- exec.mockImplementationOnce((_, _2, cb) => cb(null, 'Installed dependencies!'));
324
- const createWhook = await initCreateWhook({
325
- CWD,
326
- SOURCE_DIR,
327
- author,
328
- project,
329
- writeFile,
330
- readFile,
331
- readdir,
332
- exec: exec,
333
- copy,
334
- axios: axios,
335
- ora: ora,
336
- log
337
- });
338
- await createWhook();
339
- expect(JSON.parse(writeFile.mock.calls.find(call => call[0].endsWith('package.json'))[1])).toMatchInlineSnapshot(`
340
- Object {
341
- "author": Object {
342
- "email": "wayne@warner.com",
343
- "name": "Wayne Campbell",
344
- },
345
- "babel": Object {
346
- "env": Object {
347
- "cjs": Object {
348
- "presets": Array [
349
- Array [
350
- "@babel/env",
351
- Object {
352
- "modules": "commonjs",
353
- "targets": Object {
354
- "node": "10",
355
- },
356
- },
357
- ],
358
- ],
359
- },
360
- "mjs": Object {
361
- "presets": Array [
362
- Array [
363
- "@babel/env",
364
- Object {
365
- "modules": false,
366
- "targets": Object {
367
- "node": "12",
368
- },
369
- },
370
- ],
371
- ],
372
- },
373
- },
374
- "plugins": Array [
375
- "@babel/proposal-class-properties",
376
- "@babel/plugin-proposal-object-rest-spread",
377
- "babel-plugin-knifecycle",
378
- ],
379
- "presets": Array [
380
- "@babel/typescript",
381
- Array [
382
- "@babel/env",
383
- Object {
384
- "targets": Object {
385
- "node": "12.19.0",
386
- },
387
- },
388
- ],
389
- ],
390
- "sourceMaps": true,
391
- },
392
- "dependencies": Object {
393
- "@whook/authorization": "<current_version>",
394
- "@whook/cli": "<current_version>",
395
- "@whook/cors": "<current_version>",
396
- "@whook/http-router": "<current_version>",
397
- "@whook/http-server": "^9.0.0",
398
- "@whook/http-transaction": "<current_version>",
399
- "@whook/swagger-ui": "<current_version>",
400
- "@whook/whook": "<current_version>",
401
- "common-services": "^10.0.2",
402
- "http-auth-utils": "^3.0.3",
403
- "jwt-service": "^8.0.1",
404
- "knifecycle": "^12.0.4",
405
- "openapi-schema-validator": "^11.0.1",
406
- "openapi-types": "^11.0.1",
407
- "strict-qs": "^6.1.5",
408
- "type-fest": "^2.13.0",
409
- "yerror": "^6.0.2",
410
- "yhttperror": "^6.0.3",
411
- },
412
- "description": "A new Whook project",
413
- "devDependencies": Object {
414
- "@babel/cli": "^7.17.10",
415
- "@babel/core": "^7.18.2",
416
- "@babel/eslint-parser": "^7.18.2",
417
- "@babel/node": "^7.13.13",
418
- "@babel/plugin-proposal-class-properties": "^7.17.12",
419
- "@babel/plugin-proposal-object-rest-spread": "^7.18.0",
420
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
421
- "@babel/plugin-syntax-import-meta": "^7.10.4",
422
- "@babel/preset-env": "^7.18.2",
423
- "@babel/preset-typescript": "^7.17.12",
424
- "@babel/register": "^7.17.7",
425
- "@types/jest": "^27.0.2",
426
- "@typescript-eslint/eslint-plugin": "^5.26.0",
427
- "@typescript-eslint/parser": "^5.26.0",
428
- "axios": "^0.27.2",
429
- "babel-plugin-knifecycle": "^5.0.3",
430
- "chokidar": "^3.5.1",
431
- "eslint": "^8.16.0",
432
- "eslint-plugin-prettier": "^4.0.0",
433
- "jest": "^28.1.0",
434
- "jsarch": "^5.0.1",
435
- "parse-gitignore": "^1.0.1",
436
- "prettier": "^2.6.2",
437
- "rimraf": "^3.0.2",
438
- "schema2dts": "^4.1.1",
439
- "typescript": "^4.7.2",
440
- },
441
- "engines": Object {
442
- "node": ">=12.19.0",
443
- },
444
- "eslintConfig": Object {
445
- "env": Object {
446
- "es6": true,
447
- "jest": true,
448
- "mocha": true,
449
- "node": true,
450
- },
451
- "extends": Array [
452
- "eslint:recommended",
453
- "plugin:@typescript-eslint/eslint-recommended",
454
- "plugin:@typescript-eslint/recommended",
455
- ],
456
- "ignorePatterns": Array [
457
- "*.d.ts",
458
- ],
459
- "parser": "@typescript-eslint/parser",
460
- "parserOptions": Object {
461
- "ecmaVersion": 2018,
462
- "modules": true,
463
- "sourceType": "module",
464
- },
465
- "plugins": Array [
466
- "prettier",
467
- ],
468
- "rules": Object {
469
- "prettier/prettier": "error",
470
- },
471
- },
472
- "files": Array [
473
- "bin",
474
- "dist",
475
- "src",
476
- "LICENSE",
477
- "README.md",
478
- "CHANGELOG.md",
479
- ],
480
- "jest": Object {
481
- "coverageReporters": Array [
482
- "lcov",
483
- "html",
484
- ],
485
- "roots": Array [
486
- "<rootDir>/src",
487
- ],
488
- "testEnvironment": "node",
489
- "testPathIgnorePatterns": Array [
490
- "/node_modules/",
491
- ],
492
- },
493
- "keywords": Array [
494
- "whook",
495
- ],
496
- "license": "SEE LICENSE",
497
- "main": "dist/index",
498
- "module": "dist/index.mjs",
499
- "name": "super-project",
500
- "prettier": Object {
501
- "printWidth": 80,
502
- "proseWrap": "always",
503
- "semi": true,
504
- "singleQuote": true,
505
- "trailingComma": "all",
506
- },
507
- "private": true,
508
- "scripts": Object {
509
- "apitypes": "npm run --silent whook -- generateOpenAPISchema --authenticated=true | npm run --silent whook -- generateOpenAPITypes > src/openAPISchema.d.ts",
510
- "architecture": "jsarch 'src/**/*.ts' > ARCHITECTURE.md && git add ARCHITECTURE.md",
511
- "build": "npm run compile && NODE_ENV=\${NODE_ENV:-development} node bin/build",
512
- "compile": "rimraf -f 'dist' && npm run compile:cjs && npm run compile:mjs",
513
- "compile:cjs": "babel --env-name=cjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
514
- "compile:mjs": "babel --env-name=mjs --out-file-extension=.mjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
515
- "cover": "npm run jest -- --coverage",
516
- "debug": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 DEBUG=\${DEBUG:-whook} babel-node --extensions '.ts,.js' --inspect bin/dev",
517
- "dev": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/dev",
518
- "genPackagelock": "npm i --package-lock-only",
519
- "jest": "NODE_ENV=test jest",
520
- "lint": "eslint 'src/**/*.ts'",
521
- "prettier": "prettier --write 'src/**/*.ts'",
522
- "start": "NODE_ENV=\${NODE_ENV:-development} node bin/start",
523
- "test": "npm run jest",
524
- "types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist",
525
- "watch": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/watch",
526
- "whook": "NODE_ENV=\${NODE_ENV:-development} whook",
527
- "whook-dev": "PROJECT_SRC=\\"$PWD/src\\" NODE_ENV=\${NODE_ENV:-development} babel-node --extensions '.ts,.js' -- node_modules/@whook/cli/bin/whook.js",
528
- "whook-repl": "PROJECT_SRC=\\"$PWD/src\\" NODE_ENV=\${NODE_ENV:-development} babel-node --extensions '.ts,.js' -- bin/repl.js",
529
- },
530
- "types": "dist/index.d.ts",
531
- "version": "0.0.0",
532
- }
533
- `);
534
- expect({
535
- copyCalls: copy.mock.calls,
536
- writeFileCalls: writeFile.mock.calls,
537
- readFileCalls: readFile.mock.calls,
538
- execCalls: exec.mock.calls,
539
- oraCalls: ora.mock.calls,
540
- oraStartCalls: oraInstance.start.mock.calls,
541
- oraStopAndPersistCalls: oraInstance.stopAndPersist.mock.calls,
542
- logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
543
- readdirCalls: readFile.mock.calls
544
- }).toMatchSnapshot();
545
- });
546
- it('should handle git initialization problems', async () => {
547
- readFile.mockResolvedValueOnce(JSON.stringify(packageJSON));
548
- readdir.mockResolvedValueOnce(['development', 'production']);
549
- copy.mockResolvedValueOnce(new YError('E_ACCESS'));
550
- axios.mockResolvedValueOnce({
551
- data: 'node_modules'
552
- });
553
- writeFile.mockResolvedValueOnce(undefined);
554
- writeFile.mockResolvedValueOnce(undefined);
555
- writeFile.mockResolvedValueOnce(undefined);
556
- exec.mockImplementationOnce((_, _2, cb) => cb(new YError('E_ACCESS')));
557
- exec.mockImplementationOnce((_, _2, cb) => cb(null, 'Installed dependencies!'));
558
- const createWhook = await initCreateWhook({
559
- CWD,
560
- SOURCE_DIR,
561
- author,
562
- project,
563
- writeFile,
564
- readFile,
565
- readdir,
566
- exec: exec,
567
- copy,
568
- axios: axios,
569
- ora: ora,
570
- log
571
- });
572
- await createWhook();
573
- expect(JSON.parse(writeFile.mock.calls.find(call => call[0].endsWith('package.json'))[1])).toMatchInlineSnapshot(`
574
- Object {
575
- "author": Object {
576
- "email": "wayne@warner.com",
577
- "name": "Wayne Campbell",
578
- },
579
- "babel": Object {
580
- "env": Object {
581
- "cjs": Object {
582
- "presets": Array [
583
- Array [
584
- "@babel/env",
585
- Object {
586
- "modules": "commonjs",
587
- "targets": Object {
588
- "node": "10",
589
- },
590
- },
591
- ],
592
- ],
593
- },
594
- "mjs": Object {
595
- "presets": Array [
596
- Array [
597
- "@babel/env",
598
- Object {
599
- "modules": false,
600
- "targets": Object {
601
- "node": "12",
602
- },
603
- },
604
- ],
605
- ],
606
- },
607
- },
608
- "plugins": Array [
609
- "@babel/proposal-class-properties",
610
- "@babel/plugin-proposal-object-rest-spread",
611
- "babel-plugin-knifecycle",
612
- ],
613
- "presets": Array [
614
- "@babel/typescript",
615
- Array [
616
- "@babel/env",
617
- Object {
618
- "targets": Object {
619
- "node": "12.19.0",
620
- },
621
- },
622
- ],
623
- ],
624
- "sourceMaps": true,
625
- },
626
- "dependencies": Object {
627
- "@whook/authorization": "<current_version>",
628
- "@whook/cli": "<current_version>",
629
- "@whook/cors": "<current_version>",
630
- "@whook/http-router": "<current_version>",
631
- "@whook/http-server": "^9.0.0",
632
- "@whook/http-transaction": "<current_version>",
633
- "@whook/swagger-ui": "<current_version>",
634
- "@whook/whook": "<current_version>",
635
- "common-services": "^10.0.2",
636
- "http-auth-utils": "^3.0.3",
637
- "jwt-service": "^8.0.1",
638
- "knifecycle": "^12.0.4",
639
- "openapi-schema-validator": "^11.0.1",
640
- "openapi-types": "^11.0.1",
641
- "strict-qs": "^6.1.5",
642
- "type-fest": "^2.13.0",
643
- "yerror": "^6.0.2",
644
- "yhttperror": "^6.0.3",
645
- },
646
- "description": "A new Whook project",
647
- "devDependencies": Object {
648
- "@babel/cli": "^7.17.10",
649
- "@babel/core": "^7.18.2",
650
- "@babel/eslint-parser": "^7.18.2",
651
- "@babel/node": "^7.13.13",
652
- "@babel/plugin-proposal-class-properties": "^7.17.12",
653
- "@babel/plugin-proposal-object-rest-spread": "^7.18.0",
654
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
655
- "@babel/plugin-syntax-import-meta": "^7.10.4",
656
- "@babel/preset-env": "^7.18.2",
657
- "@babel/preset-typescript": "^7.17.12",
658
- "@babel/register": "^7.17.7",
659
- "@types/jest": "^27.0.2",
660
- "@typescript-eslint/eslint-plugin": "^5.26.0",
661
- "@typescript-eslint/parser": "^5.26.0",
662
- "axios": "^0.27.2",
663
- "babel-plugin-knifecycle": "^5.0.3",
664
- "chokidar": "^3.5.1",
665
- "eslint": "^8.16.0",
666
- "eslint-plugin-prettier": "^4.0.0",
667
- "jest": "^28.1.0",
668
- "jsarch": "^5.0.1",
669
- "parse-gitignore": "^1.0.1",
670
- "prettier": "^2.6.2",
671
- "rimraf": "^3.0.2",
672
- "schema2dts": "^4.1.1",
673
- "typescript": "^4.7.2",
674
- },
675
- "engines": Object {
676
- "node": ">=12.19.0",
677
- },
678
- "eslintConfig": Object {
679
- "env": Object {
680
- "es6": true,
681
- "jest": true,
682
- "mocha": true,
683
- "node": true,
684
- },
685
- "extends": Array [
686
- "eslint:recommended",
687
- "plugin:@typescript-eslint/eslint-recommended",
688
- "plugin:@typescript-eslint/recommended",
689
- ],
690
- "ignorePatterns": Array [
691
- "*.d.ts",
692
- ],
693
- "parser": "@typescript-eslint/parser",
694
- "parserOptions": Object {
695
- "ecmaVersion": 2018,
696
- "modules": true,
697
- "sourceType": "module",
698
- },
699
- "plugins": Array [
700
- "prettier",
701
- ],
702
- "rules": Object {
703
- "prettier/prettier": "error",
704
- },
705
- },
706
- "files": Array [
707
- "bin",
708
- "dist",
709
- "src",
710
- "LICENSE",
711
- "README.md",
712
- "CHANGELOG.md",
713
- ],
714
- "jest": Object {
715
- "coverageReporters": Array [
716
- "lcov",
717
- "html",
718
- ],
719
- "roots": Array [
720
- "<rootDir>/src",
721
- ],
722
- "testEnvironment": "node",
723
- "testPathIgnorePatterns": Array [
724
- "/node_modules/",
725
- ],
726
- },
727
- "keywords": Array [
728
- "whook",
729
- ],
730
- "license": "SEE LICENSE",
731
- "main": "dist/index",
732
- "module": "dist/index.mjs",
733
- "name": "super-project",
734
- "prettier": Object {
735
- "printWidth": 80,
736
- "proseWrap": "always",
737
- "semi": true,
738
- "singleQuote": true,
739
- "trailingComma": "all",
740
- },
741
- "private": true,
742
- "scripts": Object {
743
- "apitypes": "npm run --silent whook -- generateOpenAPISchema --authenticated=true | npm run --silent whook -- generateOpenAPITypes > src/openAPISchema.d.ts",
744
- "architecture": "jsarch 'src/**/*.ts' > ARCHITECTURE.md && git add ARCHITECTURE.md",
745
- "build": "npm run compile && NODE_ENV=\${NODE_ENV:-development} node bin/build",
746
- "compile": "rimraf -f 'dist' && npm run compile:cjs && npm run compile:mjs",
747
- "compile:cjs": "babel --env-name=cjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
748
- "compile:mjs": "babel --env-name=mjs --out-file-extension=.mjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
749
- "cover": "npm run jest -- --coverage",
750
- "debug": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 DEBUG=\${DEBUG:-whook} babel-node --extensions '.ts,.js' --inspect bin/dev",
751
- "dev": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/dev",
752
- "genPackagelock": "npm i --package-lock-only",
753
- "jest": "NODE_ENV=test jest",
754
- "lint": "eslint 'src/**/*.ts'",
755
- "prettier": "prettier --write 'src/**/*.ts'",
756
- "start": "NODE_ENV=\${NODE_ENV:-development} node bin/start",
757
- "test": "npm run jest",
758
- "types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist",
759
- "watch": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/watch",
760
- "whook": "NODE_ENV=\${NODE_ENV:-development} whook",
761
- "whook-dev": "PROJECT_SRC=\\"$PWD/src\\" NODE_ENV=\${NODE_ENV:-development} babel-node --extensions '.ts,.js' -- node_modules/@whook/cli/bin/whook.js",
762
- "whook-repl": "PROJECT_SRC=\\"$PWD/src\\" NODE_ENV=\${NODE_ENV:-development} babel-node --extensions '.ts,.js' -- bin/repl.js",
763
- },
764
- "types": "dist/index.d.ts",
765
- "version": "0.0.0",
766
- }
767
- `);
768
- expect({
769
- copyCalls: copy.mock.calls,
770
- writeFileCalls: writeFile.mock.calls,
771
- readFileCalls: readFile.mock.calls,
772
- execCalls: exec.mock.calls,
773
- oraCalls: ora.mock.calls,
774
- oraStartCalls: oraInstance.start.mock.calls,
775
- oraStopAndPersistCalls: oraInstance.stopAndPersist.mock.calls,
776
- logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
777
- readdirCalls: readFile.mock.calls
778
- }).toMatchSnapshot();
779
- });
780
- it('should fail with access problems', async () => {
781
- readFile.mockResolvedValueOnce(JSON.stringify(packageJSON));
782
- readdir.mockResolvedValueOnce(['development', 'production']);
783
- copy.mockRejectedValueOnce(new YError('E_ACCESS'));
784
- axios.mockResolvedValueOnce({
785
- data: 'node_modules'
786
- });
787
- writeFile.mockResolvedValueOnce(undefined);
788
- writeFile.mockResolvedValueOnce(undefined);
789
- writeFile.mockResolvedValueOnce(undefined);
790
- exec.mockImplementationOnce((_, _2, cb) => cb(null, ''));
791
- exec.mockImplementationOnce((_, _2, cb) => cb(null, 'Installed dependencies!'));
792
-
793
- try {
794
- const createWhook = await initCreateWhook({
795
- CWD,
796
- SOURCE_DIR,
797
- author,
798
- project,
799
- writeFile,
800
- readFile,
801
- readdir,
802
- exec: exec,
803
- copy,
804
- axios: axios,
805
- ora: ora,
806
- log
807
- });
808
- await createWhook();
809
- throw new YError('E_UNEXPECTED_SUCCESS');
810
- } catch (err) {
811
- expect({
812
- errorCode: err.code,
813
- errorParams: err.params
814
- }).toMatchInlineSnapshot(`
815
- Object {
816
- "errorCode": "E_ACCESS",
817
- "errorParams": Array [],
818
- }
819
- `);
820
- expect({
821
- copyCalls: copy.mock.calls,
822
- writeFileCalls: writeFile.mock.calls,
823
- readFileCalls: readFile.mock.calls,
824
- execCalls: exec.mock.calls,
825
- oraCalls: ora.mock.calls,
826
- oraStartCalls: oraInstance.start.mock.calls,
827
- oraStopAndPersistCalls: oraInstance.stopAndPersist.mock.calls,
828
- logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
829
- readdirCalls: readdir.mock.calls
830
- }).toMatchSnapshot();
831
- }
832
- });
833
- });
834
- //# sourceMappingURL=createWhook.test.mjs.map