@neurodevs/meta-node 0.19.12 → 0.19.13
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.
- package/.vscode/launch.json +1 -0
- package/build/__tests__/impl/NpmAutopackage.test.d.ts +28 -2
- package/build/__tests__/impl/NpmAutopackage.test.js +248 -44
- package/build/__tests__/impl/NpmAutopackage.test.js.map +1 -1
- package/build/impl/NpmAutopackage.d.ts +29 -5
- package/build/impl/NpmAutopackage.js +131 -14
- package/build/impl/NpmAutopackage.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/impl/NpmAutopackage.test.ts +346 -47
- package/src/impl/NpmAutopackage.ts +199 -19
|
@@ -24,7 +24,9 @@ export default class NpmAutopackage implements Autopackage {
|
|
|
24
24
|
private author?: string
|
|
25
25
|
|
|
26
26
|
private originalPackageJson!: Record<string, unknown>
|
|
27
|
-
private
|
|
27
|
+
private originalGitignore!: string
|
|
28
|
+
|
|
29
|
+
private originalTsconfig!: TsConfig
|
|
28
30
|
private metaNodeVersion!: string
|
|
29
31
|
|
|
30
32
|
private originalTasksJson!: {
|
|
@@ -40,8 +42,8 @@ export default class NpmAutopackage implements Autopackage {
|
|
|
40
42
|
private readonly packageDir: string
|
|
41
43
|
private readonly packageJsonPath: string
|
|
42
44
|
private readonly gitignorePath: string
|
|
45
|
+
private readonly tsconfigPath: string
|
|
43
46
|
private readonly tasksJsonPath: string
|
|
44
|
-
private readonly settingsJsonPath: string
|
|
45
47
|
private readonly testDirPath: string
|
|
46
48
|
private readonly abstractTestPath: string
|
|
47
49
|
|
|
@@ -52,6 +54,16 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
52
54
|
await super.beforeEach()
|
|
53
55
|
}
|
|
54
56
|
}
|
|
57
|
+
`
|
|
58
|
+
|
|
59
|
+
private readonly eslintConfigFile = `import esConfigNdx from './src/eslint.config.js'
|
|
60
|
+
|
|
61
|
+
export default esConfigNdx
|
|
62
|
+
`
|
|
63
|
+
|
|
64
|
+
private readonly prettierConfigFile = `import prettierConfigNdx from '@neurodevs/prettier-config-ndx'
|
|
65
|
+
|
|
66
|
+
export default prettierConfigNdx
|
|
55
67
|
`
|
|
56
68
|
|
|
57
69
|
protected constructor(options: AutopackageOptions) {
|
|
@@ -78,13 +90,8 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
78
90
|
this.packageDir = path.join(this.installDir, this.packageName)
|
|
79
91
|
this.packageJsonPath = path.join(this.packageDir, 'package.json')
|
|
80
92
|
this.gitignorePath = path.join(this.packageDir, '.gitignore')
|
|
93
|
+
this.tsconfigPath = path.join(this.packageDir, 'tsconfig.json')
|
|
81
94
|
this.tasksJsonPath = path.join(this.packageDir, '.vscode/tasks.json')
|
|
82
|
-
|
|
83
|
-
this.settingsJsonPath = path.join(
|
|
84
|
-
this.packageDir,
|
|
85
|
-
'.vscode/settings.json'
|
|
86
|
-
)
|
|
87
|
-
|
|
88
95
|
this.testDirPath = path.join(this.packageDir, 'src', '__tests__')
|
|
89
96
|
|
|
90
97
|
this.abstractTestPath = path.join(
|
|
@@ -107,10 +114,13 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
107
114
|
await this.spruceCreateModule()
|
|
108
115
|
await this.updatePackageJson()
|
|
109
116
|
await this.updateGitignore()
|
|
117
|
+
await this.updateTsconfig()
|
|
110
118
|
await this.setupVscode()
|
|
111
119
|
await this.updateVscodeTasks()
|
|
112
120
|
await this.installDefaultDevDependencies()
|
|
113
121
|
await this.installAbstractPackageTest()
|
|
122
|
+
await this.installEslintConfigFile()
|
|
123
|
+
await this.installPrettierConfigFile()
|
|
114
124
|
await this.openVscode()
|
|
115
125
|
}
|
|
116
126
|
|
|
@@ -244,7 +254,7 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
244
254
|
}
|
|
245
255
|
|
|
246
256
|
private async updatePackageJson() {
|
|
247
|
-
this.originalPackageJson = await this.
|
|
257
|
+
this.originalPackageJson = await this.loadPackageJson()
|
|
248
258
|
|
|
249
259
|
if (!this.isPackageUpToDate) {
|
|
250
260
|
console.log('Updating package.json...')
|
|
@@ -254,7 +264,7 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
254
264
|
}
|
|
255
265
|
}
|
|
256
266
|
|
|
257
|
-
private async
|
|
267
|
+
private async loadPackageJson() {
|
|
258
268
|
const raw = await this.readFile(this.packageJsonPath, {
|
|
259
269
|
encoding: 'utf-8',
|
|
260
270
|
})
|
|
@@ -301,6 +311,7 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
301
311
|
...this.originalPackageJson,
|
|
302
312
|
name: this.scopedPackageName,
|
|
303
313
|
description: this.description,
|
|
314
|
+
type: 'module',
|
|
304
315
|
keywords: this.keywords ?? [],
|
|
305
316
|
license: this.license,
|
|
306
317
|
author: this.author,
|
|
@@ -350,7 +361,7 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
350
361
|
}
|
|
351
362
|
|
|
352
363
|
private async updateGitignore() {
|
|
353
|
-
this.
|
|
364
|
+
this.originalGitignore = await this.loadGitignore()
|
|
354
365
|
|
|
355
366
|
if (!this.isGitignoreUpdated) {
|
|
356
367
|
console.log('Updating .gitignore...')
|
|
@@ -360,14 +371,14 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
360
371
|
}
|
|
361
372
|
}
|
|
362
373
|
|
|
363
|
-
private async
|
|
374
|
+
private async loadGitignore() {
|
|
364
375
|
return await this.readFile(this.gitignorePath, {
|
|
365
376
|
encoding: 'utf-8',
|
|
366
377
|
})
|
|
367
378
|
}
|
|
368
379
|
|
|
369
380
|
private get isGitignoreUpdated() {
|
|
370
|
-
const lines = this.
|
|
381
|
+
const lines = this.originalGitignore
|
|
371
382
|
.split(/\r?\n/)
|
|
372
383
|
.map((line) => line.trim())
|
|
373
384
|
|
|
@@ -387,10 +398,97 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
387
398
|
)
|
|
388
399
|
}
|
|
389
400
|
|
|
401
|
+
private async updateTsconfig() {
|
|
402
|
+
this.originalTsconfig = await this.loadTsconfig()
|
|
403
|
+
|
|
404
|
+
if (!this.isTsconfigUpdated) {
|
|
405
|
+
console.log('Updating tsconfig...')
|
|
406
|
+
await this.updateTsconfigFile()
|
|
407
|
+
await this.commitUpdateTsconfig()
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
private async loadTsconfig() {
|
|
412
|
+
const raw = await this.readFile(this.tsconfigPath, {
|
|
413
|
+
encoding: 'utf-8',
|
|
414
|
+
})
|
|
415
|
+
return JSON.parse(raw)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private get isTsconfigUpdated() {
|
|
419
|
+
return (
|
|
420
|
+
JSON.stringify(this.originalTsconfig) ==
|
|
421
|
+
JSON.stringify(this.updatedTsconfig)
|
|
422
|
+
)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
private async updateTsconfigFile() {
|
|
426
|
+
await this.writeFile(
|
|
427
|
+
this.tsconfigPath,
|
|
428
|
+
JSON.stringify(this.updatedTsconfig, null, 4) + '\n',
|
|
429
|
+
{
|
|
430
|
+
encoding: 'utf-8',
|
|
431
|
+
flag: 'a',
|
|
432
|
+
}
|
|
433
|
+
)
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
private get updatedTsconfig() {
|
|
437
|
+
return {
|
|
438
|
+
...this.originalTsconfig,
|
|
439
|
+
compilerOptions: {
|
|
440
|
+
module: 'nodenext',
|
|
441
|
+
moduleResolution: 'nodenext',
|
|
442
|
+
target: 'ES2022',
|
|
443
|
+
lib: Array.from(
|
|
444
|
+
new Set([
|
|
445
|
+
...(this.originalTsconfig?.compilerOptions?.lib ?? []),
|
|
446
|
+
'ES2022',
|
|
447
|
+
])
|
|
448
|
+
),
|
|
449
|
+
types: Array.from(
|
|
450
|
+
new Set([
|
|
451
|
+
...(this.originalTsconfig?.compilerOptions?.types ??
|
|
452
|
+
[]),
|
|
453
|
+
'node',
|
|
454
|
+
])
|
|
455
|
+
),
|
|
456
|
+
baseUrl: 'src',
|
|
457
|
+
outDir: 'build',
|
|
458
|
+
sourceMap: false,
|
|
459
|
+
strict: true,
|
|
460
|
+
noImplicitAny: true,
|
|
461
|
+
noImplicitReturns: true,
|
|
462
|
+
noUnusedLocals: true,
|
|
463
|
+
forceConsistentCasingInFileNames: true,
|
|
464
|
+
declaration: true,
|
|
465
|
+
skipLibCheck: true,
|
|
466
|
+
esModuleInterop: true,
|
|
467
|
+
moduleDetection: 'force',
|
|
468
|
+
allowJs: true,
|
|
469
|
+
resolveJsonModule: true,
|
|
470
|
+
experimentalDecorators: true,
|
|
471
|
+
},
|
|
472
|
+
include: Array.from(
|
|
473
|
+
new Set([
|
|
474
|
+
...(this.originalTsconfig?.include ?? []),
|
|
475
|
+
'./src/*.ts',
|
|
476
|
+
'./src/**/*.ts',
|
|
477
|
+
])
|
|
478
|
+
),
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
private async commitUpdateTsconfig() {
|
|
483
|
+
await this.GitAutocommit(
|
|
484
|
+
`patch: update tsconfig (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
485
|
+
)
|
|
486
|
+
}
|
|
487
|
+
|
|
390
488
|
private async setupVscode() {
|
|
391
|
-
const
|
|
489
|
+
const vscodeTasksExist = await this.checkIfVscodeTasksExist()
|
|
392
490
|
|
|
393
|
-
if (!
|
|
491
|
+
if (!vscodeTasksExist) {
|
|
394
492
|
console.log('Setting up VSCode...')
|
|
395
493
|
|
|
396
494
|
await this.spruceSetupVscode()
|
|
@@ -398,8 +496,8 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
398
496
|
}
|
|
399
497
|
}
|
|
400
498
|
|
|
401
|
-
private async
|
|
402
|
-
return this.pathExists(this.
|
|
499
|
+
private async checkIfVscodeTasksExist() {
|
|
500
|
+
return this.pathExists(this.tasksJsonPath)
|
|
403
501
|
}
|
|
404
502
|
|
|
405
503
|
private async spruceSetupVscode() {
|
|
@@ -505,14 +603,24 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
505
603
|
'@neurodevs/node-tdd'
|
|
506
604
|
)
|
|
507
605
|
|
|
606
|
+
const eslintConfigNdxVersion = await this.getLatestVersion(
|
|
607
|
+
'@neurodevs/eslint-config-ndx'
|
|
608
|
+
)
|
|
609
|
+
|
|
610
|
+
const prettierConfigNdxVersion = await this.getLatestVersion(
|
|
611
|
+
'@neurodevs/prettier-config-ndx'
|
|
612
|
+
)
|
|
613
|
+
|
|
508
614
|
if (
|
|
509
615
|
this.currentGenerateIdVersion != generateIdVersion ||
|
|
510
|
-
this.currentNodeTddVersion != nodeTddVersion
|
|
616
|
+
this.currentNodeTddVersion != nodeTddVersion ||
|
|
617
|
+
this.currentEslintConfigNdxVersion != eslintConfigNdxVersion ||
|
|
618
|
+
this.currentPrettierConfigNdxVersion != prettierConfigNdxVersion
|
|
511
619
|
) {
|
|
512
620
|
console.log('Installing default devDependencies...')
|
|
513
621
|
|
|
514
622
|
await this.exec(
|
|
515
|
-
'yarn add -D @neurodevs/generate-id
|
|
623
|
+
'yarn add -D @neurodevs/generate-id @neurodevs/node-tdd @neurodevs/eslint-config-ndx @neurodevs/prettier-config-ndx',
|
|
516
624
|
{ cwd: this.packageDir }
|
|
517
625
|
)
|
|
518
626
|
await this.commitInstallDevDependencies()
|
|
@@ -543,6 +651,22 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
543
651
|
).replace('^', '')
|
|
544
652
|
}
|
|
545
653
|
|
|
654
|
+
private get currentEslintConfigNdxVersion() {
|
|
655
|
+
return (
|
|
656
|
+
(this.originalPackageJson.devDependencies as any)[
|
|
657
|
+
'@neurodevs/eslint-config-ndx'
|
|
658
|
+
] || ''
|
|
659
|
+
).replace('^', '')
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
private get currentPrettierConfigNdxVersion() {
|
|
663
|
+
return (
|
|
664
|
+
(this.originalPackageJson.devDependencies as any)[
|
|
665
|
+
'@neurodevs/prettier-config-ndx'
|
|
666
|
+
] || ''
|
|
667
|
+
).replace('^', '')
|
|
668
|
+
}
|
|
669
|
+
|
|
546
670
|
private async commitInstallDevDependencies() {
|
|
547
671
|
await this.GitAutocommit(
|
|
548
672
|
`patch: install default devDependencies (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
@@ -582,6 +706,52 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
582
706
|
)
|
|
583
707
|
}
|
|
584
708
|
|
|
709
|
+
private async installEslintConfigFile() {
|
|
710
|
+
const eslintConfigPath = path.join(this.packageDir, 'eslint.config.js')
|
|
711
|
+
const fileExists = await this.pathExists(eslintConfigPath)
|
|
712
|
+
|
|
713
|
+
if (!fileExists) {
|
|
714
|
+
console.log('Installing eslint.config.js...')
|
|
715
|
+
|
|
716
|
+
await this.writeFile(eslintConfigPath, this.eslintConfigFile, {
|
|
717
|
+
encoding: 'utf-8',
|
|
718
|
+
})
|
|
719
|
+
|
|
720
|
+
await this.commitInstallEslintConfigFile()
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
private async commitInstallEslintConfigFile() {
|
|
725
|
+
await this.GitAutocommit(
|
|
726
|
+
`patch: install eslint.config.js (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
727
|
+
)
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
private async installPrettierConfigFile() {
|
|
731
|
+
const prettierConfigPath = path.join(
|
|
732
|
+
this.packageDir,
|
|
733
|
+
'prettier.config.js'
|
|
734
|
+
)
|
|
735
|
+
|
|
736
|
+
const fileExists = await this.pathExists(prettierConfigPath)
|
|
737
|
+
|
|
738
|
+
if (!fileExists) {
|
|
739
|
+
console.log('Installing prettier.config.js...')
|
|
740
|
+
|
|
741
|
+
await this.writeFile(prettierConfigPath, this.prettierConfigFile, {
|
|
742
|
+
encoding: 'utf-8',
|
|
743
|
+
})
|
|
744
|
+
|
|
745
|
+
await this.commitInstallPrettierConfigFile()
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
private async commitInstallPrettierConfigFile() {
|
|
750
|
+
await this.GitAutocommit(
|
|
751
|
+
`patch: install prettier.config.js (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
752
|
+
)
|
|
753
|
+
}
|
|
754
|
+
|
|
585
755
|
private async openVscode() {
|
|
586
756
|
if (this.shouldOpenVscode) {
|
|
587
757
|
await this.exec('code .', { cwd: this.packageDir })
|
|
@@ -635,3 +805,13 @@ export interface AutopackageOptions {
|
|
|
635
805
|
export type AutopackageConstructor = new (
|
|
636
806
|
options: AutopackageOptions
|
|
637
807
|
) => Autopackage
|
|
808
|
+
|
|
809
|
+
export interface TsConfig {
|
|
810
|
+
compilerOptions?: {
|
|
811
|
+
lib?: string[]
|
|
812
|
+
types?: string[]
|
|
813
|
+
[key: string]: unknown
|
|
814
|
+
}
|
|
815
|
+
include?: string[]
|
|
816
|
+
[key: string]: unknown
|
|
817
|
+
}
|