This repository has been archived by the owner on May 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.atom-build.js
87 lines (83 loc) · 2.53 KB
/
.atom-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
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
module.exports = {
cmd: 'make',
name: 'make all',
args: [
'all'
],
cwd: '{FILE_ACTIVE_PATH}',
preBuild: function() {
const path = require('path');
const editor = atom.workspace.getActiveTextEditor();
const projectPaths = atom.project.getPaths().map(projectPath => {
try {
return fs.realpathSync(projectPath);
} catch (e) { /* Do nothing. */ }
return null;
});
const replacements = {
PROJECT_PATH: projectPaths[0]
};
if (editor && (undefined !== editor.getPath())) {
replacements.FILE_ACTIVE = fs.realpathSync(editor.getPath());
replacements.FILE_ACTIVE_PATH = path.dirname(replacements.FILE_ACTIVE);
replacements.PROJECT_PATH = projectPaths.find(p => replacements.FILE_ACTIVE_PATH && replacements.FILE_ACTIVE_PATH.startsWith(p));
replacements.FILE_ACTIVE_NAME = path.basename(replacements.FILE_ACTIVE);
replacements.FILE_ACTIVE_NAME_BASE = path.basename(replacements.FILE_ACTIVE, path.extname(replacements.FILE_ACTIVE));
replacements.SELECTION = editor.getSelectedText();
}
if (atom.project.getRepositories[0]) {
replacements.REPO_BRANCH_SHORT = atom.project.getRepositories()[0].getShortHead();
}
let subPath = replacements.FILE_ACTIVE_PATH.replace(replacements.PROJECT_PATH, '');
for (let dir of ['beacon', 'locomotive']) {
if (subPath.startsWith('/firmware/' + dir)) {
this.cwd = replacements.PROJECT_PATH + '/firmware/' + dir;
}
}
},
targets: {
'beacon make': {
cmd: 'make',
args: [
'all',
'ID=0xbcaf'
],
cwd: '{PROJECT_PATH}/firmware/beacon',
preBuild: function() {
let id = parseInt(editor.getSelectedText(), 16);
if (!isNaN(id)) {
this.args[1] = this.args[1].replace('bcaf', id.toString(16).substr(0, 4));
}
}
},
'beacon make program': {
cmd: 'make',
args: [
'program',
'AVRDUDE_PROGRAMMER=avrisp2',
'ID=0xbcaf'
],
cwd: '{PROJECT_PATH}/firmware/beacon',
preBuild: function() {
let id = parseInt(editor.getSelectedText(), 16);
if (!isNaN(id)) {
this.args[2] = this.args[2].replace('bcaf', id.toString(16).substr(0, 4));
}
}
},
'locomotive make': {
'cmd': 'make',
args: [
'all'
],
cwd: '{PROJECT_PATH}/firmware/locomotive'
},
'locomotive make flash': {
'cmd': 'make',
args: [
'flash'
],
cwd: '{PROJECT_PATH}/firmware/locomotive'
}
}
};