@neurodevs/meta-node 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/__tests__/AbstractPackageTest.d.ts +5 -0
- package/build/__tests__/AbstractPackageTest.js +16 -0
- package/build/__tests__/AbstractPackageTest.js.map +1 -0
- package/build/__tests__/modules/GitAutocloner.test.d.ts +2 -3
- package/build/__tests__/modules/GitAutocloner.test.js +3 -38
- package/build/__tests__/modules/GitAutocloner.test.js.map +1 -1
- package/build/__tests__/modules/ImplAutomodule.test.d.ts +13 -4
- package/build/__tests__/modules/ImplAutomodule.test.js +96 -4
- package/build/__tests__/modules/ImplAutomodule.test.js.map +1 -1
- package/build/__tests__/modules/NpmAutopackage.test.d.ts +2 -2
- package/build/__tests__/modules/NpmAutopackage.test.js +3 -35
- package/build/__tests__/modules/NpmAutopackage.test.js.map +1 -1
- package/build/__tests__/modules/PackageAutodocumenter.test.d.ts +7 -0
- package/build/__tests__/modules/PackageAutodocumenter.test.js +31 -0
- package/build/__tests__/modules/PackageAutodocumenter.test.js.map +1 -0
- package/build/index.d.ts +6 -0
- package/build/index.js +11 -1
- package/build/index.js.map +1 -1
- package/build/modules/ImplAutomodule.d.ts +16 -1
- package/build/modules/ImplAutomodule.js +76 -3
- package/build/modules/ImplAutomodule.js.map +1 -1
- package/build/modules/PackageAutodocumenter.d.ts +8 -0
- package/build/modules/PackageAutodocumenter.js +10 -0
- package/build/modules/PackageAutodocumenter.js.map +1 -0
- package/build/scripts/runAutomodule.js +3 -2
- package/build/scripts/runAutomodule.js.map +1 -1
- package/build/testDoubles/Autodocumenter/FakeAutodocumenter.d.ts +6 -0
- package/build/testDoubles/Autodocumenter/FakeAutodocumenter.js +13 -0
- package/build/testDoubles/Autodocumenter/FakeAutodocumenter.js.map +1 -0
- package/build/testDoubles/fs/fakeReadFile.d.ts +5 -0
- package/build/testDoubles/fs/fakeReadFile.js +20 -0
- package/build/testDoubles/fs/fakeReadFile.js.map +1 -0
- package/build/testDoubles/fs/fakeWriteFile.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/AbstractPackageTest.ts +11 -0
- package/src/__tests__/modules/GitAutocloner.test.ts +3 -10
- package/src/__tests__/modules/ImplAutomodule.test.ts +123 -9
- package/src/__tests__/modules/NpmAutopackage.test.ts +3 -6
- package/src/__tests__/modules/PackageAutodocumenter.test.ts +24 -0
- package/src/index.ts +11 -0
- package/src/modules/ImplAutomodule.ts +102 -6
- package/src/modules/PackageAutodocumenter.ts +13 -0
- package/src/scripts/runAutomodule.ts +4 -2
- package/src/testDoubles/Autodocumenter/FakeAutodocumenter.ts +13 -0
- package/src/testDoubles/fs/fakeReadFile.ts +18 -0
- package/src/testDoubles/fs/fakeWriteFile.ts +4 -1
|
@@ -1,22 +1,33 @@
|
|
|
1
|
-
import { writeFile } from 'fs/promises'
|
|
1
|
+
import { readFile, writeFile } from 'fs/promises'
|
|
2
2
|
import path from 'path'
|
|
3
3
|
import pathExists from './pathExists'
|
|
4
4
|
|
|
5
5
|
export default class ImplAutomodule implements Automodule {
|
|
6
6
|
public static Class?: AutomoduleConstructor
|
|
7
7
|
public static pathExists = pathExists
|
|
8
|
+
public static readFile = readFile
|
|
8
9
|
public static writeFile = writeFile
|
|
9
10
|
|
|
10
11
|
private testSaveDir: string
|
|
11
12
|
private moduleSaveDir: string
|
|
13
|
+
private fakeSaveDir: string
|
|
12
14
|
private interfaceName: string
|
|
13
15
|
private implName: string
|
|
14
16
|
|
|
17
|
+
private originalIndexFile!: string
|
|
18
|
+
|
|
15
19
|
protected constructor(options: AutomoduleOptions) {
|
|
16
|
-
const {
|
|
20
|
+
const {
|
|
21
|
+
testSaveDir,
|
|
22
|
+
moduleSaveDir,
|
|
23
|
+
fakeSaveDir,
|
|
24
|
+
interfaceName,
|
|
25
|
+
implName,
|
|
26
|
+
} = options
|
|
17
27
|
|
|
18
28
|
this.testSaveDir = testSaveDir
|
|
19
29
|
this.moduleSaveDir = moduleSaveDir
|
|
30
|
+
this.fakeSaveDir = fakeSaveDir
|
|
20
31
|
this.interfaceName = interfaceName
|
|
21
32
|
this.implName = implName
|
|
22
33
|
}
|
|
@@ -28,16 +39,20 @@ export default class ImplAutomodule implements Automodule {
|
|
|
28
39
|
public async run() {
|
|
29
40
|
await this.throwIfTestDirDoesNotExist()
|
|
30
41
|
await this.throwIfModuleDirDoesNotExist()
|
|
42
|
+
await this.throwIfFakeDirDoesNotExist()
|
|
31
43
|
|
|
32
44
|
await this.createTestFile()
|
|
33
45
|
await this.createModuleFile()
|
|
46
|
+
await this.createFakeFile()
|
|
47
|
+
|
|
48
|
+
await this.updateIndexFileExports()
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
private async throwIfTestDirDoesNotExist() {
|
|
37
52
|
const testDirExists = await this.pathExists(this.testSaveDir)
|
|
38
53
|
|
|
39
54
|
if (!testDirExists) {
|
|
40
|
-
throw
|
|
55
|
+
this.throw(`testSaveDir does not exist: ${this.testSaveDir}!`)
|
|
41
56
|
}
|
|
42
57
|
}
|
|
43
58
|
|
|
@@ -45,12 +60,22 @@ export default class ImplAutomodule implements Automodule {
|
|
|
45
60
|
const moduleDirExists = await this.pathExists(this.moduleSaveDir)
|
|
46
61
|
|
|
47
62
|
if (!moduleDirExists) {
|
|
48
|
-
throw
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
this.throw(`moduleSaveDir does not exist: ${this.moduleSaveDir}!`)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private async throwIfFakeDirDoesNotExist() {
|
|
68
|
+
const fakeDirExists = await this.pathExists(this.fakeSaveDir)
|
|
69
|
+
|
|
70
|
+
if (!fakeDirExists) {
|
|
71
|
+
this.throw(`fakeSaveDir does not exist: ${this.fakeSaveDir}!`)
|
|
51
72
|
}
|
|
52
73
|
}
|
|
53
74
|
|
|
75
|
+
private throw(err: string) {
|
|
76
|
+
throw new Error(err)
|
|
77
|
+
}
|
|
78
|
+
|
|
54
79
|
private async createTestFile() {
|
|
55
80
|
await this.writeFile(this.testFileName, this.testFilePattern)
|
|
56
81
|
}
|
|
@@ -67,10 +92,33 @@ export default class ImplAutomodule implements Automodule {
|
|
|
67
92
|
return path.join(this.moduleSaveDir, `${this.implName}.ts`)
|
|
68
93
|
}
|
|
69
94
|
|
|
95
|
+
private async createFakeFile() {
|
|
96
|
+
await this.writeFile(this.fakeFileName, this.fakeFilePattern)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private get fakeFileName() {
|
|
100
|
+
return path.join(this.fakeSaveDir, `Fake${this.interfaceName}.ts`)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private async updateIndexFileExports() {
|
|
104
|
+
this.originalIndexFile = await this.loadOriginalIndexFile()
|
|
105
|
+
await this.writeFile(this.indexFilePath, this.sortedIndexFile)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private async loadOriginalIndexFile() {
|
|
109
|
+
return await this.readFile(this.indexFilePath, 'utf-8')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private readonly indexFilePath = './src/index.ts'
|
|
113
|
+
|
|
70
114
|
private get pathExists() {
|
|
71
115
|
return ImplAutomodule.pathExists
|
|
72
116
|
}
|
|
73
117
|
|
|
118
|
+
private get readFile() {
|
|
119
|
+
return ImplAutomodule.readFile
|
|
120
|
+
}
|
|
121
|
+
|
|
74
122
|
private get writeFile() {
|
|
75
123
|
return ImplAutomodule.writeFile
|
|
76
124
|
}
|
|
@@ -118,6 +166,53 @@ export default class ImplAutomodule implements Automodule {
|
|
|
118
166
|
export type ${this.interfaceName}Constructor = new () => ${this.interfaceName}
|
|
119
167
|
`
|
|
120
168
|
}
|
|
169
|
+
|
|
170
|
+
private get fakeFilePattern() {
|
|
171
|
+
return `
|
|
172
|
+
import { ${this.interfaceName} } from '../../modules/${this.implName}'
|
|
173
|
+
|
|
174
|
+
export default class Fake${this.interfaceName} implements ${this.interfaceName} {
|
|
175
|
+
public static numCallsToConstructor = 0
|
|
176
|
+
|
|
177
|
+
public constructor() {
|
|
178
|
+
Fake${this.interfaceName}.numCallsToConstructor++
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
public static resetTestDouble() {
|
|
182
|
+
Fake${this.interfaceName}.numCallsToConstructor = 0
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
`
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private get indexFilePattern() {
|
|
189
|
+
return `
|
|
190
|
+
${this.originalIndexFile}
|
|
191
|
+
|
|
192
|
+
// ${this.interfaceName}
|
|
193
|
+
|
|
194
|
+
export { default as ${this.implName} } from './modules/${this.implName}'
|
|
195
|
+
export * from './modules/${this.implName}'
|
|
196
|
+
|
|
197
|
+
export { default as Fake${this.interfaceName} } from './testDoubles/${this.interfaceName}/Fake${this.interfaceName}'
|
|
198
|
+
export * from './testDoubles/${this.interfaceName}/Fake${this.interfaceName}'
|
|
199
|
+
`
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private get sortedIndexFile() {
|
|
203
|
+
const blocks = this.indexFilePattern
|
|
204
|
+
.split(/(?=\/\/)/)
|
|
205
|
+
.map((s) => s.trim())
|
|
206
|
+
.filter(Boolean)
|
|
207
|
+
|
|
208
|
+
blocks.sort((a, b) => {
|
|
209
|
+
const aKey = a.match(/^\/\/\s*([^\n]*)/)?.[1]?.trim() ?? ''
|
|
210
|
+
const bKey = b.match(/^\/\/\s*([^\n]*)/)?.[1]?.trim() ?? ''
|
|
211
|
+
return aKey.localeCompare(bKey)
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
return blocks.join('\n\n')
|
|
215
|
+
}
|
|
121
216
|
}
|
|
122
217
|
|
|
123
218
|
export interface Automodule {
|
|
@@ -131,6 +226,7 @@ export type AutomoduleConstructor = new (
|
|
|
131
226
|
export interface AutomoduleOptions {
|
|
132
227
|
testSaveDir: string
|
|
133
228
|
moduleSaveDir: string
|
|
229
|
+
fakeSaveDir: string
|
|
134
230
|
interfaceName: string
|
|
135
231
|
implName: string
|
|
136
232
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default class PackageAutodocumenter implements Autodocumenter {
|
|
2
|
+
public static Class?: AutodocumenterConstructor
|
|
3
|
+
|
|
4
|
+
protected constructor() {}
|
|
5
|
+
|
|
6
|
+
public static Create() {
|
|
7
|
+
return new (this.Class ?? this)()
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Autodocumenter {}
|
|
12
|
+
|
|
13
|
+
export type AutodocumenterConstructor = new () => Autodocumenter
|
|
@@ -7,8 +7,10 @@ async function main() {
|
|
|
7
7
|
testSaveDir:
|
|
8
8
|
'/Users/ericthecurious/dev/meta-node/src/__tests__/modules',
|
|
9
9
|
moduleSaveDir: '/Users/ericthecurious/dev/meta-node/src/modules',
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
fakeSaveDir:
|
|
11
|
+
'/Users/ericthecurious/dev/meta-node/src/testDoubles/Autodocumenter',
|
|
12
|
+
interfaceName: 'Autodocumenter',
|
|
13
|
+
implName: 'PackageAutodocumenter',
|
|
12
14
|
})
|
|
13
15
|
|
|
14
16
|
await instance.run()
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Autodocumenter } from '../../modules/PackageAutodocumenter'
|
|
2
|
+
|
|
3
|
+
export default class FakeAutodocumenter implements Autodocumenter {
|
|
4
|
+
public static numCallsToConstructor = 0
|
|
5
|
+
|
|
6
|
+
public constructor() {
|
|
7
|
+
FakeAutodocumenter.numCallsToConstructor++
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public static resetTestDouble() {
|
|
11
|
+
FakeAutodocumenter.numCallsToConstructor = 0
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { generateId } from '@sprucelabs/test-utils'
|
|
2
|
+
|
|
3
|
+
export let callsToReadFile: string[] = []
|
|
4
|
+
|
|
5
|
+
export function resetCallsToReadFile() {
|
|
6
|
+
callsToReadFile = []
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export let fakeReadFileResult = generateId()
|
|
10
|
+
|
|
11
|
+
export function setFakeReadFileResult(result: string) {
|
|
12
|
+
fakeReadFileResult = result
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default async function fakeReadFile(file: string) {
|
|
16
|
+
callsToReadFile.push(file)
|
|
17
|
+
return fakeReadFileResult
|
|
18
|
+
}
|