-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
50 lines (38 loc) · 1.53 KB
/
build.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
var fs = require( "fs" );
var path = require( "path" );
var coreR = "// @hobo-ext";
var buildR = "@hobo-dist npm run build";
var hoboF = String( fs.readFileSync( path.join( __dirname, "hobo.js" ) ) );
var child_process = require( "child_process" );
var Build = function ( modules ) {
if ( !modules.length ) {
console.log( "> [Hobo]", "Specify modules to custom build or just use hobo core." );
process.exit( 0 );
}
var hoboExt = [];
hoboF = hoboF.replace( /\.\/lib/g, "../lib" );
modules.forEach(function ( module ) {
if ( hoboExt.length ) {
hoboExt.push( ' Hobo.prototype.' + module + ' = require( "../lib/extended/' + module + '" );' );
} else {
hoboExt.push( 'Hobo.prototype.' + module + ' = require( "../lib/extended/' + module + '" );' );
}
});
hoboF = hoboF.replace( coreR, hoboExt.join( "\n" ) );
hoboF = hoboF.replace( buildR, (buildR + " -- " + modules.join( " " )) );
if ( !fs.existsSync( path.join( __dirname, "dist" ) ) ) {
fs.mkdirSync( path.join( __dirname, "dist" ) );
}
fs.writeFileSync( path.join( __dirname, "dist", "hobo.build.js" ), hoboF );
console.log( "> [Hobo]", ("Generated custom build with -- " + modules.join( " " )) );
};
// npm run build -- "foo bar baz bot"
try {
if ( process.argv.length < 3 ) {
module.exports = new Build( [] );
} else {
module.exports = new Build( process.argv[ 2 ].split( " " ) );
}
} catch ( error ) {
console.log( "[Build Error]", error );
}