Skip to content

Commit 3d969ea

Browse files
committed
Add --force to build, and allow specifying particular files to build.
The force flag makes it easier to test. Specifying one particular file improves File Watchers in IDEA WebStorm. On changes, I can transparently transpile a single file, ready for running or launching a test without requiring a full build.
1 parent 194cf60 commit 3d969ea

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

build/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ require('check-dependencies')((result) => {
3131
const Tasks = require('./tasks').default;
3232

3333
if (~process.argv.indexOf('--build')) {
34-
Tasks.build().then(null, handleTaskFailed);
34+
const taskArgs = process.argv.slice(1 + process.argv.indexOf('--build'));
35+
Tasks.build({}, taskArgs).then(null, handleTaskFailed);
3536
} else if (~process.argv.indexOf('--run')) {
3637
const taskArgs = process.argv.slice(1 + process.argv.indexOf('--run'));
3738
Tasks.run(taskArgs).then(null, handleTaskFailed);

build/task-build.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,18 @@ const transpile = (filename, options = {}) => new Promise((resolve, reject) => {
3232
});
3333
});
3434

35-
export async function buildFile(sourceFile, sourceStats) {
35+
export async function buildFile(sourceFile, sourceStats, force = false) {
3636
let targetFile = getTargetPath(sourceFile);
3737

38-
try {
39-
const targetStats = await fs.stat(targetFile);
40-
if (targetStats.mtime > sourceStats.mtime) {
41-
return;
38+
if (!force) {
39+
try {
40+
const targetStats = await fs.stat(targetFile);
41+
if (targetStats.mtime > sourceStats.mtime) {
42+
return;
43+
}
44+
} catch (e) {
45+
// The target may not exist. For whatever reason just go and try to build it
4246
}
43-
} catch (e) {
44-
// The target may not exist. For whatever reason just go and try to build it
4547
}
4648

4749
const extension = path.extname(sourceFile);
@@ -68,10 +70,21 @@ export async function buildFile(sourceFile, sourceStats) {
6870
}
6971
}
7072

71-
async function babelBuild() {
72-
const source = path.resolve(path.join(__dirname, '..', 'app'));
73+
async function babelBuild(args = []) {
74+
const index = args.indexOf('--force');
75+
const force = index > -1;
76+
args.splice(index, 1);
7377

74-
const paths = await fs.walk(source);
78+
let paths;
79+
if (!args.length) {
80+
const source = path.resolve(path.join(__dirname, '..', 'app'));
81+
paths = await fs.walk(source);
82+
} else {
83+
paths = args.map((p) => {
84+
const pathItem = path.resolve(path.join(__dirname, '..', p));
85+
return { path: pathItem, stats: fs.lstatSync(pathItem) };
86+
});
87+
}
7588

7689
// Find all the directories and sort by depth.
7790
const dirs = paths.filter(p => p.stats.isDirectory())
@@ -82,7 +95,7 @@ async function babelBuild() {
8295

8396
// Build all the files
8497
const files = paths.filter(p => p.stats.isFile());
85-
await Promise.all(files.map(p => buildFile(p.path, p.stats)));
98+
await Promise.all(files.map(p => buildFile(p.path, p.stats, force)));
8699
}
87100

88-
export default () => babelBuild();
101+
export default babelBuild;

build/tasks.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ export default {
1717
await require('./task-build-deps').default();
1818
},
1919

20-
async build(config = {}) {
20+
async build(config = {}, args = []) {
2121
await this.config(config);
22-
await require('./task-build').default();
22+
await require('./task-build').default(args);
2323
},
2424

25-
async buildDev() {
25+
async buildDev(args = []) {
2626
await this.config({ development: true });
27-
await require('./task-build').default();
27+
await require('./task-build').default(args);
2828
},
2929

3030
async run(args = []) {

0 commit comments

Comments
 (0)