/
fern.js
executable file
·91 lines (75 loc) · 2.69 KB
/
fern.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
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
'use strict';
const childProcess = require('child_process');
fern();
function fern() {
const program = require('commander');
const spaws = require('cross-spawn');
const fs = require('fs');
const wrench = require('wrench');
const glob = require('glob');
const colors = require('colors');
const path = require('path')
const notifier = require('node-notifier');
const common = require('./fern/commands/common');
require('./fern/commands/build');
require('./fern/commands/serve');
require('./fern/commands/test');
require('./fern/commands/pack');
require('./fern/commands/version');
require('./fern/commands/lint');
const setConfigPath = common.setConfigPath;
const getExtensionVersion = common.getExtensionVersion;
const createBuildWatcher = common.createBuildWatcher;
const cleanupDefaultBuild = common.cleanupDefaultBuild;
colors.setTheme({
silly: 'rainbow',
input: 'grey',
verbose: 'cyan',
prompt: 'grey',
info: 'green',
data: 'grey',
help: 'cyan',
warn: 'yellow',
debug: 'blue',
error: 'red'
});
program.command('addon-id [file]')
.action((configPath) => {
setConfigPath(configPath);
console.log(CONFIG.settings.id || 'cliqz@cliqz.com')
});
program.command('generate <type> <moduleName>')
.description('available types: module')
.action((type, moduleName) => {
if(type !== 'module') {
console.error(`Error: generate does not support type - '${type}'`);
return;
}
const modulePath = `modules/${moduleName}`;
try {
fs.lstatSync(modulePath);
// lstatSync throws error if Directory does not exist, which is
// the only situation that generator can work.
console.log(e);
console.error(`Error: module '${moduleName}' already exists`);
return;
} catch (e) {
}
wrench.copyDirSyncRecursive('fern/templates/module', modulePath);
console.log('installing module');
glob.sync(modulePath+'/**/*').forEach(path => console.log(' created'.info, path));
});
program.command('react-dev [config]')
.description('run the react-native dev server')
.action((config) => {
const cfg = setConfigPath(config || 'configs/react-native.js');
const CONFIG = cfg.CONFIG;
const OUTPUT_PATH = cfg.OUTPUT_PATH;
const projectRoots = [OUTPUT_PATH, path.resolve(process.cwd(), 'node_modules')]
const options = ['./node_modules/react-native/local-cli/cli.js', 'start',
'--projectRoots', projectRoots.join(',')]
spaws.sync('node', options, { stdio: 'inherit', stderr: 'inherit'});
});
program.parse(process.argv);
}