Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 3ece853

Browse files
committed
Remove modified Types in script instead of travis
1 parent 5a97494 commit 3ece853

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
language: node_js
22

33
node_js:
4-
- 'node'
5-
- 'lts/*'
4+
- "node"
5+
- "lts/*"
66

77
services:
88
- xvfb
99

1010
script:
1111
- node ./internals/scripts/generate-templates-for-linting
12-
- git checkout -- .
1312
- npm test -- --maxWorkers=4
1413
- npm run build
1514

@@ -21,7 +20,7 @@ notifications:
2120
email:
2221
on_failure: change
2322

24-
after_success: 'npm run coveralls'
23+
after_success: "npm run coveralls"
2524

2625
cache:
2726
directories:

internals/scripts/generate-templates-for-linting.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,29 @@ function removeFile(filePath) {
175175
});
176176
}
177177

178+
/**
179+
* Copy file
180+
* @param {string} filePath
181+
* @param {string} [backupFileExtension=BACKUPFILE_EXTENSION]
182+
* @returns {Promise<*>}
183+
*/
184+
async function backupFile(
185+
filePath,
186+
backupFileExtension = BACKUPFILE_EXTENSION,
187+
) {
188+
return new Promise((resolve, reject) => {
189+
const targetFile = filePath.concat(`.${backupFileExtension}`)
190+
try {
191+
fs.copyFile(filePath, targetFile, err => {
192+
if (err) throw err;
193+
});
194+
resolve(targetFile);
195+
} catch (err) {
196+
reject(err);
197+
}
198+
});
199+
}
200+
178201
/**
179202
* Overwrite file from copy
180203
* @param {string} filePath
@@ -230,6 +253,7 @@ async function generateComponent({ name, memo }) {
230253
return component;
231254
}
232255

256+
233257
/**
234258
* Test the container generator and rollback when successful
235259
* @param {string} name - Container name
@@ -271,6 +295,8 @@ async function generateContainer({ name, memo }) {
271295
* @returns {Promise<[string]>}
272296
*/
273297
async function generateComponents(components) {
298+
const typesPath = '../../app/types/index.d.ts'
299+
274300
const promises = components.map(async component => {
275301
let result;
276302

@@ -283,8 +309,20 @@ async function generateComponents(components) {
283309
return result;
284310
});
285311

312+
const backupTypes = await backupFile(typesPath)
313+
.then(feedbackToUser("Generated 'types/index.ds.ts.rbgen'"))
314+
.catch(reason => reportErrors(reason));
315+
286316
const results = await Promise.all(promises);
287317

318+
await restoreModifiedFile(backupTypes)
319+
.then(feedbackToUser(`Restored: ${typesPath}`))
320+
.catch(reason => reportErrors(reason));
321+
322+
await removeFile(backupTypes)
323+
.then(feedbackToUser(`Removed: ${backupTypes}`))
324+
.catch(reason => reportErrors(reason));
325+
288326
return results;
289327
}
290328

0 commit comments

Comments
 (0)