Skip to content
代码片段 群组 项目
提交 d510054b 编辑于 作者: Timotej Ecimovic's avatar Timotej Ecimovic
浏览文件

Deduplicate some scripts.

上级 dcbd112f
No related branches found
No related tags found
无相关合并请求
/**
*
* Copyright (c) 2020 Silicon Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const { spawn } = require('child_process')
// Utilities shared by scripts.
function executeCmd(ctx, cmd, args) {
return new Promise((resolve, reject) => {
console.log(`🚀 Executing: ${cmd} ${args.join(' ')}`)
var c = spawn(cmd, args)
c.on('exit', (code) => {
if (code == 0) resolve(ctx)
else {
console.log(`👎 Program ${cmd} exited with error code: ${code}`)
reject()
}
})
c.stdout.on('data', (data) => {
process.stdout.write(data)
})
c.stderr.on('data', (data) => {
process.stderr.write('' + data)
})
})
}
exports.executeCmd = executeCmd
......@@ -19,27 +19,7 @@
const { spawn } = require('child_process')
const yargs = require('yargs')
const fs = require('fs')
function executeCmd(ctx, cmd, args) {
return new Promise((resolve, reject) => {
console.log(`🚀 Executing: ${cmd}`)
var c = spawn(cmd, args)
c.on('exit', (code) => {
if (code == 0) {
resolve(ctx)
} else {
console.log(`👎 Program ${cmd} exited with error code: ${code}`)
reject(code)
}
})
c.stdout.on('data', (data) => {
process.stdout.write(data)
})
c.stderr.on('data', (data) => {
process.stderr.write('' + data)
})
})
}
const scriptUtil = require('./script-util.js')
var arg = yargs
.option('zclProperties', {
......@@ -96,7 +76,8 @@ if (arg.in != null) {
cli.push(arg.in)
}
executeCmd(ctx, 'electron', cli)
scriptUtil
.executeCmd(ctx, 'electron', cli)
.then(() => {
console.log('😎 All done.')
process.exit(0)
......
......@@ -15,35 +15,15 @@
* limitations under the License.
*/
const { spawn } = require('child_process')
const { hashElement } = require('folder-hash')
const hashOptions = {}
const spaDir = 'dist/spa'
const fs = require('fs')
const path = require('path')
const scriptUtil = require('./script-util.js')
console.log(`node version: ${process.version}`)
function executeCmd(ctx, cmd, args) {
return new Promise((resolve, reject) => {
console.log(`🚀 Executing: ${cmd} ${args}`)
var c = spawn(cmd, args)
c.on('exit', (code) => {
if (code == 0) resolve(ctx)
else {
console.log(`👎 Program ${cmd} exited with error code: ${code}`)
reject()
}
})
c.stdout.on('data', (data) => {
process.stdout.write('' + data)
})
c.stderr.on('data', (data) => {
process.stderr.write('' + data)
})
})
}
var fileName = path.join(spaDir, 'hash.json')
hashElement('src', hashOptions)
......@@ -78,7 +58,7 @@ hashElement('src', hashOptions)
})
)
.then((ctx) => {
if (ctx.needsRebuild) return executeCmd(ctx, 'quasar', ['build'])
if (ctx.needsRebuild) return scriptUtil.executeCmd(ctx, 'quasar', ['build'])
else return Promise.resolve(ctx)
})
.then(
......@@ -98,7 +78,7 @@ hashElement('src', hashOptions)
.then((ctx) => {
var cmdArgs = ['src-electron/main-process/electron-main.dev.js']
cmdArgs.push(...process.argv.slice(2))
return executeCmd(ctx, 'electron', cmdArgs)
return scriptUtil.executeCmd(ctx, 'electron', cmdArgs)
})
.then(() => {
console.log('😎 All done.')
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册