* chore: run lint first for tests
* chore: upgrade dependencies
* chore: use Node 8 syntax
* feat: use async/await syntax
This commit is contained in:
Mark Lee 2019-05-28 21:40:38 -07:00 коммит произвёл GitHub
Родитель 652479536c
Коммит ead1083aa1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 992 добавлений и 820 удалений

Просмотреть файл

@ -28,7 +28,6 @@ steps-test: &steps-test
key: v1-dependencies-{{ arch }}-{{ checksum "yarn.lock" }}
- run: yarn test
version: 2
jobs:
test-linux-8:

Просмотреть файл

@ -1,71 +1,73 @@
var path = require('path')
var spawn = require('child_process').spawn
const path = require('path')
const { spawn } = require('child_process')
var pairSettings = ['version-string']
var singleSettings = ['file-version', 'product-version', 'icon', 'requested-execution-level']
var noPrefixSettings = ['application-manifest']
const pairSettings = ['version-string']
const singleSettings = ['file-version', 'product-version', 'icon', 'requested-execution-level']
const noPrefixSettings = ['application-manifest']
module.exports = function (exe, options, callback) {
var rcedit = path.resolve(__dirname, '..', 'bin', 'rcedit.exe')
var args = [exe]
module.exports = async (exe, options) => {
let rcedit = path.resolve(__dirname, '..', 'bin', 'rcedit.exe')
const args = [exe]
pairSettings.forEach(function (name) {
if (options[name] != null) {
for (var key in options[name]) {
var value = options[name][key]
args.push('--set-' + name)
args.push(key)
args.push(value)
for (const name of pairSettings) {
if (options[name]) {
for (const [key, value] of Object.entries(options[name])) {
args.push(`--set-${name}`, key, value)
}
}
})
}
singleSettings.forEach(function (name) {
if (options[name] != null) {
args.push('--set-' + name)
args.push(options[name])
for (const name of singleSettings) {
if (options[name]) {
args.push(`--set-${name}`, options[name])
}
})
}
noPrefixSettings.forEach(function (name) {
if (options[name] != null) {
args.push('--' + name)
args.push(options[name])
for (const name of noPrefixSettings) {
if (options[name]) {
args.push(`--${name}`, options[name])
}
})
}
var spawnOptions = {}
spawnOptions.env = Object.create(process.env)
const spawnOptions = {
env: { ...process.env }
}
if (process.platform !== 'win32') {
args.unshift(rcedit)
rcedit = 'wine'
// Supress fixme: stderr log messages
// Suppress "fixme:" stderr log messages
spawnOptions.env.WINEDEBUG = '-all'
}
var child = spawn(rcedit, args, spawnOptions)
var stderr = ''
var error = null
return new Promise((resolve, reject) => {
const child = spawn(rcedit, args, spawnOptions)
let stderr = ''
let error = null
child.on('error', function (err) {
if (error == null) error = err
})
child.on('error', err => {
if (error === null) {
error = err
}
})
child.stderr.on('data', function (data) {
stderr += data
})
child.stderr.on('data', data => {
stderr += data
})
child.on('close', function (code) {
if (error != null) {
callback(error)
} else if (code === 0) {
callback()
} else {
var message = 'rcedit.exe failed with exit code ' + code
stderr = stderr.trim()
if (stderr) message += '. ' + stderr
callback(new Error(message))
}
child.on('close', code => {
if (error !== null) {
reject(error)
} else if (code === 0) {
resolve()
} else {
let message = `rcedit.exe failed with exit code ${code}`
stderr = stderr.trim()
if (stderr) {
message += `. ${stderr}`
}
reject(new Error(message))
}
})
})
}

Просмотреть файл

@ -4,7 +4,8 @@
"description": "Node module to edit resources of exe",
"main": "lib/rcedit.js",
"scripts": {
"test": "mocha test/*.js && npm run lint",
"mocha": "mocha test/*.js",
"test": "npm run lint && npm run mocha",
"lint": "standard"
},
"repository": {
@ -15,13 +16,16 @@
"url": "https://github.com/electron/node-rcedit/issues"
},
"license": "MIT",
"engines": {
"node": ">= 8.0.0"
},
"devDependencies": {
"@continuous-auth/semantic-release-npm": "^1.0.3",
"got": "^6.7.1",
"mocha": "^3.0.2",
"got": "^9.6.0",
"mocha": "^6.1.4",
"rcinfo": "^0.1.3",
"semantic-release": "^15.13.3",
"standard": "^7.1.2",
"temp": "^0.8.3"
"standard": "^12.0.1",
"temp": "^0.9.0"
}
}

Просмотреть файл

@ -1,29 +1,43 @@
var assert = require('assert')
var fs = require('fs')
var path = require('path')
var rcedit = require('..')
var rcinfo = require('rcinfo')
var temp = require('temp').track()
/* eslint-env node, mocha */
var beforeEach = global.beforeEach
var describe = global.describe
var it = global.it
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const { promisify } = require('util')
const rcedit = require('..')
const rcinfo = promisify(require('rcinfo'))
const temp = require('temp').track()
describe('rcedit(exePath, options, callback)', function () {
const copyFile = promisify(fs.copyFile)
const readFile = promisify(fs.readFile)
async function assertRceditError (exePath, options, messages) {
try {
await rcedit(exePath, options)
assert.fail('should not succeed')
} catch (error) {
assert.ok(error instanceof Error)
for (const message of messages) {
assert.ok(error.message.includes(message))
}
}
}
describe('async rcedit(exePath, options)', function () {
this.timeout(60000)
var exePath = null
var tempPath = null
let exePath = null
let tempPath = null
beforeEach(function () {
beforeEach(async () => {
tempPath = temp.mkdirSync('node-rcedit-')
exePath = path.join(tempPath, 'electron.exe')
var fixturesExePath = path.join(__dirname, 'fixtures', 'electron.exe')
fs.writeFileSync(exePath, fs.readFileSync(fixturesExePath))
const fixturesExePath = path.join(__dirname, 'fixtures', 'electron.exe')
await copyFile(fixturesExePath, exePath)
})
it('updates the information in the executable', function (done) {
var options = {
it('updates the information in the executable', async () => {
await rcedit(exePath, {
'version-string': {
CompanyName: 'Umbrella',
FileDescription: 'Vanhouten',
@ -33,156 +47,80 @@ describe('rcedit(exePath, options, callback)', function () {
'file-version': '3.4.5.6',
'product-version': '4.5.6.7',
icon: path.join(__dirname, 'fixtures', 'app.ico')
}
rcedit(exePath, options, function (error) {
if (error != null) return done(error)
rcinfo(exePath, function (error, info) {
if (error != null) return done(error)
assert.equal(info.CompanyName, 'Umbrella')
assert.equal(info.FileDescription, 'Vanhouten')
assert.equal(info.LegalCopyright, 'Maritime')
assert.equal(info.ProductName, 'Millhouse')
assert.equal(info.FileVersion, '3.4.5.6')
assert.equal(info.ProductVersion, '4.5.6.7')
done()
})
})
const info = await rcinfo(exePath)
assert.strictEqual(info.CompanyName, 'Umbrella')
assert.strictEqual(info.FileDescription, 'Vanhouten')
assert.strictEqual(info.LegalCopyright, 'Maritime')
assert.strictEqual(info.ProductName, 'Millhouse')
assert.strictEqual(info.FileVersion, '3.4.5.6')
assert.strictEqual(info.ProductVersion, '4.5.6.7')
})
it('supports non-ASCII characters in the .exe path', function (done) {
var unicodePath = path.join(path.dirname(exePath), 'äeiöü.exe')
fs.renameSync(exePath, unicodePath)
it('supports non-ASCII characters in the .exe path', async () => {
const unicodePath = path.join(path.dirname(exePath), 'äeiöü.exe')
await promisify(fs.rename)(exePath, unicodePath)
var options = {
await rcedit(unicodePath, {
'version-string': {
FileDescription: 'foo',
ProductName: 'bar'
},
'file-version': '8.0.8'
}
rcedit(unicodePath, options, function (error) {
if (error != null) return done(error)
done()
})
})
it('supports a product version of 1', function (done) {
var options = {
'product-version': '1'
}
it('supports a product version of 1', async () => {
await rcedit(exePath, { 'product-version': '1' })
rcedit(exePath, options, function (error) {
if (error != null) return done(error)
rcinfo(exePath, function (error, info) {
if (error != null) return done(error)
assert.equal(info.ProductVersion, '1.0.0.0')
done()
})
})
const info = await rcinfo(exePath)
assert.strictEqual(info.ProductVersion, '1.0.0.0')
})
it('supports a product version of 1.0', function (done) {
var options = {
'product-version': '1.0'
}
it('supports a product version of 1.0', async () => {
await rcedit(exePath, { 'product-version': '1.0' })
rcedit(exePath, options, function (error) {
if (error != null) return done(error)
rcinfo(exePath, function (error, info) {
if (error != null) return done(error)
assert.equal(info.ProductVersion, '1.0.0.0')
done()
})
})
const info = await rcinfo(exePath)
assert.strictEqual(info.ProductVersion, '1.0.0.0')
})
it('supports setting requestedExecutionLevel to requireAdministrator', function (done) {
var options = {
'requested-execution-level': 'requireAdministrator'
}
it('supports setting requestedExecutionLevel to requireAdministrator', async () => {
let exeData = await readFile(exePath, 'utf8')
assert.ok(!exeData.includes('requireAdministrator'))
// first read in the file and test that requireAdministrator is not present
var text = fs.readFileSync(exePath, 'utf8')
assert.equal(text.indexOf('requireAdministrator'), -1)
await rcedit(exePath, { 'requested-execution-level': 'requireAdministrator' })
rcedit(exePath, options, function (error) {
if (error != null) return done(error)
// read in the exe as text
text = fs.readFileSync(exePath, 'utf8')
assert.notEqual(text.indexOf('requireAdministrator'), -1)
done()
})
exeData = await readFile(exePath, 'utf8')
assert.ok(exeData.includes('requireAdministrator'))
})
it('supports replacing the manifest with a specified manifest file', function (done) {
var options = {
'application-manifest': path.join(__dirname, 'fixtures', 'electron.manifest')
}
it('supports replacing the manifest with a specified manifest file', async () => {
let exeData = await readFile(exePath, 'utf8')
assert.ok(!exeData.includes('requireAdministrator'))
// first read in the file and test that requireAdministrator is not present
var text = fs.readFileSync(exePath, 'utf8')
assert.equal(text.indexOf('requireAdministrator'), -1)
await rcedit(exePath, { 'application-manifest': path.join(__dirname, 'fixtures', 'electron.manifest') })
rcedit(exePath, options, function (error) {
if (error != null) return done(error)
// read in the exe as text
text = fs.readFileSync(exePath, 'utf8')
assert.notEqual(text.indexOf('requireAdministrator'), -1)
done()
})
exeData = await readFile(exePath, 'utf8')
assert.ok(exeData.includes('requireAdministrator'))
})
it('reports an error when the .exe path does not exist', function (done) {
rcedit(path.join(tempPath, 'does-not-exist.exe'), {'file-version': '3.4.5.6'}, function (error) {
assert.ok(error instanceof Error)
assert.notEqual(error.message.indexOf('rcedit.exe failed with exit code 1.'), -1)
assert.notEqual(error.message.indexOf('Unable to load file'), -1)
done()
})
it('reports an error when the .exe path does not exist', async () => {
assertRceditError(path.join(tempPath, 'does-not-exist.exe'), { 'file-version': '3.4.5.6' }, [
'rcedit.exe failed with exit code 1.',
'Unable to load file'
])
})
it('reports an error when the icon path does not exist', function (done) {
rcedit(exePath, {icon: path.join(tempPath, 'does-not-exist.ico')}, function (error) {
assert.ok(error instanceof Error)
assert.notEqual(error.message.indexOf('Fatal error: Unable to set icon'), -1)
done()
})
it('reports an error when the icon path does not exist', async () => {
assertRceditError(exePath, { icon: path.join(tempPath, 'does-not-exist.ico') }, ['Fatal error: Unable to set icon'])
})
it('reports an error when the file version is invalid', function (done) {
rcedit(exePath, {'file-version': 'foo'}, function (error) {
assert.ok(error instanceof Error)
assert.notEqual(error.message.indexOf('Fatal error: Unable to parse version string for FileVersion'), -1)
done()
})
it('reports an error when the file version is invalid', async () => {
assertRceditError(exePath, { 'file-version': 'foo' }, ['Fatal error: Unable to parse version string for FileVersion'])
})
it('reports an error when the product version is invalid', function (done) {
rcedit(exePath, {'product-version': 'foo'}, function (error) {
assert.ok(error instanceof Error)
assert.notEqual(error.message.indexOf('Fatal error: Unable to parse version string for ProductVersion'), -1)
done()
})
it('reports an error when the product version is invalid', async () => {
assertRceditError(exePath, { 'product-version': 'foo' }, ['Fatal error: Unable to parse version string for ProductVersion'])
})
})

1487
yarn.lock

Разница между файлами не показана из-за своего большого размера Загрузить разницу