forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-js.js
More file actions
executable file
·147 lines (129 loc) · 4.37 KB
/
Copy pathbuild-js.js
File metadata and controls
executable file
·147 lines (129 loc) · 4.37 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env node
/* global Promise */
/** @file Build script for JS assets in the code-studio package, which is loaded
by dashboard (our "Code Studio" Rails app). */
'use strict';
var _ = require('lodash');
var build_commands = require('./build-commands');
var chalk = require('chalk');
var commander = require('commander');
var gaze = require('gaze');
var child_process = require('child_process');
// Use commander to parse command line arguments
// https://github.com/tj/commander.js
commander
.option('--dist', 'Build output optimized for distribution', false)
.option('--watch', 'Watch file system', false)
.parse(process.argv);
var defaultOptions = {
srcPath: 'src/js/',
buildPath: 'build/js/',
shouldFactor: false,
forDistribution: commander.dist,
shouldWatch: commander.watch
};
Promise.all([
// Code in code-studio.js and any common code factored out of this bundle
// gets included into every page in dashboard.
// @see application.html.haml
build_commands.bundle(_.extend({}, defaultOptions, {
filenames: [
'code-studio.js',
'levelbuilder.js',
'levelbuilder_markdown.js',
'levelbuilder_studio.js',
'districtDropdown.js',
'levels/contract_match.jsx',
'levels/widget.js',
'levels/external.js',
'levels/multi.js',
'levels/textMatch.js',
'levels/levelGroup.js',
'levels/dialogHelper.js',
'initApp/initApp.js'
],
commonFile: 'code-studio-common',
shouldFactor: true
})),
// Build embedVideo.js in its own step (skipping factor-bundle) so that
// we don't have to include the large code-studio-common file in the
// embedded video page, keeping it fairly lightweight.
// (I wonder how much more we could slim it down by removing jQuery!)
// @see embed.html.haml
build_commands.bundle(_.extend({}, defaultOptions, {
filenames: [
'embedVideo.js'
],
commonFile: 'embedVideo'
})),
// only-react.js is just React in a bundle. In the future, this might be
// expanded to include a small set of libraries that we expect on the global
// namespace
build_commands.bundle(_.extend({}, defaultOptions, {
filenames: [
'react-only.js'
],
commonFile: 'react-only'
})),
// Have a bundle for plc stuff - no sense in expanding this to everything yet
build_commands.bundle(_.extend({}, defaultOptions, {
filenames: [
'plc/evaluation_creation.js',
'plc/perform_evaluation.js',
'plc/task_creation.js'
],
commonFile: 'plc'
})),
// makerlab-only dependencies for app lab
build_commands.bundle(_.extend({}, defaultOptions, {
filenames: [
'makerlab/makerlabDependencies.js'
],
commonFile: 'makerlab'
})),
build_commands.bundle(_.extend({}, defaultOptions, {
filenames: [
'pd/workshop_dashboard/workshop_dashboard.jsx'
],
commonFile: 'pd',
browserifyGlobalShim: {
"react": "React",
"react-dom": "ReactDOM"
}
}))
]).then(function (results) {
var allStepsSucceeded = !results.some(function (result) {
return result instanceof Error;
});
if (allStepsSucceeded) {
build_commands.logBoxedMessage("code-studio js built");
} else {
build_commands.logBoxedMessage('code-studio js build failed', chalk.bold.red.bgBlack);
}
if (commander.watch) {
// Watching for JavaScript file changes is already set up by browserify/watchify on each bundle
console.log("Watching for .js file changes...");
// Use gaze to set a watcher for scss file changes
gaze('src/css/*.scss', function (err, watcher) {
console.log("Watching for .scss file changes...");
/* Uncomment this if you want to debug .scss watching
console.log("cwd: " + process.cwd());
var watched = this.watched();
Object.keys(watched).forEach(function(watchedDir) {
watched[watchedDir].forEach(function(watchedFile) {
console.log('Watching ' + watchedFile + ' for changes.');
});
});
*/
watcher.on('changed', function (filepath) {
console.log(filepath + ' was changed, rebuilding CSS');
child_process.execSync('npm run build-css', {stdio:'inherit'});
});
});
} else if (!allStepsSucceeded) {
// Don't actually call process.exit() on success, or you might truncate one
// of the files produced by factor-bundle! Let the process exit gracefully
// on its own.
process.exit(1);
}
});