-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathremoveDemo.js
72 lines (63 loc) · 1.83 KB
/
removeDemo.js
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
61
62
63
64
65
66
67
68
69
70
71
72
// This script removes demo app files
import rimraf from 'rimraf';
import fs from 'fs';
import {chalkSuccess} from './chalkConfig';
/* eslint-disable no-console */
const pathsToRemove = [
'./src/actions/*',
'./src/utils',
'./src/components/*',
'./src/constants/*',
'./src/containers/*',
'./src/images',
'./src/reducers/*',
'./src/store/store.spec.js',
'./src/styles',
'./src/index.js',
'./tools/removeDemo.js'
];
const filesToCreate = [
{
path: './src/components/emptyTest.spec.js',
content: '// Must have at least one test file in this directory or Mocha will throw an error.'
},
{
path: './src/index.js',
content: '// Set up your application entry point here...'
},
{
path: './src/reducers/index.js',
content: '// Set up your root reducer here...\n import { combineReducers } from \'redux\';\n export default combineReducers;'
}
];
function removePath(path, callback) {
rimraf(path, error => {
if (error) throw new Error(error);
callback();
});
}
function createFile(file) {
fs.writeFile(file.path, file.content, error => {
if (error) throw new Error(error);
});
}
function removePackageJsonScriptEntry(scriptName) {
const packageJsonPath = './package.json';
let fileData = fs.readFileSync(packageJsonPath);
let content = JSON.parse(fileData);
delete content.scripts[scriptName];
fs.writeFileSync(packageJsonPath,
JSON.stringify(content, null, 2) + '\n');
}
let numPathsRemoved = 0;
pathsToRemove.map(path => {
removePath(path, () => {
numPathsRemoved++;
if (numPathsRemoved === pathsToRemove.length) { // All paths have been processed
// Now we can create files since we're done deleting.
filesToCreate.map(file => createFile(file));
}
});
});
removePackageJsonScriptEntry('remove-demo');
console.log(chalkSuccess('Demo app removed.'));