-
Notifications
You must be signed in to change notification settings - Fork 2
/
prepare.js
68 lines (57 loc) · 1.81 KB
/
prepare.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
const _ = require('lodash');
const async = require('async');
const copy = require('cp-file');
const join = require('path').join;
const dirname = require('path').dirname;
const rimraf = require('rimraf');
const createTmpDir = require('./lib/createTmpDir');
const getReleaseManifest = require('./lib/getReleaseManifest');
const getAppManifests = require('./lib/getAppManifests');
const cp = _.curry((
from
, to
, cb
) => (
copy(from, to)
.then(() => cb(null))
.catch(cb)
), 3);
const TMP_DIR = '__manifests';
const DEPLOYMENT_MANIFEST = 'deploymentManifest.json';
const prepare = (
options
, plugins
, deploymentManifestPath
, tmpDir
, done
) => {
options = options || {};
tmpDir = tmpDir || join(process.cwd(), TMP_DIR);
const tmpDeploymentManifest = join(tmpDir, DEPLOYMENT_MANIFEST);
var clear = (cb) => cb();
if (options.clearWorkspace) {
clear = (cb) => rimraf(tmpDir, cb);
}
const afterPlugins = _.map(_.filter(plugins, (p) => p.afterPrepare),
(p) => p.afterPrepare.bind(p, tmpDir));
const afterReleasePlugins = _.map(_.filter(plugins, (p) => p.afterGetReleaseManifest),
(p) => p.afterGetReleaseManifest.bind(p, tmpDir));
const afterDeploymentPlugins = _.map(_.filter(plugins, (p) => p.afterGetDeploymentManifest),
(p) => p.afterGetDeploymentManifest.bind(p, tmpDir));
const afterRelease = afterReleasePlugins
.concat([getAppManifests(plugins, tmpDir)])
.concat(afterPlugins);
async.waterfall([
clear
, createTmpDir(tmpDir)
, (next) => {
cp(deploymentManifestPath, tmpDeploymentManifest)((err) => {
if (err) return next(err);
next(null, require(tmpDeploymentManifest));
});
}].concat(afterDeploymentPlugins)
.concat([getReleaseManifest(plugins, tmpDir, dirname(deploymentManifestPath))])
.concat(afterRelease)
, done);
};
module.exports = prepare;