This repository was archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
78 lines (69 loc) · 1.71 KB
/
utils.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
73
74
75
76
77
78
const chalk = require('chalk');
const fs = require('fs-extra');
const path = require('path');
const execSync = require('child_process').execSync;
const e = module.exports = {};
e.getPaths = function() {
const pkg = JSON.parse(fs.readFileSync('./package.json'));
const src = pkg.appDir ? pkg.appDir + '/' : './';
return {
app : `${src}`,
actions : `${src}actions/`,
reducers : `${src}reducers/`,
store : `${src}store/`,
tests : {
base : `${src}__tests__/`,
actions : `${src}__tests__/actions/`,
reducers : `${src}__tests__/reducers/`,
},
};
};
e.shouldUseYarn = function() {
try {
execSync('yarnpkg --version', { stdio: 'ignore' });
return true;
} catch (e) {
return false;
}
};
e.tree = function() {
const paths = e.getPaths();
const dirs = [
paths.actions,
paths.reducers,
paths.tests.base,
paths.tests.actions,
paths.tests.reducers,
];
for (const dir of dirs) {
try {
fs.ensureDirSync(dir);
console.log(`${chalk.green('Create')} dir ${chalk.cyan(dir)}`);
} catch (err) {
console.error(`${chalk.red(err)}`);
}
}
try {
fs.ensureFileSync(`${dirs[0]}index.js`);
console.log(`${chalk.green('Create')} file ${chalk.cyan(dirs[0] + 'index.js')}`);
fs.ensureFileSync(`${dirs[1]}index.js`);
console.log(`${chalk.green('Create')} file ${chalk.cyan(dirs[1] + 'index.js')}`);
console.log();
} catch (err) {
console.error(`${chalk.red(err)}`);
}
};
e.isNative = function() {
try {
const data = fs.readFileSync('./package.json');
if(data.indexOf('react-native') >= 0){
return true;
}
else {
return false;
}
return true;
} catch (e) {
return false;
}
};