2018-09-16 20:24:07 +03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2018-09-13 18:30:12 +03:00
|
|
|
const cp = require('child_process')
|
|
|
|
const crypto = require('crypto')
|
|
|
|
const fs = require('fs')
|
|
|
|
const { hashElement } = require('folder-hash')
|
|
|
|
const path = require('path')
|
|
|
|
|
2018-09-13 19:57:39 +03:00
|
|
|
const utils = require('./lib/utils')
|
|
|
|
|
2018-09-13 18:30:12 +03:00
|
|
|
const BASE = path.resolve(__dirname, '../..')
|
|
|
|
const NPM_CMD = process.platform === 'win32' ? 'npm.cmd' : 'npm'
|
|
|
|
|
|
|
|
const specHashPath = path.resolve(__dirname, '../spec/.hash')
|
|
|
|
|
|
|
|
const [lastSpecHash, lastSpecInstallHash] = fs.existsSync(specHashPath)
|
|
|
|
? fs.readFileSync(specHashPath, 'utf8').split('\n')
|
|
|
|
: ['invalid', 'invalid']
|
|
|
|
|
|
|
|
getSpecHash().then(([currentSpecHash, currentSpecInstallHash]) => {
|
|
|
|
const specChanged = currentSpecHash !== lastSpecHash
|
|
|
|
const installChanged = lastSpecInstallHash !== currentSpecInstallHash
|
|
|
|
if (specChanged || installChanged) {
|
|
|
|
const out = cp.spawnSync(NPM_CMD, ['install'], {
|
|
|
|
env: Object.assign({}, process.env, {
|
2018-09-13 19:57:39 +03:00
|
|
|
npm_config_nodedir: path.resolve(BASE, `out/${utils.OUT_DIR}/gen/node_headers`),
|
2018-09-13 18:30:12 +03:00
|
|
|
npm_config_msvs_version: '2017'
|
|
|
|
}),
|
2018-09-20 23:43:33 +03:00
|
|
|
cwd: path.resolve(__dirname, '../spec'),
|
|
|
|
stdio: 'inherit'
|
2018-09-13 18:30:12 +03:00
|
|
|
})
|
|
|
|
if (out.status !== 0) {
|
|
|
|
console.error('Failed to npm install in the spec folder')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
return getSpecHash()
|
|
|
|
.then(([newSpecHash, newSpecInstallHash]) => {
|
|
|
|
fs.writeFileSync(specHashPath, `${newSpecHash}\n${newSpecInstallHash}`)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}).then(() => {
|
2018-09-13 19:57:39 +03:00
|
|
|
let exe = path.resolve(BASE, utils.getElectronExec())
|
2018-09-13 18:30:12 +03:00
|
|
|
const args = process.argv.slice(2)
|
|
|
|
if (process.platform === 'linux') {
|
2018-09-16 20:24:07 +03:00
|
|
|
args.unshift(path.resolve(__dirname, 'dbus_mock.py'), exe)
|
2018-09-13 18:30:12 +03:00
|
|
|
exe = 'python'
|
|
|
|
}
|
|
|
|
const child = cp.spawn(exe, args, {
|
|
|
|
cwd: path.resolve(__dirname, '../..'),
|
|
|
|
stdio: 'inherit'
|
|
|
|
})
|
|
|
|
child.on('exit', (code) => {
|
|
|
|
process.exit(code)
|
|
|
|
})
|
2018-10-01 17:00:04 +03:00
|
|
|
}).catch((error) => {
|
|
|
|
console.error('An error occurred inside the spec runner', error)
|
|
|
|
process.exit(1)
|
2018-09-13 18:30:12 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
function getSpecHash () {
|
|
|
|
return Promise.all([
|
|
|
|
new Promise((resolve) => {
|
|
|
|
const hasher = crypto.createHash('SHA256')
|
|
|
|
hasher.update(fs.readFileSync(path.resolve(__dirname, '../spec/package.json')))
|
|
|
|
hasher.update(fs.readFileSync(path.resolve(__dirname, '../spec/package-lock.json')))
|
|
|
|
resolve(hasher.digest('hex'))
|
|
|
|
}),
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
const specNodeModulesPath = path.resolve(__dirname, '../spec/node_modules')
|
|
|
|
if (!fs.existsSync(specNodeModulesPath)) {
|
|
|
|
return resolve('invalid')
|
|
|
|
}
|
2018-10-01 17:00:04 +03:00
|
|
|
hashElement(specNodeModulesPath, {
|
|
|
|
folders: {
|
|
|
|
exclude: ['.bin']
|
|
|
|
}
|
|
|
|
}).then((result) => resolve(result.hash)).catch(reject)
|
2018-09-13 18:30:12 +03:00
|
|
|
})
|
|
|
|
])
|
|
|
|
}
|