mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-12-28 17:13:45 +03:00
Move fingerprinting to utils
This commit is contained in:
parent
d1434b82ea
commit
5dfed6d222
@ -1,13 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
var cp = require('./utils/child-process-wrapper.js');
|
||||
var crypto = require('crypto')
|
||||
var fingerprint = require('./utils/fingerprint')
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
process.chdir(path.dirname(__dirname));
|
||||
|
||||
var homeDir = process.platform == 'win32' ? process.env.USERPROFILE : process.env.HOME;
|
||||
var fingerprintPath = path.resolve(__dirname, '..', '.atom-ci-fingerprint')
|
||||
|
||||
function loadEnvironmentVariables(filePath) {
|
||||
try {
|
||||
@ -44,9 +44,8 @@ function setEnvironmentVariables() {
|
||||
}
|
||||
|
||||
function removeNodeModules() {
|
||||
var fingerprint = generateModuleFingerprint()
|
||||
if (fs.existsSync(fingerprintPath) && fs.readFileSync(fingerprintPath).toString() === fingerprint) {
|
||||
console.log('node_modules matches current fingerprint ' + fingerprint + ' - not removing')
|
||||
if (fingerprint.fingerprintMatches()) {
|
||||
console.log('node_modules matches current fingerprint ' + fingerprint.fingerprint() + ' - not removing')
|
||||
return
|
||||
}
|
||||
|
||||
@ -65,17 +64,6 @@ function removeNodeModules() {
|
||||
}
|
||||
}
|
||||
|
||||
function generateModuleFingerprint () {
|
||||
var packageJson = fs.readFileSync(path.resolve(__dirname, '..', 'package.json'))
|
||||
var body = packageJson.toString() + process.platform
|
||||
return crypto.createHash('sha1').update(body).digest('hex')
|
||||
}
|
||||
|
||||
function fingerprintNodeModules (callback) {
|
||||
fs.writeFileSync(fingerprintPath, generateModuleFingerprint())
|
||||
callback(null, fingerprintPath)
|
||||
}
|
||||
|
||||
function removeTempFolders() {
|
||||
var fsPlus;
|
||||
try {
|
||||
@ -117,8 +105,8 @@ cp.safeExec.bind(global, 'npm install npm --loglevel error', {cwd: path.resolve(
|
||||
var async = require('async');
|
||||
var gruntPath = path.join('build', 'node_modules', '.bin', 'grunt') + (process.platform === 'win32' ? '.cmd' : '');
|
||||
var tasks = [
|
||||
cp.safeExec.bind(global, 'git clean -dff -e node_modules -e .atom-ci-fingerprint'), // If we left them behind in removeNodeModules() they are OK to use
|
||||
cp.safeExec.bind(global, gruntPath + ' ci --gruntfile build/Gruntfile.coffee --stack --no-color'),
|
||||
cp.safeExec.bind(global, 'git clean -dff -e node_modules'), // If we left them behind in removeNodeModules() they are OK to use
|
||||
cp.safeExec.bind(global, gruntPath + ' ci --gruntfile build/Gruntfile.coffee --stack --no-color')
|
||||
]
|
||||
async.series(tasks, function(error) {
|
||||
process.exit(error ? 1 : 0);
|
||||
|
31
script/utils/fingerprint.js
Normal file
31
script/utils/fingerprint.js
Normal file
@ -0,0 +1,31 @@
|
||||
var crypto = require('crypto')
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
|
||||
var fingerprintPath = path.resolve(__dirname, '..', '..', 'node_modules', '.atom-ci-fingerprint')
|
||||
|
||||
module.exports = {
|
||||
fingerprint: function () {
|
||||
var packageJson = fs.readFileSync(path.resolve(__dirname, '..', '..', 'package.json'))
|
||||
var body = packageJson.toString() + process.platform
|
||||
return crypto.createHash('sha1').update(body).digest('hex')
|
||||
},
|
||||
|
||||
writeFingerprint: function () {
|
||||
var fingerprint = this.fingerprint()
|
||||
fs.writeFileSync(fingerprintPath, fingerprint)
|
||||
console.log('Wrote ci fingerprint:', fingerprintPath, fingerprint)
|
||||
}
|
||||
|
||||
readFingerprint: function() {
|
||||
if (fs.existsSync(fingerprintPath)) {
|
||||
return fs.readFileSync(fingerprintPath).toString()
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
fingerprintMatches: function () {
|
||||
return this.readFingerprint() && this.readFingerprint() === this.fingerprint()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user