chore: desktop workflow

This commit is contained in:
Mo
2022-06-11 20:37:41 -05:00
parent 2aac0294ef
commit 3b70495836
9 changed files with 214 additions and 78 deletions

View File

@@ -0,0 +1,7 @@
export const Command = function (prompt, dir, extraEnv = {}) {
return {
prompt,
dir,
extraEnv,
}
}

View File

@@ -1,13 +1,14 @@
import { spawn } from 'child_process'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import { Command } from './Command'
import { publishSnap } from './publishSnap'
import { runCommand } from './runCommand'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const RootDir = path.join(__dirname, '../../..')
const DesktopDir = path.join(__dirname, '../')
export const DesktopDir = path.join(__dirname, '../')
const ScriptsDir = path.join(__dirname)
async function buildTargets(targets) {
@@ -34,30 +35,6 @@ async function buildTargets(targets) {
}
}
function runCommand(commandObj) {
return new Promise((resolve, reject) => {
const { prompt, extraEnv } = commandObj
console.log(prompt, Object.keys(extraEnv).length > 0 ? extraEnv : '')
const [command, ...args] = prompt.split(' ')
const options = { cwd: commandObj.dir, env: Object.assign({}, process.env, extraEnv) }
const child = spawn(command, args, options)
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
child.on('error', reject)
child.on('close', (code) => {
if (code > 0) {
reject(code)
} else {
resolve(code)
}
})
})
}
const Targets = {
Appimage: 'appimage',
AppimageArm64: 'appimage-arm64',
@@ -102,14 +79,6 @@ const TargetGroups = {
const arm64Env = { npm_config_target_arch: 'arm64' }
const Command = function (prompt, dir, extraEnv = {}) {
return {
prompt,
dir,
extraEnv,
}
}
const CompileGroups = [
{
compileCommand: Command('yarn run webpack --config desktop.webpack.prod.js', DesktopDir),
@@ -192,12 +161,6 @@ const BuildCommands = {
[Targets.Windows]: [Command('yarn run electron-builder --windows --x64 --ia32 --publish=never', DesktopDir)],
}
async function publishSnap() {
const packageJson = await fs.promises.readFile(path.join(DesktopDir, 'package.json'))
const version = JSON.parse(packageJson).version
await runCommand(Command(`snapcraft upload dist/standard-notes-${version}-linux-amd64.snap`, DesktopDir))
}
;(async () => {
try {
const input = process.argv[2]

View File

@@ -0,0 +1,11 @@
import fs from 'fs'
import path from 'path'
import { Command } from './Command'
import { runCommand } from './runCommand'
import { DesktopDir } from './build'
export async function publishSnap() {
const packageJson = await fs.promises.readFile(path.join(DesktopDir, 'package.json'))
const version = JSON.parse(packageJson).version
await runCommand(Command(`snapcraft upload dist/standard-notes-${version}-linux-amd64.snap`, DesktopDir))
}

View File

@@ -0,0 +1,25 @@
import { spawn } from 'child_process'
export function runCommand(commandObj) {
return new Promise((resolve, reject) => {
const { prompt, extraEnv } = commandObj
console.log(prompt, Object.keys(extraEnv).length > 0 ? extraEnv : '')
const [command, ...args] = prompt.split(' ')
const options = { cwd: commandObj.dir, env: Object.assign({}, process.env, extraEnv) }
const child = spawn(command, args, options)
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
child.on('error', reject)
child.on('close', (code) => {
if (code > 0) {
reject(code)
} else {
resolve(code)
}
})
})
}

View File

@@ -23,8 +23,13 @@ function sha256(filePath) {
let hashes = await Promise.all(
files.map(async (fileName) => {
const hash = await sha256(fileName)
return `${hash} ${fileName}`
try {
const hash = await sha256(fileName)
return `${hash} ${fileName}`
} catch (error) {
console.error('Unable to hash file', fileName)
return null
}
}),
)
hashes = hashes.join('\n')