mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-05 08:28:32 +00:00
[ci]: Made various changes for the electron app:
- Support for multiple electron targe per platform. - Removed packager CLI. Changed the logic we calculate the app name. - Fixed various OS-specific tests: stubbed `os`. - Restructured the final ZIP formats for Windows and Linux. - Added packager tests. - Switched from `@grpc/grpc-js` to native `grpc`. - Updated the version from 0.0.5 to 0.0.6. Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
@@ -2,8 +2,11 @@
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const temp = require('temp');
|
||||
const zip = require('7zip-min');
|
||||
const shell = require('shelljs');
|
||||
const depcheck = require('depcheck');
|
||||
const fromFile = require('file-type').fromFile;
|
||||
|
||||
/**
|
||||
* Returns with the version info for the artifact.
|
||||
@@ -67,7 +70,7 @@ function currentCommitish() {
|
||||
*/
|
||||
function collectUnusedDependencies(pathToProject = process.cwd()) {
|
||||
const p = path.isAbsolute(pathToProject) ? pathToProject : path.resolve(process.cwd(), pathToProject);
|
||||
console.log(`⏱️ >>> Collecting unused backend dependencies for ${p}.`);
|
||||
console.log(`⏱️ >>> Collecting unused backend dependencies for ${p}...`);
|
||||
return new Promise(resolve => {
|
||||
depcheck(p, {
|
||||
ignoreDirs: [
|
||||
@@ -97,4 +100,108 @@ function collectUnusedDependencies(pathToProject = process.cwd()) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { versionInfo, collectUnusedDependencies };
|
||||
/**
|
||||
* `pathToZip` is a `path/to/your/app-name.zip`.
|
||||
* If the `pathToZip` archive does not have a root directory with name `app-name`, it creates one, and move the content from the
|
||||
* archive's root to the new root folder. If the archive already has the desired root folder, calling this function is a NOOP.
|
||||
* If `pathToZip` is not a ZIP, rejects. `targetFolderName` is the destination folder not the new archive location.
|
||||
*/
|
||||
function adjustArchiveStructure(pathToZip, targetFolderName, noCleanup) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (!await isZip(pathToZip)) {
|
||||
reject(new Error(`Expected a ZIP file.`));
|
||||
return;
|
||||
}
|
||||
if (!fs.existsSync(targetFolderName)) {
|
||||
reject(new Error(`${targetFolderName} does not exist.`));
|
||||
return;
|
||||
}
|
||||
if (!fs.lstatSync(targetFolderName).isDirectory()) {
|
||||
reject(new Error(`${targetFolderName} is not a directory.`));
|
||||
return;
|
||||
}
|
||||
console.log(`⏱️ >>> Adjusting ZIP structure ${pathToZip}...`);
|
||||
|
||||
const root = basename(pathToZip);
|
||||
const resources = await list(pathToZip);
|
||||
const hasBaseFolder = resources.find(name => name === root);
|
||||
if (hasBaseFolder) {
|
||||
if (resources.filter(name => name.indexOf(path.sep) === -1).length > 1) {
|
||||
console.warn(`${pathToZip} ZIP has the desired root folder ${root}, however the ZIP contains other entries too: ${JSON.stringify(resources)}`);
|
||||
}
|
||||
console.log(`👌 <<< The ZIP already has the desired ${root} folder.`);
|
||||
resolve(pathToZip);
|
||||
return;
|
||||
}
|
||||
|
||||
const track = temp.track();
|
||||
try {
|
||||
const unzipOut = path.join(track.mkdirSync(), root);
|
||||
fs.mkdirSync(unzipOut);
|
||||
await unpack(pathToZip, unzipOut);
|
||||
const adjustedZip = path.join(targetFolderName, path.basename(pathToZip));
|
||||
await pack(unzipOut, adjustedZip);
|
||||
console.log(`👌 <<< Adjusted the ZIP structure. Moved the modified ${basename(pathToZip)} to the ${targetFolderName} folder.`);
|
||||
resolve(adjustedZip);
|
||||
} finally {
|
||||
if (!noCleanup) {
|
||||
track.cleanupSync();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the `basename` of `pathToFile` without the file extension.
|
||||
*/
|
||||
function basename(pathToFile) {
|
||||
const name = path.basename(pathToFile);
|
||||
const ext = path.extname(pathToFile);
|
||||
return name.substr(0, name.length - ext.length);
|
||||
}
|
||||
|
||||
function unpack(what, where) {
|
||||
return new Promise((resolve, reject) => {
|
||||
zip.unpack(what, where, error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function pack(what, where) {
|
||||
return new Promise((resolve, reject) => {
|
||||
zip.pack(what, where, error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function list(what) {
|
||||
return new Promise((resolve, reject) => {
|
||||
zip.list(what, (error, result) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
resolve(result.map(({ name }) => name));
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
async function isZip(pathToFile) {
|
||||
if (!fs.existsSync(pathToFile)) {
|
||||
throw new Error(`${pathToFile} does not exist`);
|
||||
}
|
||||
const type = await fromFile(pathToFile);
|
||||
return type && type.ext === 'zip';
|
||||
}
|
||||
|
||||
module.exports = { versionInfo, collectUnusedDependencies, adjustArchiveStructure, isZip, unpack };
|
||||
|
||||
Reference in New Issue
Block a user