@neurodevs/meta-node 0.6.1 → 0.7.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__/modules/GitAutocloner.test.d.ts +4 -7
- package/build/__tests__/modules/GitAutocloner.test.js +31 -27
- package/build/__tests__/modules/GitAutocloner.test.js.map +1 -1
- package/build/__tests__/modules/ImplAutomodule.test.d.ts +2 -0
- package/build/__tests__/modules/ImplAutomodule.test.js +38 -56
- package/build/__tests__/modules/ImplAutomodule.test.js.map +1 -1
- package/build/__tests__/modules/NpmAutopackage.test.d.ts +6 -10
- package/build/__tests__/modules/NpmAutopackage.test.js +96 -120
- package/build/__tests__/modules/NpmAutopackage.test.js.map +1 -1
- package/build/index.d.ts +0 -6
- package/build/index.js +1 -11
- package/build/index.js.map +1 -1
- package/build/modules/GitAutocloner.d.ts +10 -8
- package/build/modules/GitAutocloner.js +32 -25
- package/build/modules/GitAutocloner.js.map +1 -1
- package/build/modules/ImplAutomodule.d.ts +7 -2
- package/build/modules/ImplAutomodule.js +30 -17
- package/build/modules/ImplAutomodule.js.map +1 -1
- package/build/modules/NpmAutopackage.d.ts +18 -14
- package/build/modules/NpmAutopackage.js +99 -89
- package/build/modules/NpmAutopackage.js.map +1 -1
- package/build/scripts/runAutomodule.js +3 -3
- package/build/scripts/runAutomodule.js.map +1 -1
- package/build/scripts/runAutopackage.js +1 -1
- package/build/scripts/runAutopackage.js.map +1 -1
- package/package.json +4 -1
- package/src/__tests__/modules/GitAutocloner.test.ts +44 -29
- package/src/__tests__/modules/ImplAutomodule.test.ts +34 -10
- package/src/__tests__/modules/NpmAutopackage.test.ts +140 -143
- package/src/index.ts +0 -11
- package/src/modules/GitAutocloner.ts +37 -26
- package/src/modules/ImplAutomodule.ts +35 -19
- package/src/modules/NpmAutopackage.ts +110 -87
- package/src/scripts/runAutomodule.ts +3 -3
- package/src/scripts/runAutopackage.ts +1 -1
- package/build/modules/pathExists.d.ts +0 -1
- package/build/modules/pathExists.js +0 -14
- package/build/modules/pathExists.js.map +0 -1
- package/build/testDoubles/fs/fakePathExists.d.ts +0 -3
- package/build/testDoubles/fs/fakePathExists.js +0 -13
- package/build/testDoubles/fs/fakePathExists.js.map +0 -1
- package/build/testDoubles/fs/fakeReadFile.d.ts +0 -5
- package/build/testDoubles/fs/fakeReadFile.js +0 -20
- package/build/testDoubles/fs/fakeReadFile.js.map +0 -1
- package/build/testDoubles/fs/fakeWriteFile.d.ts +0 -6
- package/build/testDoubles/fs/fakeWriteFile.js +0 -13
- package/build/testDoubles/fs/fakeWriteFile.js.map +0 -1
- package/src/modules/pathExists.ts +0 -10
- package/src/testDoubles/fs/fakePathExists.ts +0 -9
- package/src/testDoubles/fs/fakeReadFile.ts +0 -18
- package/src/testDoubles/fs/fakeWriteFile.ts +0 -12
|
@@ -1,38 +1,51 @@
|
|
|
1
|
+
import { exec as execSync } from 'child_process'
|
|
2
|
+
import { readFile, writeFile } from 'fs/promises'
|
|
3
|
+
import { promisify } from 'util'
|
|
1
4
|
import { test, assert, generateId } from '@sprucelabs/test-utils'
|
|
5
|
+
import {
|
|
6
|
+
callsToChdir,
|
|
7
|
+
callsToExec,
|
|
8
|
+
callsToFetch,
|
|
9
|
+
callsToReadFile,
|
|
10
|
+
callsToWriteFile,
|
|
11
|
+
fakeChdir,
|
|
12
|
+
fakeExec,
|
|
13
|
+
fakeFetch,
|
|
14
|
+
fakePathExists,
|
|
15
|
+
fakeReadFile,
|
|
16
|
+
fakeWriteFile,
|
|
17
|
+
resetCallsToChdir,
|
|
18
|
+
resetCallsToExec,
|
|
19
|
+
resetCallsToFetch,
|
|
20
|
+
resetCallsToPathExists,
|
|
21
|
+
resetCallsToReadFile,
|
|
22
|
+
resetCallsToWriteFile,
|
|
23
|
+
setFakeReadFileResult,
|
|
24
|
+
} from '@neurodevs/fake-node-core'
|
|
2
25
|
import NpmAutopackage, {
|
|
3
26
|
Autopackage,
|
|
4
27
|
AutopackageOptions,
|
|
5
28
|
} from '../../modules/NpmAutopackage'
|
|
6
29
|
import AbstractPackageTest from '../AbstractPackageTest'
|
|
7
30
|
|
|
31
|
+
const exec = promisify(execSync)
|
|
32
|
+
|
|
8
33
|
export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
9
34
|
private static instance: Autopackage
|
|
10
35
|
|
|
11
|
-
private static callsToChdir: string[] = []
|
|
12
|
-
private static callsToExecSync: string[] = []
|
|
13
|
-
private static callsToExistsSync: string[] = []
|
|
14
|
-
private static callsToFetch: { url: string; init: RequestInit }[] = []
|
|
15
|
-
private static callsToReadFileSync: { path: string; options: any }[] = []
|
|
16
|
-
private static callsToWriteFileSync: {
|
|
17
|
-
path: string
|
|
18
|
-
data: any
|
|
19
|
-
options: any
|
|
20
|
-
}[] = []
|
|
21
|
-
|
|
22
36
|
protected static async beforeEach() {
|
|
23
37
|
await super.beforeEach()
|
|
24
38
|
|
|
25
39
|
this.fakeChdir()
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
40
|
+
this.fakeExec()
|
|
41
|
+
this.fakePathExists()
|
|
28
42
|
this.fakeFetch()
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
43
|
+
this.fakeReadFile()
|
|
44
|
+
this.fakeWriteFile()
|
|
31
45
|
|
|
32
46
|
process.env.GITHUB_TOKEN = this.githubToken
|
|
33
47
|
|
|
34
48
|
this.instance = this.NpmAutopackage()
|
|
35
|
-
await this.instance.run()
|
|
36
49
|
}
|
|
37
50
|
|
|
38
51
|
@test()
|
|
@@ -56,10 +69,12 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
56
69
|
|
|
57
70
|
@test()
|
|
58
71
|
protected static async firstCreateRepoInGithubOrg() {
|
|
72
|
+
await this.run()
|
|
73
|
+
|
|
59
74
|
assert.isEqualDeep(
|
|
60
75
|
{
|
|
61
|
-
passedUrl:
|
|
62
|
-
passedInit:
|
|
76
|
+
passedUrl: callsToFetch[0]?.input,
|
|
77
|
+
passedInit: callsToFetch[0]?.init,
|
|
63
78
|
},
|
|
64
79
|
{
|
|
65
80
|
passedUrl: `https://api.github.com/orgs/${this.gitNamespace}/repos`,
|
|
@@ -86,8 +101,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
86
101
|
|
|
87
102
|
@test()
|
|
88
103
|
protected static async secondChdirToInstallDir() {
|
|
104
|
+
await this.run()
|
|
105
|
+
|
|
89
106
|
assert.isEqual(
|
|
90
|
-
|
|
107
|
+
callsToChdir[0],
|
|
91
108
|
this.installDir,
|
|
92
109
|
'Did not change to installDir!'
|
|
93
110
|
)
|
|
@@ -95,8 +112,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
95
112
|
|
|
96
113
|
@test()
|
|
97
114
|
protected static async thirdGitClone() {
|
|
115
|
+
await this.run()
|
|
116
|
+
|
|
98
117
|
assert.isEqual(
|
|
99
|
-
|
|
118
|
+
callsToExec[0],
|
|
100
119
|
`git clone https://github.com/${this.gitNamespace}/${this.packageName}.git`,
|
|
101
120
|
'Did not call git clone!'
|
|
102
121
|
)
|
|
@@ -104,8 +123,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
104
123
|
|
|
105
124
|
@test()
|
|
106
125
|
protected static async fourthSpruceCreateModule() {
|
|
126
|
+
await this.run()
|
|
127
|
+
|
|
107
128
|
assert.isEqual(
|
|
108
|
-
|
|
129
|
+
callsToExec[1],
|
|
109
130
|
this.createModuleCmd,
|
|
110
131
|
'Did not call "spruce create.module"!'
|
|
111
132
|
)
|
|
@@ -113,8 +134,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
113
134
|
|
|
114
135
|
@test()
|
|
115
136
|
protected static async fifthCommitCreatePackage() {
|
|
137
|
+
await this.run()
|
|
138
|
+
|
|
116
139
|
assert.isEqualDeep(
|
|
117
|
-
|
|
140
|
+
callsToExec.slice(2, 5),
|
|
118
141
|
['git add .', 'git commit -m "patch: create package"', 'git push'],
|
|
119
142
|
'Did not commit create package changes!'
|
|
120
143
|
)
|
|
@@ -122,8 +145,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
122
145
|
|
|
123
146
|
@test()
|
|
124
147
|
protected static async sixthChdirToPackageDir() {
|
|
148
|
+
await this.run()
|
|
149
|
+
|
|
125
150
|
assert.isEqual(
|
|
126
|
-
|
|
151
|
+
callsToChdir[1],
|
|
127
152
|
this.packageDir,
|
|
128
153
|
'Did not change to packageDir!'
|
|
129
154
|
)
|
|
@@ -131,7 +156,9 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
131
156
|
|
|
132
157
|
@test()
|
|
133
158
|
protected static async seventhReadPackageJson() {
|
|
134
|
-
|
|
159
|
+
await this.run()
|
|
160
|
+
|
|
161
|
+
assert.isEqualDeep(callsToReadFile[0], {
|
|
135
162
|
path: this.packageJsonPath,
|
|
136
163
|
options: { encoding: 'utf-8' },
|
|
137
164
|
})
|
|
@@ -139,42 +166,44 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
139
166
|
|
|
140
167
|
@test()
|
|
141
168
|
protected static async eighthUpdatePackageJson() {
|
|
142
|
-
|
|
169
|
+
await this.run()
|
|
170
|
+
|
|
171
|
+
const actual = callsToWriteFile[0]
|
|
172
|
+
|
|
173
|
+
const ordered = this.orderJsonKeys(JSON.parse(this.updatedJsonFile), [
|
|
174
|
+
'name',
|
|
175
|
+
'version',
|
|
176
|
+
'description',
|
|
177
|
+
'keywords',
|
|
178
|
+
'license',
|
|
179
|
+
'author',
|
|
180
|
+
'homepage',
|
|
181
|
+
'repository',
|
|
182
|
+
'bugs',
|
|
183
|
+
'main',
|
|
184
|
+
'bin',
|
|
185
|
+
'files',
|
|
186
|
+
'scripts',
|
|
187
|
+
'dependencies',
|
|
188
|
+
'devDependencies',
|
|
189
|
+
'jest',
|
|
190
|
+
'skill',
|
|
191
|
+
])
|
|
143
192
|
|
|
144
193
|
const expected = {
|
|
145
|
-
|
|
146
|
-
data:
|
|
147
|
-
'name',
|
|
148
|
-
'version',
|
|
149
|
-
'description',
|
|
150
|
-
'keywords',
|
|
151
|
-
'license',
|
|
152
|
-
'author',
|
|
153
|
-
'homepage',
|
|
154
|
-
'repository',
|
|
155
|
-
'bugs',
|
|
156
|
-
'main',
|
|
157
|
-
'bin',
|
|
158
|
-
'files',
|
|
159
|
-
'scripts',
|
|
160
|
-
'dependencies',
|
|
161
|
-
'devDependencies',
|
|
162
|
-
'jest',
|
|
163
|
-
'skill',
|
|
164
|
-
]),
|
|
194
|
+
file: this.packageJsonPath,
|
|
195
|
+
data: JSON.stringify(ordered, null, 2) + '\n',
|
|
165
196
|
options: { encoding: 'utf-8' },
|
|
166
197
|
}
|
|
167
198
|
|
|
168
|
-
const normalize = (s: string) => s.replace(/\s+/g, '').trim()
|
|
169
|
-
|
|
170
199
|
assert.isEqualDeep(
|
|
171
200
|
{
|
|
172
201
|
...actual,
|
|
173
|
-
data: normalize(actual.data),
|
|
202
|
+
data: this.normalize(actual.data),
|
|
174
203
|
},
|
|
175
204
|
{
|
|
176
205
|
...expected,
|
|
177
|
-
data: normalize(expected.data),
|
|
206
|
+
data: this.normalize(expected.data),
|
|
178
207
|
},
|
|
179
208
|
'Did not update package.json as expected!'
|
|
180
209
|
)
|
|
@@ -182,8 +211,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
182
211
|
|
|
183
212
|
@test()
|
|
184
213
|
protected static async ninthCommitUpdatePackage() {
|
|
214
|
+
await this.run()
|
|
215
|
+
|
|
185
216
|
assert.isEqualDeep(
|
|
186
|
-
|
|
217
|
+
callsToExec.slice(5, 8),
|
|
187
218
|
['git add .', 'git commit -m "patch: update package"', 'git push'],
|
|
188
219
|
'Did not commit update package changes!'
|
|
189
220
|
)
|
|
@@ -191,25 +222,25 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
191
222
|
|
|
192
223
|
@test()
|
|
193
224
|
protected static async tenthAddBuildDirToGitignore() {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const expected = {
|
|
197
|
-
path: this.gitignorePath,
|
|
198
|
-
data: '\nbuild/\n',
|
|
199
|
-
options: { encoding: 'utf-8', flag: 'a' },
|
|
200
|
-
}
|
|
225
|
+
await this.run()
|
|
201
226
|
|
|
202
227
|
assert.isEqualDeep(
|
|
203
|
-
|
|
204
|
-
|
|
228
|
+
callsToWriteFile[1],
|
|
229
|
+
{
|
|
230
|
+
file: this.gitignorePath,
|
|
231
|
+
data: this.buildDirGitignorePattern,
|
|
232
|
+
options: { encoding: 'utf-8', flag: 'a' },
|
|
233
|
+
},
|
|
205
234
|
'Did not update .gitignore as expected!'
|
|
206
235
|
)
|
|
207
236
|
}
|
|
208
237
|
|
|
209
238
|
@test()
|
|
210
239
|
protected static async eleventhCommitUpdateGitignore() {
|
|
240
|
+
await this.run()
|
|
241
|
+
|
|
211
242
|
assert.isEqualDeep(
|
|
212
|
-
|
|
243
|
+
callsToExec.slice(8, 11),
|
|
213
244
|
[
|
|
214
245
|
'git add .',
|
|
215
246
|
'git commit -m "patch: add build dir to gitignore"',
|
|
@@ -221,8 +252,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
221
252
|
|
|
222
253
|
@test()
|
|
223
254
|
protected static async twelfthSpruceSetupVscode() {
|
|
255
|
+
await this.run()
|
|
256
|
+
|
|
224
257
|
assert.isEqual(
|
|
225
|
-
|
|
258
|
+
callsToExec[11],
|
|
226
259
|
NpmAutopackageTest.setupVscodeCmd,
|
|
227
260
|
'Did not call "spruce setup.vscode"!'
|
|
228
261
|
)
|
|
@@ -230,8 +263,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
230
263
|
|
|
231
264
|
@test()
|
|
232
265
|
protected static async lastlyCommitVscodeChanges() {
|
|
266
|
+
await this.run()
|
|
267
|
+
|
|
233
268
|
assert.isEqualDeep(
|
|
234
|
-
|
|
269
|
+
callsToExec.slice(12, 15),
|
|
235
270
|
['git add .', 'git commit -m "patch: setup vscode"', 'git push'],
|
|
236
271
|
'Did not commit vscode changes!'
|
|
237
272
|
)
|
|
@@ -239,8 +274,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
239
274
|
|
|
240
275
|
@test()
|
|
241
276
|
protected static async doesNotCloneRepoIfDone() {
|
|
277
|
+
await this.createAndRunAutopackage()
|
|
278
|
+
|
|
242
279
|
assert.isEqual(
|
|
243
|
-
|
|
280
|
+
callsToExec.filter(
|
|
244
281
|
(cmd) =>
|
|
245
282
|
cmd ===
|
|
246
283
|
`git clone https://github.com/${this.gitNamespace}/${this.packageName}.git`
|
|
@@ -255,8 +292,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
255
292
|
await this.createAndRunAutopackage()
|
|
256
293
|
|
|
257
294
|
assert.isEqual(
|
|
258
|
-
|
|
259
|
-
.length,
|
|
295
|
+
callsToExec.filter((cmd) => cmd === this.createModuleCmd).length,
|
|
260
296
|
1,
|
|
261
297
|
'Did not call spruce create.module once!'
|
|
262
298
|
)
|
|
@@ -267,8 +303,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
267
303
|
await this.createAndRunAutopackage()
|
|
268
304
|
|
|
269
305
|
assert.isEqual(
|
|
270
|
-
|
|
271
|
-
.length,
|
|
306
|
+
callsToExec.filter((cmd) => cmd === this.setupVscodeCmd).length,
|
|
272
307
|
1,
|
|
273
308
|
'Did not call spruce setup.vscode once!'
|
|
274
309
|
)
|
|
@@ -279,7 +314,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
279
314
|
await this.createAndRunAutopackage()
|
|
280
315
|
|
|
281
316
|
assert.isEqual(
|
|
282
|
-
|
|
317
|
+
callsToExec.filter(
|
|
283
318
|
(cmd) => cmd === 'git commit -m "patch: create package"'
|
|
284
319
|
).length,
|
|
285
320
|
1,
|
|
@@ -292,7 +327,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
292
327
|
await this.createAndRunAutopackage()
|
|
293
328
|
|
|
294
329
|
assert.isEqual(
|
|
295
|
-
|
|
330
|
+
callsToExec.filter(
|
|
296
331
|
(cmd) => cmd === 'git commit -m "patch: update package"'
|
|
297
332
|
).length,
|
|
298
333
|
1,
|
|
@@ -305,7 +340,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
305
340
|
await this.createAndRunAutopackage()
|
|
306
341
|
|
|
307
342
|
assert.isEqual(
|
|
308
|
-
|
|
343
|
+
callsToExec.filter(
|
|
309
344
|
(cmd) =>
|
|
310
345
|
cmd === 'git commit -m "patch: add build dir to gitignore"'
|
|
311
346
|
).length,
|
|
@@ -319,7 +354,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
319
354
|
await this.createAndRunAutopackage()
|
|
320
355
|
|
|
321
356
|
assert.isEqual(
|
|
322
|
-
|
|
357
|
+
callsToExec.filter(
|
|
323
358
|
(cmd) => cmd === 'git commit -m "patch: setup vscode"'
|
|
324
359
|
).length,
|
|
325
360
|
1,
|
|
@@ -329,13 +364,19 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
329
364
|
|
|
330
365
|
@test()
|
|
331
366
|
protected static async doesNotOverrideOriginalDependencies() {
|
|
367
|
+
await this.createAndRunAutopackage()
|
|
368
|
+
|
|
332
369
|
assert.isEqualDeep(
|
|
333
|
-
JSON.parse(
|
|
370
|
+
JSON.parse(callsToWriteFile[0]?.data).dependencies,
|
|
334
371
|
this.dependencies,
|
|
335
372
|
'Did not update package.json as expected!'
|
|
336
373
|
)
|
|
337
374
|
}
|
|
338
375
|
|
|
376
|
+
private static async run() {
|
|
377
|
+
await this.instance.run()
|
|
378
|
+
}
|
|
379
|
+
|
|
339
380
|
private static async createAndRunAutopackage() {
|
|
340
381
|
const instance = this.NpmAutopackage()
|
|
341
382
|
await instance.run()
|
|
@@ -357,6 +398,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
357
398
|
return `${this.packageDir}/.gitignore`
|
|
358
399
|
}
|
|
359
400
|
|
|
401
|
+
private static readonly buildDirGitignorePattern = '\nbuild/\n'
|
|
402
|
+
|
|
360
403
|
private static get createModuleCmd() {
|
|
361
404
|
return `spruce create.module --name "${this.packageName}" --destination "${this.packageDir}" --description "${this.packageDescription}"`
|
|
362
405
|
}
|
|
@@ -383,73 +426,39 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
383
426
|
ordered[key] = json[key]
|
|
384
427
|
}
|
|
385
428
|
|
|
386
|
-
return
|
|
429
|
+
return ordered
|
|
387
430
|
}
|
|
388
431
|
|
|
389
432
|
private static fakeChdir() {
|
|
390
|
-
NpmAutopackage.chdir =
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
this.callsToChdir = []
|
|
433
|
+
NpmAutopackage.chdir = fakeChdir
|
|
434
|
+
resetCallsToChdir()
|
|
394
435
|
}
|
|
395
436
|
|
|
396
|
-
private static
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
private static fakeExistsSync() {
|
|
405
|
-
// @ts-ignore
|
|
406
|
-
NpmAutopackage.existsSync = (path: string) => {
|
|
407
|
-
if (this.callsToExistsSync.includes(path)) {
|
|
408
|
-
this.callsToExistsSync.push(path)
|
|
409
|
-
return true
|
|
410
|
-
} else {
|
|
411
|
-
this.callsToExistsSync.push(path)
|
|
412
|
-
return false
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
this.callsToExistsSync = []
|
|
437
|
+
private static fakeExec() {
|
|
438
|
+
NpmAutopackage.exec = fakeExec as unknown as typeof exec
|
|
439
|
+
resetCallsToExec()
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
private static fakePathExists() {
|
|
443
|
+
NpmAutopackage.pathExists = fakePathExists
|
|
444
|
+
resetCallsToPathExists()
|
|
416
445
|
}
|
|
417
446
|
|
|
418
447
|
private static fakeFetch() {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
this.callsToReadFileSync.filter(
|
|
434
|
-
({ path }) => path === this.packageJsonPath
|
|
435
|
-
).length > 1
|
|
436
|
-
) {
|
|
437
|
-
return this.updatedJsonFile
|
|
438
|
-
}
|
|
439
|
-
return this.originalJsonFile
|
|
440
|
-
} else if (path === this.gitignorePath) {
|
|
441
|
-
if (
|
|
442
|
-
this.callsToReadFileSync.filter(
|
|
443
|
-
({ path }) => path === this.gitignorePath
|
|
444
|
-
).length > 1
|
|
445
|
-
) {
|
|
446
|
-
return 'node_modules/\n\nbuild/\n'
|
|
447
|
-
}
|
|
448
|
-
return 'node_modules/\n'
|
|
449
|
-
}
|
|
450
|
-
return ''
|
|
451
|
-
}
|
|
452
|
-
this.callsToReadFileSync = []
|
|
448
|
+
NpmAutopackage.fetch = fakeFetch as unknown as typeof fetch
|
|
449
|
+
resetCallsToFetch()
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private static fakeReadFile() {
|
|
453
|
+
NpmAutopackage.readFile = fakeReadFile as unknown as typeof readFile
|
|
454
|
+
resetCallsToReadFile()
|
|
455
|
+
|
|
456
|
+
setFakeReadFileResult(this.originalJsonFile)
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
private static fakeWriteFile() {
|
|
460
|
+
NpmAutopackage.writeFile = fakeWriteFile as unknown as typeof writeFile
|
|
461
|
+
resetCallsToWriteFile()
|
|
453
462
|
}
|
|
454
463
|
|
|
455
464
|
private static get originalJsonFile() {
|
|
@@ -486,18 +495,6 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
486
495
|
})
|
|
487
496
|
}
|
|
488
497
|
|
|
489
|
-
private static fakeWriteFileSync() {
|
|
490
|
-
// @ts-ignore
|
|
491
|
-
NpmAutopackage.writeFileSync = (
|
|
492
|
-
path: string,
|
|
493
|
-
data: any,
|
|
494
|
-
options: any
|
|
495
|
-
) => {
|
|
496
|
-
this.callsToWriteFileSync.push({ path, data, options })
|
|
497
|
-
}
|
|
498
|
-
this.callsToWriteFileSync = []
|
|
499
|
-
}
|
|
500
|
-
|
|
501
498
|
private static readonly packageName = generateId()
|
|
502
499
|
private static readonly packageDescription = generateId()
|
|
503
500
|
private static readonly gitNamespace = generateId()
|
package/src/index.ts
CHANGED
|
@@ -29,14 +29,3 @@ export * from './modules/NpmAutopackage'
|
|
|
29
29
|
|
|
30
30
|
export { default as FakeAutopackage } from './testDoubles/Autopackage/FakeAutopackage'
|
|
31
31
|
export * from './testDoubles/Autopackage/FakeAutopackage'
|
|
32
|
-
|
|
33
|
-
// fs
|
|
34
|
-
|
|
35
|
-
export { default as fakePathExists } from './testDoubles/fs/fakePathExists'
|
|
36
|
-
export * from './testDoubles/fs/fakePathExists'
|
|
37
|
-
|
|
38
|
-
export { default as fakeReadFile } from './testDoubles/fs/fakeReadFile'
|
|
39
|
-
export * from './testDoubles/fs/fakeReadFile'
|
|
40
|
-
|
|
41
|
-
export { default as fakeWriteFile } from './testDoubles/fs/fakeWriteFile'
|
|
42
|
-
export * from './testDoubles/fs/fakeWriteFile'
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { execSync } from 'child_process'
|
|
2
|
-
import { existsSync } from 'fs'
|
|
1
|
+
import { exec as execSync } from 'child_process'
|
|
3
2
|
import { chdir } from 'process'
|
|
3
|
+
import { promisify } from 'util'
|
|
4
|
+
import { pathExists } from 'fs-extra'
|
|
4
5
|
|
|
5
6
|
export default class GitAutocloner implements Autocloner {
|
|
6
7
|
public static Class?: AutoclonerConstructor
|
|
7
|
-
public static
|
|
8
|
-
public static
|
|
8
|
+
public static chdir = chdir
|
|
9
|
+
public static exec = promisify(execSync)
|
|
10
|
+
public static pathExists = pathExists
|
|
9
11
|
|
|
10
12
|
private urls!: string[]
|
|
11
13
|
private dirPath!: string
|
|
@@ -25,19 +27,22 @@ export default class GitAutocloner implements Autocloner {
|
|
|
25
27
|
this.urls = urls
|
|
26
28
|
this.dirPath = dirPath
|
|
27
29
|
|
|
28
|
-
this.throwIfDirPathDoesNotExist()
|
|
30
|
+
await this.throwIfDirPathDoesNotExist()
|
|
31
|
+
|
|
29
32
|
this.changeDirectoryToDirPath()
|
|
30
|
-
this.cloneReposFromUrls()
|
|
33
|
+
await this.cloneReposFromUrls()
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
private throwIfDirPathDoesNotExist() {
|
|
34
|
-
|
|
36
|
+
private async throwIfDirPathDoesNotExist() {
|
|
37
|
+
const dirPathExists = await this.checkIfDirPathExists()
|
|
38
|
+
|
|
39
|
+
if (!dirPathExists) {
|
|
35
40
|
this.throwDirPathDoesNotExist()
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
private
|
|
40
|
-
return this.
|
|
44
|
+
private async checkIfDirPathExists() {
|
|
45
|
+
return this.pathExists(this.dirPath)
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
private throwDirPathDoesNotExist() {
|
|
@@ -45,26 +50,28 @@ export default class GitAutocloner implements Autocloner {
|
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
private changeDirectoryToDirPath() {
|
|
48
|
-
chdir(this.dirPath)
|
|
53
|
+
this.chdir(this.dirPath)
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
private cloneReposFromUrls() {
|
|
52
|
-
this.urls
|
|
56
|
+
private async cloneReposFromUrls() {
|
|
57
|
+
for (const url of this.urls) {
|
|
53
58
|
this.currentUrl = url
|
|
54
|
-
this.cloneCurrentUrl()
|
|
55
|
-
}
|
|
59
|
+
await this.cloneCurrentUrl()
|
|
60
|
+
}
|
|
56
61
|
}
|
|
57
62
|
|
|
58
|
-
private cloneCurrentUrl() {
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
private async cloneCurrentUrl() {
|
|
64
|
+
const currentRepoExists = await this.checkIfCurrentRepoExists()
|
|
65
|
+
|
|
66
|
+
if (!currentRepoExists) {
|
|
67
|
+
await this.tryToCloneRepo()
|
|
61
68
|
} else {
|
|
62
69
|
this.log.info(`Repo exists, skipping: ${this.currentRepoName}!`)
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
private
|
|
67
|
-
return this.
|
|
73
|
+
private async checkIfCurrentRepoExists() {
|
|
74
|
+
return this.pathExists(this.currentRepoName)
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
private get currentRepoName() {
|
|
@@ -73,9 +80,9 @@ export default class GitAutocloner implements Autocloner {
|
|
|
73
80
|
|
|
74
81
|
private readonly regexForRepoName = /\/([a-zA-Z0-9_.-]+)\.git/
|
|
75
82
|
|
|
76
|
-
private tryToCloneRepo() {
|
|
83
|
+
private async tryToCloneRepo() {
|
|
77
84
|
try {
|
|
78
|
-
this.
|
|
85
|
+
await this.exec(`git clone ${this.currentUrl}`)
|
|
79
86
|
} catch (err: any) {
|
|
80
87
|
this.currentError = err
|
|
81
88
|
this.throwGitCloneFailed()
|
|
@@ -90,12 +97,16 @@ export default class GitAutocloner implements Autocloner {
|
|
|
90
97
|
return `Git clone failed for repo: ${this.currentUrl}!\n\n${this.currentError}\n\n`
|
|
91
98
|
}
|
|
92
99
|
|
|
93
|
-
private get
|
|
94
|
-
return GitAutocloner.
|
|
100
|
+
private get chdir() {
|
|
101
|
+
return GitAutocloner.chdir
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private get exec() {
|
|
105
|
+
return GitAutocloner.exec
|
|
95
106
|
}
|
|
96
107
|
|
|
97
|
-
private get
|
|
98
|
-
return GitAutocloner.
|
|
108
|
+
private get pathExists() {
|
|
109
|
+
return GitAutocloner.pathExists
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
|