Skip to content

Commit 153f872

Browse files
committed
Initial logic commit
1 parent b2e0d4e commit 153f872

File tree

4 files changed

+6760
-40
lines changed

4 files changed

+6760
-40
lines changed

README.md

+74-27
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,114 @@
1-
# ember-cli-deploy-manifest-json
1+
# ember-cli-deploy-index-json
22

3-
> An Ember CLI Deploy plugin to ....... (you could add a tag line for your plugin here)
3+
> An Ember CLI Deploy plugin to use a JSON index rather than an HTML one as provided by [`ember-cli-deploy-s3-index`](https://github.com/ember-cli-deploy/ember-cli-deploy-s3-index).
44
5-
[TODO] You could write a short summary of your plugin here
5+
This JSON index file is meant to be consumed by some application embedding yours.
6+
7+
```
8+
$ ember deploy production
9+
$ cat tmp/deploy-dist/index.json
10+
{
11+
"assets/dummy.css": "assets/dummy-d41d8cd98f00b204e9800998ecf8427e.css",
12+
"assets/dummy.js": "assets/dummy-f1caa4785f44f7dc0ca9118458c120f8.js",
13+
"assets/vendor.js": "assets/vendor-b3a3b580d0c1bf83382792291e35020b.js",
14+
"assets/vendor.css": "assets/vendor-d41d8cd98f00b204e9800998ecf8427e.css",
15+
"crossdomain.xml": "crossdomain.xml",
16+
"robots.txt": "robots.txt"
17+
}
18+
```
619

720
## What is an Ember CLI Deploy plugin?
821

922
A plugin is an addon that can be executed as a part of the Ember CLI Deploy pipeline. A plugin will implement one or more of the Ember CLI Deploy's pipeline hooks.
1023

1124
For more information on what plugins are and how they work, please refer to the [Plugin Documentation][1].
1225

13-
## Quick Start
26+
## Setup
27+
28+
- Requirements
29+
30+
You'll first have to [setup `ember-cli-deploy-s3-index`](https://github.com/ember-cli-deploy/ember-cli-deploy-s3-index#quick-start).
1431

1532
- Install this plugin
1633

1734
```bash
18-
$ ember install ember-cli-deploy-manifest-json
35+
$ ember install ember-cli-deploy-index-json
1936
```
2037

21-
[TODO] You could add some sensible default config examples needed to quickly run your plugin
38+
- Configuration
2239

23-
- Run the pipeline
40+
Edit `config/deploy.js` so that your configuration looks like the snippet below.
2441

25-
```bash
26-
$ ember deploy
42+
```js
43+
s3: {},
44+
'revision-data': {
45+
filePattern: 'index.json',
46+
type: 'version-commit'
47+
},
48+
's3-index': {
49+
filePattern: 'index.json'
50+
}
2751
```
2852

29-
## Installation
30-
Run the following command in your terminal:
53+
*In depth:* The idea is that `revision-data`, `s3-index` and `index-json` have the same `filePattern` value. `index-json` is not present in this example because we're using its default `filePattern` value.
3154

32-
```bash
33-
ember install ember-cli-deploy-manifest-json
34-
```
55+
## Usage
56+
57+
- Deploy version to production environment
58+
59+
`ember deploy production`
60+
61+
- List versions on production environment
62+
63+
`ember deploy:list production`
64+
65+
- Activate a version on the production environment
66+
67+
`ember deploy:activate --revision <revision-key>`
3568

3669
## Ember CLI Deploy Hooks Implemented
3770

3871
For detailed information on what plugin hooks are and how they work, please refer to the [Plugin Documentation][1].
3972

40-
[TODO] You should add a list of the pipeline hooks that your plugin implements here, for example:
41-
42-
- `configure`
43-
- `build`
44-
- `upload`
73+
- `willUpload`
4574

4675
## Configuration Options
4776

4877
For detailed information on how configuration of plugins works, please refer to the [Plugin Documentation][1].
4978

50-
[TODO] You should describe the config options your plugin accepts here, for example:
79+
### filePattern
5180

52-
### someConfigProperty
81+
Files matching this pattern will be included in the index.
5382

54-
[TODO] Some description of this config property should go here
83+
*Default:* `'**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2}'`
5584

56-
*Default:* `'some sensible default could go here'`
85+
### fileIgnorePattern
5786

58-
## Prerequisites
87+
Files matching this pattern will *not* be included in the index even if they match filePattern.
88+
89+
*Default:* `null`
90+
91+
### indexPath
92+
93+
The JSON index file name. If changed, you should adapt `revision-data` and `s3-index` plugins configs accordingly.
94+
95+
*Default:* `'index.json'`
5996

60-
The following properties are expected to be present on the deployment context object:
97+
### distDir
6198

62-
[TODO] You should describe which context properties your plugin depends on, for example:
99+
Directory where assets have been written to
100+
101+
*Default:* the `distDir` property of the deployment context
102+
103+
### distFiles
104+
105+
The Array of built assets.
106+
107+
*Default:* the `distFiles` property of the deployment context
108+
109+
## Prerequisites
63110

64-
- `distDir` (provided by [ember-cli-deploy-build][2])
111+
No properties are expected to be present on the deployment context object.
65112

66113
## Tests
67114

index.js

+51-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
/*eslint-env node*/
22
'use strict';
33

4-
//const RSVP = require('rsvp');
4+
const RSVP = require('rsvp');
5+
const fs = require('fs');
6+
const path = require('path');
7+
const minimatch = require('minimatch');
8+
const jsonfile = require('jsonfile');
59
const DeployPluginBase = require('ember-cli-deploy-plugin');
610

11+
// removes the md5 hash from the filename
12+
function getOriginalFilename(filename) {
13+
return filename.replace(/(-[a-f0-9]{32})(\..+)$/g, '$2');
14+
}
15+
716
module.exports = {
8-
name: 'ember-cli-deploy-manifest-json',
17+
name: 'ember-cli-deploy-index-json',
918

1019
createDeployPlugin: function(options) {
1120
let DeployPlugin = DeployPluginBase.extend({
@@ -17,10 +26,17 @@ module.exports = {
1726
* http://ember-cli-deploy.com/docs/v1.0.x/creating-a-plugin/#validating-plugin-config
1827
*/
1928

20-
defaultConfig: {
21-
meaningOfLife: 42 // Example default config. Remove this.
22-
},
23-
requiredConfig: ['isInNeedOfSleep'], // Example required config. Remove this;
29+
defaultConfig: {
30+
filePattern: '**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2}',
31+
fileIgnorePattern: null,
32+
indexPath: 'index.json',
33+
distDir: function(context) {
34+
return context.distDir;
35+
},
36+
distFiles: function(context) {
37+
return context.distFiles || [];
38+
}
39+
},
2440

2541
/*
2642
* Implement any pipeline hooks here
@@ -39,9 +55,35 @@ module.exports = {
3955
// };
4056
//},
4157

42-
//willDeploy(context) {
43-
// return RSVP.resolve(); // Return a promise if you'd like the pipeline to wait until the hook has performed some function
44-
//},
58+
willUpload: function(/* context */) {
59+
let filePattern = this.readConfig('filePattern');
60+
let distDir = this.readConfig('distDir');
61+
let distFiles = this.readConfig('distFiles');
62+
let indexPath = this.readConfig('indexPath');
63+
let fileIgnorePattern = this.readConfig('fileIgnorePattern');
64+
65+
this.log('generating manifest at `' + indexPath + '`', { verbose: true });
66+
try {
67+
let filesToInclude = distFiles.filter(minimatch.filter(filePattern, { matchBase: true }));
68+
if (fileIgnorePattern != null) {
69+
filesToInclude = filesToInclude.filter(function(path) {
70+
return !minimatch(path, fileIgnorePattern, { matchBase: true });
71+
});
72+
}
73+
filesToInclude.sort();
74+
let mappedFilesToInclude = {};
75+
filesToInclude.forEach((filename)=> {
76+
mappedFilesToInclude[getOriginalFilename(filename)] = filename;
77+
});
78+
let outputPath = path.join(distDir, indexPath);
79+
jsonfile.writeFileSync(outputPath, mappedFilesToInclude, { spaces: 2 });
80+
this.log('generated manifest including ' + filesToInclude.length + ' files ok', { verbose: true });
81+
return { indexPath };
82+
} catch (error) {
83+
this.log(error, { color: 'red' });
84+
return RSVP.reject(error);
85+
}
86+
}
4587

4688
//willBuild(context) {},
4789
//build(context) {},

0 commit comments

Comments
 (0)