source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/utils/npm/build.js@ 28897

Last change on this file since 28897 was 28897, checked in by davidb, 10 years ago

GUI front-end to server base plus web page content

File size: 3.2 KB
Line 
1/**
2 * Builds node_modules three and three-math
3 *
4 * Expects a single command line argument that is the build version in the format 0.54.4-dev
5 *
6 * @author bhouston / http://exocortex.com
7 */
8
9var fs = require( "fs" );
10var cp = require('child_process');
11
12var commandLineArguments = process.argv.splice(2);
13
14var outputRootDir = "./node_modules";
15var inputDir = "../../build";
16var readmeFileName = "../../README.md";
17
18var headerFileName = "./header.js";
19var footerFileName = "./footer.js";
20
21if( commandLineArguments.length == 0 ) {
22 throw new Error( "build version must be specified as a command line argument (e.g. 0.54.3-dev)");
23}
24var buildVersion = commandLineArguments[0];
25
26
27var concateFiles = function ( inputFileNames, outputFileName ) {
28 var buffer = [];
29 for ( var i = 0; i < inputFileNames.length; i++ ) {
30 buffer.push(
31 fs.readFileSync( inputFileNames[i], 'utf8' )
32 );
33 }
34
35 var combinedContents = buffer.join("");
36 fs.writeFileSync( outputFileName, combinedContents, 'utf8' );
37}
38
39var createTemplatedFile = function ( templateFileName, replaceSet, outputFileName ) {
40 var templateContents = fs.readFileSync( templateFileName, 'utf8' );
41 for( var token in replaceSet ) {
42 templateContents = templateContents.replace( "%"+token+"%", replaceSet[token] );
43 }
44 fs.writeFileSync( outputFileName, templateContents, 'utf8' );
45}
46
47var copyFile = function( sourceFileName, destinationFileName ) {
48
49 var contents = fs.readFileSync( sourceFileName, 'utf8' );
50 fs.writeFileSync( destinationFileName, contents, 'utf8' );
51
52}
53
54var buildModule = function ( name, version ) {
55
56 if( ! fs.existsSync( outputRootDir ) ) {
57 fs.mkdirSync( outputRootDir );
58 }
59
60 var outputModuleDir = outputRootDir + "/" + name;
61 if( ! fs.existsSync( outputModuleDir ) ) {
62 fs.mkdirSync( outputModuleDir );
63 }
64 // make directory moduleDir
65
66 var inputRawFileName = inputDir + "/" + name + ".js";
67 var outputRawFileName = outputModuleDir + "/" + name + ".js";
68
69 concateFiles( [ headerFileName, inputRawFileName, footerFileName ], outputRawFileName );
70
71 var inputMinifiedFileName = inputDir + "/" + name + ".min.js";
72 var outputMinifiedFileName = outputModuleDir + "/" + name + ".min.js";
73
74 concateFiles( [ headerFileName, inputMinifiedFileName, footerFileName ], outputMinifiedFileName );
75
76 var templatePackageFileName = "./" + name + ".package.json";
77 var replaceSet = {
78 "VERSION": buildVersion
79 };
80 var outputPackageFileName = outputModuleDir + "/package.json";
81 createTemplatedFile( templatePackageFileName, replaceSet, outputPackageFileName );
82
83 var outputReadmeFileName = outputModuleDir + "/README.md";
84 copyFile( readmeFileName, outputReadmeFileName );
85}
86
87var cmdExe, args;
88if (process.platform === 'win32' || process.platform === 'win64') {
89 cmdExe = "cmd.exe";
90 args = [ "/c", "build_all.bat" ];
91} else {
92 cmdExe = './build_all.sh';
93 args = [];
94}
95var opts = { "cwd": "../build" };
96var buildAll = cp.spawn( cmdExe, args, opts );
97
98buildAll.stdout.on('data', function (data) {
99 console.log('stdout: ' + data);
100});
101
102buildAll.stderr.on('data', function (data) {
103 console.log('stderr: ' + data);
104});
105
106buildAll.on( 'exit', function ( exitCode ) {
107 console.log( "exitCode: " + exitCode );
108 buildModule( "three" );
109 buildModule( "three-math" );
110});
Note: See TracBrowser for help on using the repository browser.