-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
104 lines (83 loc) · 2.81 KB
/
index.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
96
97
98
99
100
101
102
103
104
/* eslint-env node */
'use strict';
const fs = require('fs');
const path = require('path');
const archiver = require('archiver');
const BasePlugin = require('ember-cli-deploy-plugin');
const rimraf = require('rimraf');
const RSVP = require('rsvp');
module.exports = {
name: 'ember-cli-deploy-fastboot-app-server',
createDeployPlugin: function(options) {
let DeployPlugin = BasePlugin.extend({
name: options.name,
defaultConfig: {
fastbootArchivePrefix: 'dist-',
distDir: function(context) {
return context.distDir;
},
fastbootDistDir: 'tmp/fastboot-deploy',
revisionKey: function(context) {
let revisionKey = context.revisionData && context.revisionData.revisionKey;
return context.commandOptions.revision || revisionKey;
},
fastbootDownloaderManifestContent: function() {
return function(bucket, key) {
return `
{
"bucket": "${bucket}",
"key": "${key}"
}
`;
};
}
},
setup: function() {
let fastbootArchivePrefix = this.readConfig('fastbootArchivePrefix');
let fastbootDownloaderManifestContent = this.readConfig('fastbootDownloaderManifestContent');
return { fastbootDownloaderManifestContent, fastbootArchivePrefix };
},
willBuild: function() {
let fastbootDistDir = this.readConfig('fastbootDistDir');
rimraf.sync(fastbootDistDir);
return RSVP.resolve();
},
didPrepare: function(context) {
let distDir = this.readConfig('distDir');
let revisionKey = this.readConfig('revisionKey');
let fastbootDistDir = this.readConfig('fastbootDistDir');
let ignoreFiles = this.readConfig('ignoreFiles');
let fastbootArchivePrefix = context.fastbootArchivePrefix;
if (!fs.existsSync(fastbootDistDir)) {
fs.mkdirSync(fastbootDistDir);
}
let archiveName = fastbootArchivePrefix+revisionKey+'.zip';
let archivePath = path.join(fastbootDistDir, archiveName);
let zip = archiver('zip', {
zlib: { level: 9 }
});
let output = fs.createWriteStream(archivePath);
zip.pipe(output);
if (ignoreFiles) {
zip.glob("**/*", {
cwd: distDir,
ignore: ignoreFiles
}, {
prefix: '/dist/'
});
} else {
zip.directory(distDir, 'dist');
}
return zip
.finalize()
.then(() => {
return {
fastbootArchiveName: archiveName,
fastbootArchivePath: archivePath
};
});
}
});
return new DeployPlugin();
}
};