Add snap after-package repack script

This commit is contained in:
Thomas Nordquist
2019-03-04 20:15:27 +01:00
parent 7961a7dd3f
commit 5205ed1094
5 changed files with 55 additions and 32 deletions

View File

@@ -43,7 +43,8 @@
"app": "./",
"buildResources": "res",
"output": "build"
}
},
"afterAllArtifactBuild": "./dist/scripts/afterPack.js"
},
"author": "Thomas Nordquist",
"email": "xxnerowingerxx@gmail.com",

22
scripts/afterPack.ts Normal file
View File

@@ -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)
}
}
}

View File

@@ -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() {

29
scripts/util.ts Normal file
View File

@@ -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())
})
}

View File

@@ -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"]
}