|
1 | 1 | // @ts-check |
2 | 2 |
|
3 | 3 | (async () => { |
4 | | - const fs = require('fs'); |
5 | | - const path = require('path'); |
6 | | - const temp = require('temp'); |
| 4 | + const path = require('node:path'); |
7 | 5 | const shell = require('shelljs'); |
8 | 6 | const semver = require('semver'); |
9 | 7 | const downloader = require('./downloader'); |
| 8 | + const { taskBuildFromGit } = require('./utils'); |
10 | 9 |
|
11 | 10 | const version = (() => { |
12 | 11 | const pkg = require(path.join(__dirname, '..', 'package.json')); |
|
86 | 85 | shell.exit(1); |
87 | 86 | } |
88 | 87 | } else { |
89 | | - // We assume an object with `owner`, `repo`, commitish?` properties. |
90 | | - const { owner, repo, commitish } = version; |
91 | | - if (!owner) { |
92 | | - shell.echo(`Could not retrieve 'owner' from ${JSON.stringify(version)}`); |
93 | | - shell.exit(1); |
94 | | - } |
95 | | - if (!repo) { |
96 | | - shell.echo(`Could not retrieve 'repo' from ${JSON.stringify(version)}`); |
97 | | - shell.exit(1); |
98 | | - } |
99 | | - const url = `https://github.com/${owner}/${repo}.git`; |
100 | | - shell.echo( |
101 | | - `Building Firmware Uploader from ${url}. Commitish: ${ |
102 | | - commitish ? commitish : 'HEAD' |
103 | | - }` |
104 | | - ); |
105 | | - |
106 | | - if (fs.existsSync(destinationPath)) { |
107 | | - shell.echo( |
108 | | - `Skipping the Firmware Uploader build because it already exists: ${destinationPath}` |
109 | | - ); |
110 | | - return; |
111 | | - } |
112 | | - |
113 | | - if (shell.mkdir('-p', buildFolder).code !== 0) { |
114 | | - shell.echo('Could not create build folder.'); |
115 | | - shell.exit(1); |
116 | | - } |
117 | | - |
118 | | - const tempRepoPath = temp.mkdirSync(); |
119 | | - shell.echo(`>>> Cloning Firmware Uploader source to ${tempRepoPath}...`); |
120 | | - if (shell.exec(`git clone ${url} ${tempRepoPath}`).code !== 0) { |
121 | | - shell.exit(1); |
122 | | - } |
123 | | - shell.echo('<<< Cloned Firmware Uploader repo.'); |
124 | | - |
125 | | - if (commitish) { |
126 | | - shell.echo(`>>> Checking out ${commitish}...`); |
127 | | - if ( |
128 | | - shell.exec(`git -C ${tempRepoPath} checkout ${commitish}`).code !== 0 |
129 | | - ) { |
130 | | - shell.exit(1); |
131 | | - } |
132 | | - shell.echo(`<<< Checked out ${commitish}.`); |
133 | | - } |
134 | | - |
135 | | - shell.echo(`>>> Building the Firmware Uploader...`); |
136 | | - if (shell.exec('go build', { cwd: tempRepoPath }).code !== 0) { |
137 | | - shell.exit(1); |
138 | | - } |
139 | | - shell.echo('<<< Firmware Uploader build done.'); |
140 | | - |
141 | | - if (!fs.existsSync(path.join(tempRepoPath, fwuploderName))) { |
142 | | - shell.echo( |
143 | | - `Could not find the Firmware Uploader at ${path.join( |
144 | | - tempRepoPath, |
145 | | - fwuploderName |
146 | | - )}.` |
147 | | - ); |
148 | | - shell.exit(1); |
149 | | - } |
150 | | - |
151 | | - const builtFwUploaderPath = path.join(tempRepoPath, fwuploderName); |
152 | | - shell.echo( |
153 | | - `>>> Copying Firmware Uploader from ${builtFwUploaderPath} to ${destinationPath}...` |
154 | | - ); |
155 | | - if (shell.cp(builtFwUploaderPath, destinationPath).code !== 0) { |
156 | | - shell.exit(1); |
157 | | - } |
158 | | - shell.echo(`<<< Copied the Firmware Uploader.`); |
159 | | - |
160 | | - shell.echo('<<< Verifying Firmware Uploader...'); |
161 | | - if (!fs.existsSync(destinationPath)) { |
162 | | - shell.exit(1); |
163 | | - } |
164 | | - shell.echo('>>> Verified Firmware Uploader.'); |
| 88 | + taskBuildFromGit(version, destinationPath, 'Firmware Uploader'); |
165 | 89 | } |
166 | 90 | })(); |
0 commit comments