-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathconfig.js
155 lines (144 loc) · 3.68 KB
/
config.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
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
148
149
150
151
152
153
154
155
//@ts-check
const fs = require('fs');
const path = require('path');
const semver = require('semver');
const merge = require('deepmerge');
const dateFormat = require('dateformat');
const { isNightly, isRelease, git } = require('./utils');
function artifactName() {
const { platform, arch } = process;
const id = (() => {
if (isRelease) {
return getVersion();
} else if (isNightly) {
return `nightly-${timestamp()}`;
} else {
return getVersion();
}
})();
const name = 'arduino-ide';
switch (platform) {
case 'win32': {
if (arch === 'x64') {
return `${name}_${id}_Windows_64bit.\$\{ext}`;
}
throw new Error(`Unsupported platform, arch: ${platform}, ${arch}`);
}
case 'darwin': {
if (arch === 'arm64') {
return `${name}_${id}_macOS_ARM64.\$\{ext}`;
}
return `${name}_${id}_macOS_64bit.\$\{ext}`;
}
case 'linux': {
switch (arch) {
case 'arm': {
return `${name}_${id}_Linux_ARMv7.\$\{ext}`;
}
case 'arm64': {
return `${name}_${id}_Linux_ARM64.\$\{ext}`;
}
case 'x64': {
return `${name}_${id}_Linux_64bit.\$\{ext}`;
}
default: {
throw new Error(`Unsupported platform, arch: ${platform}, ${arch}`);
}
}
}
default:
throw new Error(`Unsupported platform, arch: ${platform}, ${arch}`);
}
}
function electronPlatform() {
switch (process.platform) {
case 'win32': {
return 'win';
}
case 'darwin': {
return 'mac';
}
case 'linux': {
return 'linux';
}
default:
throw new Error(`Unsupported platform: ${process.platform}.`);
}
}
function getVersion() {
const repositoryRootPath = git('rev-parse --show-toplevel');
let version = JSON.parse(
fs.readFileSync(path.join(repositoryRootPath, 'package.json'), {
encoding: 'utf8',
})
).version;
if (!semver.valid(version)) {
throw new Error(
`Could not read version from root package.json. Version was: '${version}'.`
);
}
if (!isRelease) {
if (isNightly) {
version = `${version}-nightly-${timestamp()}`;
} else {
version = `${version}-snapshot-${currentCommitish()}`;
}
if (!semver.valid(version)) {
throw new Error(`Invalid patched version: '${version}'.`);
}
}
return version;
}
function getChannel() {
if (isRelease) {
return 'stable';
}
if (isNightly) {
return 'nightly';
}
return '';
}
function timestamp() {
return dateFormat(new Date(), 'yyyymmdd');
}
function currentCommitish() {
return git('rev-parse --short HEAD');
}
// function currentBranch() {
// return git('rev-parse --abbrev-ref HEAD');
// }
function generateTemplate(buildDate) {
// do `export PUBLISH=true yarn package` if you want to mimic CI build locally.
// const electronPublish = release || (isCI && currentBranch() === 'main') || process.env.PUBLISH === 'true';
const version = getVersion();
const productName = 'Arduino IDE';
const name = 'arduino-ide';
const updateChannel = getChannel();
let customizations = {
name,
description: productName,
version,
theia: {
frontend: {
config: {
'arduino.ide.updateChannel': updateChannel,
},
},
},
build: {
productName,
appId: 'cc.arduino.IDE2',
[electronPlatform()]: {
artifactName: artifactName(),
},
},
};
if (buildDate) {
customizations = merge(customizations, {
theia: { frontend: { config: { buildDate } } },
});
}
const template = require('../build/template-package.json');
return merge(template, customizations);
}
module.exports = { generateTemplate };