From 5205ed109449972d5fd1013d84f9cecce2277b81 Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Mon, 4 Mar 2019 20:15:27 +0100 Subject: [PATCH] Add snap after-package repack script --- package.json | 3 ++- scripts/afterPack.ts | 22 ++++++++++++++++++++++ scripts/prepare-release.ts | 31 +------------------------------ scripts/util.ts | 29 +++++++++++++++++++++++++++++ tsconfig.json | 2 +- 5 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 scripts/afterPack.ts create mode 100644 scripts/util.ts diff --git a/package.json b/package.json index 2c2e24d..2b06c3c 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "app": "./", "buildResources": "res", "output": "build" - } + }, + "afterAllArtifactBuild": "./dist/scripts/afterPack.js" }, "author": "Thomas Nordquist", "email": "xxnerowingerxx@gmail.com", diff --git a/scripts/afterPack.ts b/scripts/afterPack.ts new file mode 100644 index 0000000..a8ff7dd --- /dev/null +++ b/scripts/afterPack.ts @@ -0,0 +1,22 @@ +import * as fs from 'fs-extra' +import * as path from 'path' +import { chdir } from 'process' +import { exec } from './util' + +export default async function (info: any) { + for (const snapFile of info.artifactPaths) { + if (/\.snap$/.test(snapFile)) { + const originalDir = __dirname + const dirname = path.dirname(snapFile) + chdir(dirname) + + await exec('sudo', ['unsquashfs', snapFile]) + await fs.remove(snapFile) + await exec('sudo', ['chmod', '-R', 'g-s', 'squashfs-root']) + await exec('sudo', ['snapcraft', 'pack', 'squashfs-root', '--output', snapFile]) + await fs.remove('squashfs-root') + + chdir(originalDir) + } + } +} diff --git a/scripts/prepare-release.ts b/scripts/prepare-release.ts index 872371b..25e762b 100644 --- a/scripts/prepare-release.ts +++ b/scripts/prepare-release.ts @@ -1,36 +1,7 @@ import * as fs from 'fs-extra' import * as path from 'path' -import { spawn, ChildProcess } from 'child_process' import { chdir } from 'process' - -async function exec(cmd: string, args: string[] = []) { - const child = spawn(cmd, args, { shell: true }) - redirectOutputFor(child) - await waitFor(child) -} - -function redirectOutputFor(child: ChildProcess) { - const printStdout = (data: Buffer) => { - process.stdout.write(data.toString()) - } - const printStderr = (data: Buffer) => { - process.stderr.write(data.toString()) - } - child.stdout.on('data', printStdout) - child.stderr.on('data', printStderr) - - child.once('close', () => { - child.stdout.off('data', printStdout) - child.stderr.off('data', printStderr) - }) -} - -async function waitFor(child: ChildProcess) { - - return new Promise((resolve) => { - child.once('close', () => resolve()) - }) -} +import { exec } from './util'; const targetDir = path.join('build', 'clean') async function prepareRelease() { diff --git a/scripts/util.ts b/scripts/util.ts new file mode 100644 index 0000000..ca1d531 --- /dev/null +++ b/scripts/util.ts @@ -0,0 +1,29 @@ +import { spawn, ChildProcess } from 'child_process' + +export async function exec(cmd: string, args: string[] = []) { + const child = spawn(cmd, args, { shell: true }) + redirectOutputFor(child) + await waitFor(child) +} + +function redirectOutputFor(child: ChildProcess) { + const printStdout = (data: Buffer) => { + process.stdout.write(data.toString()) + } + const printStderr = (data: Buffer) => { + process.stderr.write(data.toString()) + } + child.stdout.on('data', printStdout) + child.stderr.on('data', printStderr) + + child.once('close', () => { + child.stdout.off('data', printStdout) + child.stderr.off('data', printStderr) + }) +} + +async function waitFor(child: ChildProcess) { + return new Promise((resolve) => { + child.once('close', () => resolve()) + }) +} diff --git a/tsconfig.json b/tsconfig.json index 5b9d0a1..fb40d4f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,5 +11,5 @@ "lib": ["es2017", "dom"], "sourceMap": true }, - "include": ["src/electron.ts", "src/spec/electron.ts", "src/spec/webdriverio.ts"] + "include": ["src/electron.ts", "src/spec/electron.ts", "src/spec/webdriverio.ts", "scripts/*.ts"] }