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