-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
106 lines (84 loc) · 2.14 KB
/
index.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
/*
* Main
*/
var path = require('path');
var fs = require('fs');
var debug = require('debug')('BrewUI');
var Promise = require('bluebird');
var _ = require('lodash-node');
var pkg = require('./package.json');
/*
* Build
*
* @method build
* @param {String} distPath
* @param {Boolean} force optional
* @return {Promise}
*/
function build(distPath, force) {
return new Promise(function (resolve, reject) {
// Check for dev dependencies
var isDevDependencies = _.every(pkg.devDependencies, function (version, name) {
var available = true;
try {
require.resolve(name);
} catch(e) {
available = false;
}
return available;
});
if(!isDevDependencies) {
return reject('Install "devDependencies" first.');
}
var gulpfile = require('./gulpfile');
var manifestPath = path.join(distPath, 'manifest.json');
var manifest;
// Check for manifest
if(fs.existsSync(manifestPath)) {
manifest = require(manifestPath);
}
// Do not build if the same version and not forced
if(force !== true && manifest && manifest.version === pkg.version) {
debug('Already built');
return resolve(false);
}
debug('Start build');
gulpfile.build(distPath, function (err) {
if(err) {
debug('Build error', err);
return reject(err);
}
debug('Build is done');
resolve(true);
});
});
}
/*
* Extent to isomorphic
*
* requires jsx support
*
* @method extendToIsomorphic
*/
function extendToIsomorphic () {
debug('Generate Isomorphic interfaces: .app, .client');
exports.App = require('./src/scripts/app/app');
exports.Fetcher = require('./src/scripts/app/lib/Fetcher');
exports.React = require('react');
exports.actions = {
navigateAction: require('flux-router-component').navigateAction
};
}
/*
* Get static path
*
* @method getStaticPath
*/
function getStaticPath () {
return path.join(__dirname, 'build');
}
// Main interface
exports.build = build;
exports.routes = require('./src/scripts/app/config/routes');
exports.isomorphic = extendToIsomorphic;
exports.getStaticPath = getStaticPath;