mirror of
https://github.com/Kong/insomnia.git
synced 2026-05-18 21:55:38 -04:00
improve tar structure and package from script
This commit is contained in:
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -40,7 +40,9 @@ jobs:
|
||||
run: npm run inso-package
|
||||
- name: Tar Inso CLI binaries
|
||||
if: success()
|
||||
run: tar -zcvf ${{ matrix.os }}-inso-${{ github.run_number }}.tar packages/insomnia-inso/binaries
|
||||
run:
|
||||
cd packages/insomnia-inso/binaries
|
||||
tar -zcvf ${{ matrix.os }}-inso-${{ github.run_number }}.tar .
|
||||
- name: Upload Inso CLI tar
|
||||
uses: actions/upload-artifact@v2
|
||||
if: success()
|
||||
|
||||
@@ -23,23 +23,20 @@
|
||||
"lint": "eslint . --ext .js,.ts,.tsx",
|
||||
"lint:fix": "npm run lint -- --fix",
|
||||
"clean": "tsc --build tsconfig.build.json --clean",
|
||||
"postclean": "rimraf dist",
|
||||
"postclean": "rimraf dist && rimraf binaries",
|
||||
"test": "jest --runInBand",
|
||||
"test:watch": "npm run test -- --watch",
|
||||
"test:snapshots": "npm run build && npm run test -- -u",
|
||||
"prebuild": "npm run clean",
|
||||
"build": "webpack --config webpack/webpack.config.development.js",
|
||||
"prebuild:production": "npm run clean",
|
||||
"build:production": "webpack --config webpack/webpack.config.production.js --display errors-only",
|
||||
"start": "npm run build -- --watch",
|
||||
"prepare": "npm run build:production",
|
||||
"package": "rimraf binaries && npm run build:production && pkg .",
|
||||
"package:verify": "ts-node src/scripts/verify-pkg.ts"
|
||||
},
|
||||
"pkg": {
|
||||
"targets": [
|
||||
"node12-x64"
|
||||
],
|
||||
"outputPath": "binaries"
|
||||
"prepackage": "npm run build:production",
|
||||
"package": "ts-node src/scripts/pkg.ts",
|
||||
"pkg": "pkg .",
|
||||
"postpackage": "ts-node src/scripts/verify-pkg.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.9.0",
|
||||
|
||||
74
packages/insomnia-inso/src/scripts/pkg.ts
Normal file
74
packages/insomnia-inso/src/scripts/pkg.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { spawn } from 'child_process';
|
||||
import path from 'path';
|
||||
|
||||
const prefixPkgInso = (msg: string) => `[pkg-inso] ${msg}`;
|
||||
|
||||
const getPlatform = () => process.platform;
|
||||
const isMac = () => getPlatform() === 'darwin';
|
||||
const isLinux = () => getPlatform() === 'linux';
|
||||
const isWindows = () => getPlatform() === 'win32';
|
||||
|
||||
const getTargets = () => {
|
||||
if (isMac()) {
|
||||
return ['node12-macos-x64'];
|
||||
} else if (isLinux()) {
|
||||
return ['node12-linux-x64'];
|
||||
} else if (isWindows()) {
|
||||
return ['node12-win-x64'];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const pkg = async () => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const targets = getTargets();
|
||||
|
||||
if (targets.length === 0) {
|
||||
reject(new Error(prefixPkgInso(`Unsupported OS ${getPlatform()}`)));
|
||||
}
|
||||
|
||||
const rootDir = path.join(__dirname, '../..');
|
||||
|
||||
const process = spawn('npm',
|
||||
[
|
||||
'run',
|
||||
'pkg',
|
||||
'--',
|
||||
'--targets',
|
||||
targets.join(','),
|
||||
'--output',
|
||||
'binaries/inso',
|
||||
], {
|
||||
cwd: rootDir,
|
||||
shell: true,
|
||||
});
|
||||
|
||||
process.stdout.on('data', data => {
|
||||
console.log(data.toString());
|
||||
});
|
||||
|
||||
process.stderr.on('data', data => {
|
||||
console.log(data.toString());
|
||||
});
|
||||
|
||||
process.on('exit', code => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
} else {
|
||||
console.log(prefixPkgInso(`exited with code ${code}`));
|
||||
reject(new Error(prefixPkgInso('failed to package')));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
pkg()
|
||||
.then(() => {
|
||||
process.exit(0);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,54 +1,22 @@
|
||||
import { promises } from 'fs';
|
||||
import { basename, join, resolve } from 'path';
|
||||
import { difference, map } from 'ramda';
|
||||
import { join, resolve } from 'path';
|
||||
|
||||
const prefixPkgVerify = (msg: string) => `[pkg-inso-verify] ${msg}`;
|
||||
|
||||
const { readdir, stat } = promises;
|
||||
|
||||
const fail = (message: string) => {
|
||||
throw new Error(`[inso-pkg]: ${message}`);
|
||||
};
|
||||
|
||||
const verifyFile = (basePath: string) => async (fileName: string) => {
|
||||
const filePath = join(basePath, fileName);
|
||||
try {
|
||||
const stats = await stat(filePath);
|
||||
if (!stats) {
|
||||
fail(`failed to find file ${filePath}`);
|
||||
throw new Error(prefixPkgVerify(`failed to find file ${filePath}`));
|
||||
}
|
||||
if (stats.size === 0) {
|
||||
fail(`the file ${filePath} is unexpectedly empty`);
|
||||
throw new Error(prefixPkgVerify(`the file ${filePath} is unexpectedly empty`));
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
fail(error.message);
|
||||
}
|
||||
fail(`unexpected error: ${error}`);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/** this list of binary artifiacts that we intended to create */
|
||||
const desiredNames = [
|
||||
'insomnia-inso-alpine', // needed for CI use-cases
|
||||
'insomnia-inso-linux',
|
||||
'insomnia-inso-win.exe',
|
||||
'insomnia-inso-macos', // OSX binary (not M1-specific)
|
||||
// 'insomnia-inso-macos-arm64', // would be nice to have Apple M1 support here (`node12-mac-arm64`). see: https://github.com/vercel/pkg/issues/1023
|
||||
];
|
||||
|
||||
const verifyAllFilesArePresent = (filePaths: string[]) => {
|
||||
const actualNames = map(basename, filePaths);
|
||||
|
||||
const missingFiles = difference(desiredNames, actualNames);
|
||||
if (missingFiles.length > 0) {
|
||||
const singular = missingFiles.length === 1;
|
||||
fail(`missing ${singular ? 'a binary' : 'binaries'} for the expected file${singular ? '' : 's'}: ${missingFiles.join(', ')}`);
|
||||
}
|
||||
|
||||
const extraFiles = difference(actualNames, desiredNames);
|
||||
if (extraFiles.length === 1) {
|
||||
const singular = extraFiles.length === 1;
|
||||
fail(`${singular ? 'an ' : ''}extra (and unexpected) ${singular ? 'binary was' : 'binaries were'} found: ${extraFiles.join(', ')}`);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -57,11 +25,9 @@ const verifyPkg = async () => {
|
||||
|
||||
const files = await readdir(basePath);
|
||||
if (files.length === 0) {
|
||||
fail('executable files found');
|
||||
throw new Error(prefixPkgVerify('no executable binaries found'));
|
||||
}
|
||||
|
||||
verifyAllFilesArePresent(files);
|
||||
|
||||
return Promise.all(files.map(verifyFile(basePath)));
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user