-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
115 lines (94 loc) · 3.46 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
105
106
107
108
109
110
111
112
113
114
115
/* eslint-env node*/
'use strict'
const RSVP = require('rsvp')
const path = require('path')
const minimatch = require('minimatch')
const jsonfile = require('jsonfile')
const DeployPluginBase = require('ember-cli-deploy-plugin')
// removes the md5 hash from the filename
function getOriginalFilename(filename) {
return filename.replace(/(-[a-f0-9]{32})(\..+)$/g, '$2')
}
module.exports = {
name: 'ember-cli-deploy-index-json',
createDeployPlugin(options) {
let DeployPlugin = DeployPluginBase.extend({
name: options.name,
/*
* Define any config validation here
*
* http://ember-cli-deploy.com/docs/v1.0.x/creating-a-plugin/#validating-plugin-config
*/
defaultConfig: { // eslint-disable-line ember/avoid-leaking-state-in-ember-objects
filePattern: '**/*.{js,css,json,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2}',
fileIgnorePattern: null,
indexPath: 'index.json',
distDir(context) {
return context.distDir
},
distFiles(context) {
return context.distFiles || []
}
},
/*
* Implement any pipeline hooks here
*
* http://ember-cli-deploy.com/docs/v1.0.x/pipeline-hooks/
*/
// configure(context) {
// let configProp = this.readConfig('foo'); // this is how you access plugin config
// },
// setup(context) {
// // Return an object with values you'd like merged in to the context to be accessed by other pipeline hooks and plugins
// return {
// someProp: 'someValue'
// };
// },
willUpload(/* context */) {
let filePattern = this.readConfig('filePattern')
let distDir = this.readConfig('distDir')
let distFiles = this.readConfig('distFiles')
let indexPath = this.readConfig('indexPath')
let fileIgnorePattern = this.readConfig('fileIgnorePattern')
this.log(`generating manifest at \`${ indexPath }\``, { verbose: true })
try {
let filesToInclude = distFiles.filter(minimatch.filter(filePattern, { matchBase: true }))
if (fileIgnorePattern != null) {
filesToInclude = filesToInclude.filter(function(path) {
return !minimatch(path, fileIgnorePattern, { matchBase: true })
})
}
filesToInclude.sort()
let mappedFilesToInclude = {}
filesToInclude.forEach((filename)=> {
mappedFilesToInclude[getOriginalFilename(filename)] = filename
})
let outputPath = path.join(distDir, indexPath)
jsonfile.writeFileSync(outputPath, mappedFilesToInclude, { spaces: 2 })
this.log(`generated manifest including ${ filesToInclude.length } files ok`, { verbose: true })
return { indexPath }
} catch(error) {
this.log(error, { color: 'red' })
return RSVP.reject(error)
}
}
// willBuild(context) {},
// build(context) {},
// didBuild(context) {},
// willPrepare(context) {},
// prepare(context) {},
// didPrepare(context) {},
// willUpload(context) {},
// upload(context) {},
// didUpload(context) {},
// willActivate(context) {},
// activate(context) {},
// didActivate(context) {},
// fetchInitialRevisions(context) {},
// fetchRevisions(context) {},
// didDeploy(context) {},
// teardown(context) {},
})
return new DeployPlugin()
}
}