-
Notifications
You must be signed in to change notification settings - Fork 119
/
builder.js
67 lines (60 loc) · 1.57 KB
/
builder.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
import * as R from 'ramda';
import path from 'path';
import cpp from 'child-process-promise';
import fse from 'fs-extra';
import * as Utils from './utils';
// =============================================================================
//
// Prepare command and build
//
// =============================================================================
export const composeCommand = (
sketchFilePath,
fqbn,
packagesDir,
librariesDir,
buildDir,
builderToolDir
) => {
const builderExecFileName = Utils.isWindows
? 'arduino-builder.exe'
: 'arduino-builder';
const builderExec = path.join(builderToolDir, builderExecFileName);
const builderHardware = path.join(builderToolDir, 'hardware');
const builderTools = path.join(builderToolDir, 'tools');
return [
`"${builderExec}"`,
`-hardware="${builderHardware}"`,
`-hardware="${packagesDir}"`,
`-libraries="${librariesDir}"`,
`-tools="${builderTools}"`,
`-tools="${packagesDir}"`,
`-fqbn="${fqbn}"`,
`-build-path="${buildDir}"`,
`"${sketchFilePath}"`,
].join(' ');
};
// :: Path -> FQBN -> Path -> Path -> Path -> PortName -> Promise { exitCode, stdout, stderr } Error
export const build = R.curry(
(
sketchFilePath,
fqbn,
packagesDir,
librariesDir,
buildDir,
builderToolDir
) => {
const cmd = composeCommand(
sketchFilePath,
fqbn,
packagesDir,
librariesDir,
buildDir,
builderToolDir
);
return fse
.ensureDir(buildDir)
.then(() => cpp.exec(cmd))
.then(Utils.normalizeChildProcessResult);
}
);