This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
forked from ember-cli-deploy/ember-cli-deploy-manifest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (51 loc) · 2 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
/*eslint-env node*/
'use strict';
var RSVP = require('rsvp');
var fs = require('fs');
var path = require('path');
var minimatch = require('minimatch');
var DeployPluginBase = require('ember-cli-deploy-plugin');
module.exports = {
name: 'ember-cli-deploy-manifest',
createDeployPlugin: function(options) {
var DeployPlugin = DeployPluginBase.extend({
name: options.name,
defaultConfig: {
filePattern: '**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2}',
fileIgnorePattern: null,
manifestPath: 'manifest.txt',
distDir: function(context) {
return context.distDir;
},
distFiles: function(context) {
return context.distFiles || [];
}
},
willUpload: function(/* context */) {
var filePattern = this.readConfig('filePattern');
var distDir = this.readConfig('distDir');
var distFiles = this.readConfig('distFiles');
var manifestPath = this.readConfig('manifestPath');
var fileIgnorePattern = this.readConfig('fileIgnorePattern');
this.log('generating manifest at `' + manifestPath + '`', { verbose: true });
try {
var filesToInclude = distFiles.filter(minimatch.filter(filePattern, { matchBase: true }));
if (fileIgnorePattern != null) {
filesToInclude = filesToInclude.filter(function(path) {
return !minimatch(path, fileIgnorePattern, { matchBase: true });
});
}
filesToInclude.sort();
var outputPath = path.join(distDir, manifestPath);
fs.writeFileSync(outputPath, filesToInclude.join('\n'));
this.log('generated manifest including ' + filesToInclude.length + ' files ok', { verbose: true });
return { manifestPath: manifestPath };
} catch (error) {
this.log(error, { color: 'red' });
return RSVP.reject(error);
}
}
});
return new DeployPlugin();
}
};