-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZAPP-1183 added clean script to build release packages #1444
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#!/usr/bin/env node | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for my own recollection. Forgot what this was. Why do we do this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #!/usr/bin/env node is an instance of a shebang line: the very first line in an executable plain-text file on Unix-like platforms that tells the system what interpreter to pass that file to for execution, via the command line following the magic #! prefix (called shebang). From stack overflow^ |
||
/** | ||
* | ||
* Copyright (c) 2023 Silicon Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const scriptUtil = require('./script-util.js') | ||
const os = require('os') | ||
const path = require('path') | ||
const fs = require('fs') | ||
const yargs = require('yargs/yargs') | ||
const { hideBin } = require('yargs/helpers') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does hideBin do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It just helper that simplifies command line parsing |
||
|
||
/** | ||
* | ||
* @param {*} osName | ||
* @param {*} outputPath | ||
*/ | ||
async function buildForOS(osName, outputPath) { | ||
switch (osName) { | ||
case 'm': | ||
console.log(`Building for Mac... Output: ${outputPath}`) | ||
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:mac']) // Building electron app | ||
await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:mac']) // Building zap-cli | ||
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:cli:mac']) // Adding zap-cli to zip file | ||
if (outputPath) { | ||
await scriptUtil.executeCmd({}, 'mv', [ | ||
'./dist/zap-mac-x64.zip', | ||
path.join(outputPath, 'zap-mac-x64.zip') | ||
]) | ||
await scriptUtil.executeCmd({}, 'mv', [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we comment this one out because it does not even work? |
||
'./dist/zap-mac-arm64.zip', | ||
path.join(outputPath, 'zap-mac-arm64.zip') | ||
]) | ||
} | ||
break | ||
|
||
case 'w': | ||
console.log(`Building for Windows... Output: ${outputPath}`) | ||
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:win']) // Building electron app | ||
await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:win']) // Building zap-cli | ||
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:cli:win']) // Adding zap-cli to zip file | ||
if (outputPath) { | ||
await scriptUtil.executeCmd({}, 'mv', [ | ||
'dist/zap-win-x64.zip', | ||
path.join(outputPath, 'zap-win-x64.zip') | ||
]) | ||
await scriptUtil.executeCmd({}, 'mv', [ | ||
'dist/zap-win-arm64.zip', | ||
path.join(outputPath, 'zap-win-arm64.zip') | ||
]) | ||
} | ||
break | ||
|
||
case 'l': | ||
console.log(`Building for Linux... Output: ${outputPath}`) | ||
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:linux']) // Building electron app | ||
await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:linux']) // Building zap-cli | ||
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:cli:linux']) // Adding zap-cli to zip file | ||
if (outputPath) { | ||
await scriptUtil.executeCmd({}, 'mv', [ | ||
'dist/zap-linux-x64.zip', | ||
path.join(outputPath, 'zap-linux-x64.zip') | ||
]) | ||
await scriptUtil.executeCmd({}, 'mv', [ | ||
'dist/zap-linux-arm64.zip', | ||
path.join(outputPath, 'zap-linux-arm64.zip') | ||
]) | ||
await scriptUtil.executeCmd({}, 'mv', [ | ||
'dist/zap-linux-amd64.deb', | ||
path.join(outputPath, 'zap-linux-amd64.deb') | ||
]) | ||
await scriptUtil.executeCmd({}, 'mv', [ | ||
'dist/zap-linux-x64_64.rpm', | ||
path.join(outputPath, 'zap-linux-x64_64.rpm') | ||
]) | ||
} | ||
break | ||
|
||
default: | ||
console.error(`Error: Unsupported platform: ${osName}`) | ||
process.exit(1) | ||
} | ||
} | ||
|
||
const argv = yargs(hideBin(process.argv)) | ||
.option('platform', { | ||
alias: 'p', | ||
type: 'string', | ||
description: 'Specify the platform(s) to build for (m, w, l)' | ||
}) | ||
.option('output', { | ||
alias: 'o', | ||
type: 'string', | ||
description: 'Specify the output directory for the build files' | ||
}) | ||
.help() | ||
.strict().argv | ||
|
||
let targets = argv.platform | ||
let outputPath = argv.output | ||
|
||
if (outputPath && !fs.existsSync(outputPath)) { | ||
fs.mkdirSync(outputPath, { recursive: true }) | ||
console.log(`Created output directory: ${outputPath}`) | ||
} | ||
|
||
if (!targets) { | ||
const currentPlatform = os.platform() | ||
switch (currentPlatform) { | ||
case 'darwin': | ||
targets = 'm' // Mac | ||
break | ||
case 'win32': | ||
targets = 'w' // Windows | ||
break | ||
case 'linux': | ||
targets = 'l' // Linux | ||
break | ||
default: | ||
console.error(`Error: Unsupported platform: ${currentPlatform}`) | ||
process.exit(1) | ||
} | ||
console.log(`No target specified. Defaulting to current system: ${targets}`) | ||
} | ||
|
||
const targetPlatforms = targets.split('') | ||
|
||
targetPlatforms.forEach(async (target) => { | ||
await buildForOS(target, outputPath) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which version of node gets pulled in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is set by the workflow script in the setup phase.