-
Notifications
You must be signed in to change notification settings - Fork 3
/
_post_build.ts
60 lines (50 loc) · 1.33 KB
/
_post_build.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { isPackageExists } from './src/util';
import * as fs from 'fs';
import path from 'path';
// add additional files
fs.copyFileSync('README.md', 'dist/README.md');
// cleanup dist package.json
const propertiesToDelete: string[] = [
'lint-staged',
'commitlint',
'config',
'scripts',
'devDependencies'
];
if (isPackageExists('dist')) {
const packageJson = require('./dist/package.json');
propertiesToDelete.forEach(property => {
delete packageJson[property];
});
try {
fs.writeFileSync('dist/package.json', JSON.stringify(packageJson, null, 2));
} catch {
console.log('error');
}
}
// cleanup dist folder content
const paths = ['dist', 'dist/src', 'dist/src/bin'];
const filesToDelete = paths.reduce((acc, dir) => {
try {
const dirContent = fs.readdirSync(dir);
acc = acc.concat(
dirContent
.filter(file => file.match(/.*\.(js.map|d.ts)$/gi))
.map(file => path.join(dir, file))
);
} catch (err) {
console.error(err);
}
return acc;
}, [] as string[]);
filesToDelete.push('dist/_post_build.js');
filesToDelete.push('dist/src/bin/ngvm.test.js');
filesToDelete.forEach(file => {
try {
fs.unlinkSync(file);
} catch {}
});
const pathsToDelete: string[] = ['dist/src/__mocks__'];
pathsToDelete.forEach(path => {
fs.rmSync(path, { recursive: true, force: true });
});