/
ruby.js
95 lines (81 loc) · 2.27 KB
/
ruby.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
class RubyRuntime {
constructor(parent, runtime, runtimeDir) {
this.parent = parent;
this.plugin = parent.plugin;
this.default = {
runtime,
runtimeDir,
libraryFolder: 'gems',
packageManager: 'bundle',
packageManagerExtraArgs: '',
dependenciesPath: 'Gemfile',
compatibleRuntimes: [runtime],
compatibleArchitectures: parent.compatibleArchitectures,
copyBeforeInstall: [
'Gemfile.lock'
],
copyAfterInstall: [
{ from: 'ruby', to: 'gems' }
],
packagePatterns: [
'!node_modules/**',
'!package.json',
'!package-lock.json',
'!vendor/**',
'!.bundle'
],
layerOptimization: {
cleanupPatterns: [
"node_modules/**/*.pyc",
"node_modules/**/*.md",
]
}
};
this.commands = {
bundle: `bundle install --gemfile=${this.default.dependenciesPath} --path=./`,
};
}
init() {
const { dependenciesPath } = this.plugin.settings;
const localpackageJson = path.join(
process.cwd(),
dependenciesPath
);
try {
this.localPackage = fs.readFileSync(localpackageJson).toString();
} catch (e) {
this.plugin.log(`Error: Can not find ${localpackageJson}!`);
process.exit(1);
}
}
async isCompatibleVersion(runtime) {
const osVersion = await this.parent.run('ruby --version');
const [runtimeVersion] = runtime.match(/[0-9].[0-9]/);
return {
version: osVersion,
isCompatible: osVersion.startsWith(`ruby ${runtimeVersion}`)
};
}
isDiff(depsA, depsB) {
if (!depsA) {
return true;
}
return depsA !== depsB;
}
async hasDependenciesChanges() {
const remotePackage = await this.plugin.bucketService.downloadDependencesFile();
let isDifferent = true;
if (remotePackage) {
this.plugin.log(`Comparing ${this.default.dependenciesPath} dependencies...`);
isDifferent = await this.isDiff(remotePackage, this.localPackage);
}
return isDifferent;
}
getDependenciesChecksum() {
return crypto.createHash('md5').update(JSON.stringify(this.localPackage)).digest('hex');
}
}
module.exports = RubyRuntime;