forked from cliqz-oss/browser-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfern.js
executable file
·116 lines (95 loc) · 3.39 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/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 || '[email protected]')
});
program.command('test-webext')
.action(() => {
const cfg = setConfigPath('./configs/cliqzium.json');
const CONFIG = cfg.CONFIG;
const OUTPUT_PATH = cfg.OUTPUT_PATH;
const watcher = createBuildWatcher();
let runner;
watcher.on('change', () => {
notifier.notify({
title: 'Fern',
message: 'Build complete',
time: 1500
});
if (runner) {
runner.kill('SIGTERM');
}
runner = childProcess.spawn('node', [path.join(process.cwd(), 'fern/run_selenium_tests.es')]);
process.on('exit', () => { runner.kill('SIGTERM'); });
});
});
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.json');
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);
}