@neurodevs/meta-node 0.14.29 → 0.15.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.
- package/build/__tests__/AbstractPackageTest.d.ts +4 -0
- package/build/__tests__/AbstractPackageTest.js +11 -1
- package/build/__tests__/AbstractPackageTest.js.map +1 -1
- package/build/__tests__/impl/GitAutocloner.test.js +9 -9
- package/build/__tests__/impl/GitAutocloner.test.js.map +1 -1
- package/build/__tests__/impl/GitAutocommit.test.d.ts +11 -0
- package/build/__tests__/impl/GitAutocommit.test.js +49 -0
- package/build/__tests__/impl/GitAutocommit.test.js.map +1 -0
- package/build/__tests__/impl/ImplAutomodule.test.js +1 -1
- package/build/__tests__/impl/ImplAutomodule.test.js.map +1 -1
- package/build/__tests__/impl/NpmAutopackage.test.d.ts +1 -3
- package/build/__tests__/impl/NpmAutopackage.test.js +38 -64
- package/build/__tests__/impl/NpmAutopackage.test.js.map +1 -1
- package/build/__tests__/impl/NpmReleasePropagator.test.d.ts +17 -0
- package/build/__tests__/impl/NpmReleasePropagator.test.js +115 -0
- package/build/__tests__/impl/NpmReleasePropagator.test.js.map +1 -0
- package/build/__tests__/impl/UiAutomodule.test.js +1 -1
- package/build/__tests__/impl/UiAutomodule.test.js.map +1 -1
- package/build/impl/GitAutocommit.d.ts +15 -0
- package/build/impl/GitAutocommit.js +27 -0
- package/build/impl/GitAutocommit.js.map +1 -0
- package/build/impl/NpmAutopackage.d.ts +1 -9
- package/build/impl/NpmAutopackage.js +11 -48
- package/build/impl/NpmAutopackage.js.map +1 -1
- package/build/impl/NpmReleasePropagator.d.ts +40 -0
- package/build/impl/NpmReleasePropagator.js +78 -0
- package/build/impl/NpmReleasePropagator.js.map +1 -0
- package/build/index.d.ts +8 -0
- package/build/index.js +10 -0
- package/build/index.js.map +1 -1
- package/build/scripts/runNpmReleasePropagator.d.ts +1 -0
- package/build/scripts/runNpmReleasePropagator.js +8 -0
- package/build/scripts/runNpmReleasePropagator.js.map +1 -0
- package/build/testDoubles/Autocommit/FakeAutocommit.d.ts +11 -0
- package/build/testDoubles/Autocommit/FakeAutocommit.js +18 -0
- package/build/testDoubles/Autocommit/FakeAutocommit.js.map +1 -0
- package/build/testDoubles/ReleasePropagator/FakeReleasePropagator.d.ts +8 -0
- package/build/testDoubles/ReleasePropagator/FakeReleasePropagator.js +15 -0
- package/build/testDoubles/ReleasePropagator/FakeReleasePropagator.js.map +1 -0
- package/package.json +3 -3
- package/src/__tests__/AbstractPackageTest.ts +27 -1
- package/src/__tests__/impl/GitAutocloner.test.ts +13 -9
- package/src/__tests__/impl/GitAutocommit.test.ts +60 -0
- package/src/__tests__/impl/ImplAutomodule.test.ts +1 -1
- package/src/__tests__/impl/NpmAutopackage.test.ts +60 -91
- package/src/__tests__/impl/NpmReleasePropagator.test.ts +151 -0
- package/src/__tests__/impl/UiAutomodule.test.ts +1 -1
- package/src/impl/GitAutocommit.ts +40 -0
- package/src/impl/NpmAutopackage.ts +20 -64
- package/src/impl/NpmReleasePropagator.ts +134 -0
- package/src/index.ts +16 -0
- package/src/scripts/runNpmReleasePropagator.ts +9 -0
- package/src/testDoubles/Autocommit/FakeAutocommit.ts +26 -0
- package/src/testDoubles/ReleasePropagator/FakeReleasePropagator.ts +23 -0
|
@@ -6,6 +6,8 @@ import { promisify } from 'util'
|
|
|
6
6
|
import { pathExists } from 'fs-extra'
|
|
7
7
|
import { parse } from 'jsonc-parser'
|
|
8
8
|
|
|
9
|
+
import GitAutocommit from './GitAutocommit.js'
|
|
10
|
+
|
|
9
11
|
export default class NpmAutopackage implements Autopackage {
|
|
10
12
|
public static Class?: AutopackageConstructor
|
|
11
13
|
public static chdir = chdir
|
|
@@ -214,25 +216,11 @@ export default class NpmAutopackage implements Autopackage {
|
|
|
214
216
|
}
|
|
215
217
|
|
|
216
218
|
private async commitCreatePackage() {
|
|
217
|
-
await this.
|
|
218
|
-
|
|
219
|
-
await this.gitPush()
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private async gitAddAll() {
|
|
223
|
-
await this.exec('git add .')
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
private async gitCommitCreatePackage() {
|
|
227
|
-
await this.exec(
|
|
228
|
-
`git commit -m "patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})"`
|
|
219
|
+
await this.GitAutocommit(
|
|
220
|
+
`patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
229
221
|
)
|
|
230
222
|
}
|
|
231
223
|
|
|
232
|
-
private async gitPush() {
|
|
233
|
-
await this.exec('git push')
|
|
234
|
-
}
|
|
235
|
-
|
|
236
224
|
private async updatePackageJson() {
|
|
237
225
|
this.originalPackageJson = await this.loadPackageJsonFile()
|
|
238
226
|
|
|
@@ -333,14 +321,8 @@ export default class NpmAutopackage implements Autopackage {
|
|
|
333
321
|
}
|
|
334
322
|
|
|
335
323
|
private async commitUpdatePackageJson() {
|
|
336
|
-
await this.
|
|
337
|
-
|
|
338
|
-
await this.gitPush()
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
private async gitCommitUpdatePackage() {
|
|
342
|
-
await this.exec(
|
|
343
|
-
`git commit -m "patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})"`
|
|
324
|
+
await this.GitAutocommit(
|
|
325
|
+
`patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
344
326
|
)
|
|
345
327
|
}
|
|
346
328
|
|
|
@@ -379,14 +361,8 @@ export default class NpmAutopackage implements Autopackage {
|
|
|
379
361
|
}
|
|
380
362
|
|
|
381
363
|
private async commitUpdateGitignore() {
|
|
382
|
-
await this.
|
|
383
|
-
|
|
384
|
-
await this.gitPush()
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
private async gitCommitUpdateGitignore() {
|
|
388
|
-
await this.exec(
|
|
389
|
-
`git commit -m "patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})"`
|
|
364
|
+
await this.GitAutocommit(
|
|
365
|
+
`patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
390
366
|
)
|
|
391
367
|
}
|
|
392
368
|
|
|
@@ -409,14 +385,8 @@ export default class NpmAutopackage implements Autopackage {
|
|
|
409
385
|
}
|
|
410
386
|
|
|
411
387
|
private async commitSetupVscode() {
|
|
412
|
-
await this.
|
|
413
|
-
|
|
414
|
-
await this.gitPush()
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
private async gitCommitSetupVscode() {
|
|
418
|
-
await this.exec(
|
|
419
|
-
`git commit -m "patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})"`
|
|
388
|
+
await this.GitAutocommit(
|
|
389
|
+
`patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
420
390
|
)
|
|
421
391
|
}
|
|
422
392
|
|
|
@@ -499,14 +469,8 @@ export default class NpmAutopackage implements Autopackage {
|
|
|
499
469
|
}
|
|
500
470
|
|
|
501
471
|
private async commitUpdateVscodeTasks() {
|
|
502
|
-
await this.
|
|
503
|
-
|
|
504
|
-
await this.gitPush()
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
private async gitCommitUpdateVscodeTasks() {
|
|
508
|
-
await this.exec(
|
|
509
|
-
`git commit -m "patch: update vscode tasks.json (@neurodevs/meta-node: ${this.metaNodeVersion})"`
|
|
472
|
+
await this.GitAutocommit(
|
|
473
|
+
`patch: update vscode tasks.json (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
510
474
|
)
|
|
511
475
|
}
|
|
512
476
|
|
|
@@ -556,14 +520,8 @@ export default class NpmAutopackage implements Autopackage {
|
|
|
556
520
|
}
|
|
557
521
|
|
|
558
522
|
private async commitInstallDevDependencies() {
|
|
559
|
-
await this.
|
|
560
|
-
|
|
561
|
-
await this.gitPush()
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
private async gitCommitInstallDevDependencies() {
|
|
565
|
-
await this.exec(
|
|
566
|
-
`git commit -m "patch: install default devDependencies (@neurodevs/meta-node: ${this.metaNodeVersion})"`
|
|
523
|
+
await this.GitAutocommit(
|
|
524
|
+
`patch: install default devDependencies (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
567
525
|
)
|
|
568
526
|
}
|
|
569
527
|
|
|
@@ -604,14 +562,8 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
604
562
|
`
|
|
605
563
|
|
|
606
564
|
private async commitInstallAbstractPackageTest() {
|
|
607
|
-
await this.
|
|
608
|
-
|
|
609
|
-
await this.gitPush()
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
private async gitCommitInstallAbstractPackageTest() {
|
|
613
|
-
await this.exec(
|
|
614
|
-
`git commit -m "patch: install AbstractPackageTest (@neurodevs/meta-node: ${this.metaNodeVersion})"`
|
|
565
|
+
await this.GitAutocommit(
|
|
566
|
+
`patch: install AbstractPackageTest (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
615
567
|
)
|
|
616
568
|
}
|
|
617
569
|
|
|
@@ -648,6 +600,10 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
648
600
|
private get writeFile() {
|
|
649
601
|
return NpmAutopackage.writeFile
|
|
650
602
|
}
|
|
603
|
+
|
|
604
|
+
private GitAutocommit(commitMessage: string) {
|
|
605
|
+
return GitAutocommit.Create(commitMessage)
|
|
606
|
+
}
|
|
651
607
|
}
|
|
652
608
|
|
|
653
609
|
export interface Autopackage {
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { exec as execSync } from 'node:child_process'
|
|
2
|
+
import { readFile } from 'node:fs/promises'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { promisify } from 'node:util'
|
|
5
|
+
|
|
6
|
+
import GitAutocommit from './GitAutocommit.js'
|
|
7
|
+
|
|
8
|
+
export default class NpmReleasePropagator implements ReleasePropagator {
|
|
9
|
+
public static Class?: ReleasePropagatorConstructor
|
|
10
|
+
public static exec = promisify(execSync)
|
|
11
|
+
public static readFile = readFile
|
|
12
|
+
|
|
13
|
+
private packageName: string
|
|
14
|
+
private packageVersion: string
|
|
15
|
+
private repoPaths: string[]
|
|
16
|
+
|
|
17
|
+
private currentRepoPath!: string
|
|
18
|
+
private currentPackageJson!: PackageJson
|
|
19
|
+
private metaNodeVersion!: string
|
|
20
|
+
|
|
21
|
+
protected constructor(options: ReleasePropagatorOptions) {
|
|
22
|
+
const { packageName, packageVersion, repoPaths } = options
|
|
23
|
+
|
|
24
|
+
this.packageName = packageName
|
|
25
|
+
this.packageVersion = packageVersion
|
|
26
|
+
this.repoPaths = repoPaths
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static Create(options: ReleasePropagatorOptions) {
|
|
30
|
+
return new (this.Class ?? this)(options)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async run() {
|
|
34
|
+
for (const repoPath of this.repoPaths) {
|
|
35
|
+
this.currentRepoPath = repoPath
|
|
36
|
+
|
|
37
|
+
await this.throwIfPreviousReleaseNotFound()
|
|
38
|
+
await this.installReleaseForCurrentRepo()
|
|
39
|
+
await this.gitCommitChanges()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private async throwIfPreviousReleaseNotFound() {
|
|
44
|
+
await this.loadCurrentPackageJson()
|
|
45
|
+
|
|
46
|
+
if (!(this.isDependency || this.isDevDependency)) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Cannot propagate release for ${this.packageName} because it is not listed in either dependencies or devDependencies! Please install it in the target repository before running propagation.`
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private async loadCurrentPackageJson() {
|
|
54
|
+
const raw = await this.readFile(this.currentPackageJsonPath, 'utf-8')
|
|
55
|
+
this.currentPackageJson = JSON.parse(raw)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private get currentPackageJsonPath() {
|
|
59
|
+
return `${this.currentRepoPath}/package.json`
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private get isDependency() {
|
|
63
|
+
return this.currentPackageJson?.dependencies?.[this.packageName]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private get isDevDependency() {
|
|
67
|
+
return this.currentPackageJson?.devDependencies?.[this.packageName]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private async installReleaseForCurrentRepo() {
|
|
71
|
+
await this.exec(
|
|
72
|
+
`yarn add ${this.isDevDependency ? '-D ' : ''}${this.packageName}@${this.packageVersion}`,
|
|
73
|
+
{
|
|
74
|
+
cwd: this.currentRepoPath,
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private async gitCommitChanges() {
|
|
80
|
+
await this.setCurrentMetaNodeVersion()
|
|
81
|
+
|
|
82
|
+
await this.GitAutocommit(
|
|
83
|
+
`patch: propagate ${this.packageName}@${this.packageVersion} (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private async setCurrentMetaNodeVersion() {
|
|
88
|
+
const globalRoot = await this.exec('yarn global dir')
|
|
89
|
+
|
|
90
|
+
const pkgPath = path.join(
|
|
91
|
+
globalRoot.stdout.trim(),
|
|
92
|
+
'node_modules',
|
|
93
|
+
'@neurodevs',
|
|
94
|
+
'meta-node',
|
|
95
|
+
'package.json'
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
const raw = await this.readFile(pkgPath, { encoding: 'utf-8' })
|
|
99
|
+
const pkg = JSON.parse(raw)
|
|
100
|
+
|
|
101
|
+
this.metaNodeVersion = pkg.version
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private get exec() {
|
|
105
|
+
return NpmReleasePropagator.exec
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private get readFile() {
|
|
109
|
+
return NpmReleasePropagator.readFile
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private GitAutocommit(commitMessage: string) {
|
|
113
|
+
return GitAutocommit.Create(commitMessage, this.currentRepoPath)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface ReleasePropagator {
|
|
118
|
+
run(): Promise<void>
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type ReleasePropagatorConstructor = new (
|
|
122
|
+
options: ReleasePropagatorOptions
|
|
123
|
+
) => ReleasePropagator
|
|
124
|
+
|
|
125
|
+
export interface ReleasePropagatorOptions {
|
|
126
|
+
packageName: string
|
|
127
|
+
packageVersion: string
|
|
128
|
+
repoPaths: string[]
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface PackageJson {
|
|
132
|
+
dependencies?: Record<string, string>
|
|
133
|
+
devDependencies?: Record<string, string>
|
|
134
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,14 @@ export * from './impl/GitAutocloner.js'
|
|
|
6
6
|
export { default as FakeAutocloner } from './testDoubles/Autocloner/FakeAutocloner.js'
|
|
7
7
|
export * from './testDoubles/Autocloner/FakeAutocloner.js'
|
|
8
8
|
|
|
9
|
+
// Autocommit
|
|
10
|
+
|
|
11
|
+
export { default as GitAutocommit } from './impl/GitAutocommit.js'
|
|
12
|
+
export * from './impl/GitAutocommit.js'
|
|
13
|
+
|
|
14
|
+
export { default as FakeAutocommit } from './testDoubles/Autocommit/FakeAutocommit.js'
|
|
15
|
+
export * from './testDoubles/Autocommit/FakeAutocommit.js'
|
|
16
|
+
|
|
9
17
|
// Autodocumenter
|
|
10
18
|
|
|
11
19
|
export { default as PackageAutodocumenter } from './impl/PackageAutodocumenter.js'
|
|
@@ -36,6 +44,14 @@ export * from './impl/NpmAutopackage.js'
|
|
|
36
44
|
export { default as FakeAutopackage } from './testDoubles/Autopackage/FakeAutopackage.js'
|
|
37
45
|
export * from './testDoubles/Autopackage/FakeAutopackage.js'
|
|
38
46
|
|
|
47
|
+
// ReleasePropagator
|
|
48
|
+
|
|
49
|
+
export { default as NpmReleasePropagator } from './impl/NpmReleasePropagator.js'
|
|
50
|
+
export * from './impl/NpmReleasePropagator.js'
|
|
51
|
+
|
|
52
|
+
export { default as FakeReleasePropagator } from './testDoubles/ReleasePropagator/FakeReleasePropagator.js'
|
|
53
|
+
export * from './testDoubles/ReleasePropagator/FakeReleasePropagator.js'
|
|
54
|
+
|
|
39
55
|
// SnippetKeybinder
|
|
40
56
|
|
|
41
57
|
export { default as VscodeSnippetKeybinder } from './impl/VscodeSnippetKeybinder.js'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import NpmReleasePropagator from '../impl/NpmReleasePropagator.js'
|
|
2
|
+
|
|
3
|
+
const propagator = NpmReleasePropagator.Create({
|
|
4
|
+
packageName: '@neurodevs/node-tdd',
|
|
5
|
+
packageVersion: '0.2.3',
|
|
6
|
+
repoPaths: ['/Users/ericthecurious/dev/node-ble'],
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
await propagator.run()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Autocommit } from '../../impl/GitAutocommit.js'
|
|
2
|
+
|
|
3
|
+
export default class FakeAutocommit implements Autocommit {
|
|
4
|
+
public static callsToConstructor: {
|
|
5
|
+
commitMessage?: string
|
|
6
|
+
cwd?: string
|
|
7
|
+
}[] = []
|
|
8
|
+
|
|
9
|
+
public static numCallsToRun = 0
|
|
10
|
+
|
|
11
|
+
public constructor(commitMessage?: string, cwd?: string) {
|
|
12
|
+
FakeAutocommit.callsToConstructor.push({
|
|
13
|
+
commitMessage,
|
|
14
|
+
cwd,
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async run() {
|
|
19
|
+
FakeAutocommit.numCallsToRun++
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static resetTestDouble() {
|
|
23
|
+
FakeAutocommit.callsToConstructor = []
|
|
24
|
+
FakeAutocommit.numCallsToRun = 0
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReleasePropagator,
|
|
3
|
+
ReleasePropagatorOptions,
|
|
4
|
+
} from '../../impl/NpmReleasePropagator.js'
|
|
5
|
+
|
|
6
|
+
export default class FakeReleasePropagator implements ReleasePropagator {
|
|
7
|
+
public static callsToConstructor: (ReleasePropagatorOptions | undefined)[] =
|
|
8
|
+
[]
|
|
9
|
+
public static numCallsToRun = 0
|
|
10
|
+
|
|
11
|
+
public constructor(options?: ReleasePropagatorOptions) {
|
|
12
|
+
FakeReleasePropagator.callsToConstructor.push(options)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public async run() {
|
|
16
|
+
FakeReleasePropagator.numCallsToRun++
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static resetTestDouble() {
|
|
20
|
+
FakeReleasePropagator.callsToConstructor = []
|
|
21
|
+
FakeReleasePropagator.numCallsToRun = 0
|
|
22
|
+
}
|
|
23
|
+
}
|