-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent-boilerplate.js
55 lines (40 loc) · 1.31 KB
/
component-boilerplate.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
var fs = require('fs');
var readlineSync = require('readline-sync');
function createComponentFile() {
var componentName = readlineSync.question(`Name of component: `);
var filePath = readlineSync.question(`File path: `);
var specialComponents = readlineSync.question(`Special components? `);
var styleSheet = readlineSync.question(`Stylesheet? `);
const dirCount = filePath.match(/\//g) && filePath.match(/\//g).length;
if (styleSheet === 'y' || styleSheet === 'yes' || styleSheet === 'true') {
styleSheet = `import styles from '${'../'.repeat(dirCount || 1)}styles/stylesheet';`;
} else {
styleSheet = ``;
}
var globalState = `import globalState from '${'../'.repeat(dirCount || 1)}globalState';`;
var componentDoc =
`'use strict';
import React, {
View,
Text,
${specialComponents.replace(/ /g, ',\n ')}
} from 'react-native';
${globalState}
${styleSheet}
var ${componentName} = React.createClass({
render: function() {
return (
);
}
})
export default ${componentName};`;
fs.writeFile(`${filePath}/${componentName}.js`, componentDoc, function(err){
if (err) {
console.log("Problem creating component file");
process.exit(1);
}
console.log("Component created");
process.exit(0);
})
}
export default createComponentFile