├── .editorconfig ├── .ember-cli ├── .eslintrc.js ├── .github ├── PULL_REQUEST_TEMPLATE └── workflows │ └── ci.yaml ├── .gitignore ├── .npmignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── config └── environment.js ├── index.js ├── package.json ├── tests ├── .eslintrc.js ├── index-test.js └── runner.js └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | insert_final_newline = true 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.js] 17 | indent_style = space 18 | indent_size = 2 19 | 20 | [*.hbs] 21 | insert_final_newline = false 22 | indent_style = space 23 | indent_size = 2 24 | 25 | [*.css] 26 | indent_style = space 27 | indent_size = 2 28 | 29 | [*.html] 30 | indent_style = space 31 | indent_size = 2 32 | 33 | [*.{diff,md}] 34 | trim_trailing_whitespace = false 35 | -------------------------------------------------------------------------------- /.ember-cli: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | Ember CLI sends analytics information by default. The data is completely 4 | anonymous, but there are times when you might want to disable this behavior. 5 | 6 | Setting `disableAnalytics` to true will prevent any data from being sent. 7 | */ 8 | "disableAnalytics": false 9 | } 10 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parserOptions: { 4 | ecmaVersion: 6, 5 | sourceType: 'module' 6 | }, 7 | extends: 'eslint:recommended', 8 | env: { 9 | browser: true, 10 | node: true 11 | }, 12 | rules: { 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE: -------------------------------------------------------------------------------- 1 | ## What Changed & Why 2 | Explain what changed and why. 3 | 4 | ## Related issues 5 | Link to related issues in this or other repositories (if any) 6 | 7 | ## PR Checklist 8 | - [ ] Add tests 9 | - [ ] Add documentation 10 | - [ ] Prefix documentation-only commits with [DOC] 11 | 12 | ## People 13 | Mention people who would be interested in the changeset (if any) 14 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: Continuous Integration 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | test: 9 | name: Test 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | node-version: [14.x, 16.x, 18.x, 20.x] 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Use Node.js ${{ matrix.node-version }} 17 | uses: actions/setup-node@v3 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | cache: 'yarn' 21 | - run: yarn install 22 | - run: yarn test 23 | 24 | test-floating: 25 | name: Floating Dependencies 26 | runs-on: ubuntu-latest 27 | strategy: 28 | matrix: 29 | node-version: [14.x, 16.x, 18.x, 20.x] 30 | steps: 31 | - uses: actions/checkout@v2 32 | - name: Use Node.js ${{ matrix.node-version }} 33 | uses: actions/setup-node@v3 34 | with: 35 | node-version: ${{ matrix.node-version }} 36 | cache: 'yarn' 37 | - name: install dependencies 38 | run: yarn install --no-lockfile 39 | - name: test 40 | run: yarn test 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # misc 12 | /.sass-cache 13 | /connect.lock 14 | /coverage/* 15 | /libpeerconnection.log 16 | npm-debug.log* 17 | testem.log 18 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | bower_components/ 2 | tests/ 3 | tmp/ 4 | 5 | .bowerrc 6 | .editorconfig 7 | .ember-cli 8 | .travis.yml 9 | .npmignore 10 | **/.gitkeep 11 | bower.json 12 | Brocfile.js 13 | testem.json 14 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | Deprecated as of 10.7.0. highlight(lang, code, ...args) has been deprecated. 4 | Deprecated as of 10.7.0. Please use highlight(code, options) instead. 5 | https://github.com/highlightjs/highlight.js/issues/2277 6 | 7 | ## 3.0.0 (2023-06-04) 8 | 9 | #### :boom: Breaking Change 10 | * [#51](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/51) [BREAKING] Update dependencies and required node versions ([@lukemelia](https://github.com/lukemelia)) 11 | 12 | #### Committers: 1 13 | - Luke Melia ([@lukemelia](https://github.com/lukemelia)) 14 | 15 | ## 2.0.0 (2020-11-24) 16 | 17 | #### :rocket: Enhancement 18 | * [#25](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/25) Add json to default list of file extensions to include in the manifest ([@lukemelia](https://github.com/lukemelia)) 19 | * [#26](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/26) Update dependencies ([@lukemelia](https://github.com/lukemelia)) 20 | 21 | #### Committers: 2 22 | - Luke Melia ([@lukemelia](https://github.com/lukemelia)) 23 | - Vali Aminov ([@bortevik](https://github.com/bortevik)) 24 | 25 | ## [v1.1.0](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/tree/v1.1.0) (2017-05-27) 26 | [Full Changelog](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/compare/v1.0.0...v1.1.0) 27 | 28 | **Merged pull requests:** 29 | 30 | - add ignoreFilePattern config option [\#19](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/19) ([stephencattaneo](https://github.com/stephencattaneo)) 31 | 32 | ## [v1.0.0](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/tree/v1.0.0) (2017-04-06) 33 | [Full Changelog](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/compare/v1.0.0-beta.0...v1.0.0) 34 | 35 | ## [v1.0.0-beta.0](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/tree/v1.0.0-beta.0) (2017-03-25) 36 | [Full Changelog](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/compare/v0.1.2...v1.0.0-beta.0) 37 | 38 | **Merged pull requests:** 39 | 40 | - Update ember-cli and dependencies [\#17](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/17) ([lukemelia](https://github.com/lukemelia)) 41 | - \[DOC\] update URLs to other plugin repos in README [\#16](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/16) ([lukemelia](https://github.com/lukemelia)) 42 | 43 | ## [v0.1.2](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/tree/v0.1.2) (2017-02-21) 44 | [Full Changelog](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/compare/v0.1.1...v0.1.2) 45 | 46 | **Merged pull requests:** 47 | 48 | - Update minimatch to ^3.0.3 [\#14](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/14) ([jpadilla](https://github.com/jpadilla)) 49 | - Remove redis dependency and fix bower package name [\#13](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/13) ([jpadilla](https://github.com/jpadilla)) 50 | 51 | ## [v0.1.1](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/tree/v0.1.1) (2016-02-07) 52 | [Full Changelog](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/compare/v0.1.0...v0.1.1) 53 | 54 | **Merged pull requests:** 55 | 56 | - update ember-cli-deploy-plugin [\#10](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/10) ([ghedamat](https://github.com/ghedamat)) 57 | 58 | ## [v0.1.0](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/tree/v0.1.0) (2015-10-25) 59 | [Full Changelog](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/compare/v0.1.0-beta.2...v0.1.0) 60 | 61 | **Merged pull requests:** 62 | 63 | - Update to use new verbose option for logging [\#8](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/8) ([lukemelia](https://github.com/lukemelia)) 64 | - add ico to default filePattern [\#7](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/7) ([jasonkriss](https://github.com/jasonkriss)) 65 | - add swf to default filePattern [\#6](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/6) ([jasonkriss](https://github.com/jasonkriss)) 66 | 67 | ## [v0.1.0-beta.2](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/tree/v0.1.0-beta.2) (2015-08-09) 68 | [Full Changelog](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/compare/v0.1.0-beta.1...v0.1.0-beta.2) 69 | 70 | ## [v0.1.0-beta.1](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/tree/v0.1.0-beta.1) (2015-08-08) 71 | **Merged pull requests:** 72 | 73 | - Update README.md [\#5](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/5) ([kagemusha](https://github.com/kagemusha)) 74 | - Restructure to use ember-cli-deploy-plugin base class [\#4](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/4) ([lukemelia](https://github.com/lukemelia)) 75 | - Tidy up README [\#3](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/3) ([chrislopresto](https://github.com/chrislopresto)) 76 | - First pass at a README and some code cleanup with @kagemusha [\#2](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/2) ([lukemelia](https://github.com/lukemelia)) 77 | - Use new `configure` hook instead of `willDeploy` [\#1](https://github.com/ember-cli-deploy/ember-cli-deploy-manifest/pull/1) ([lukemelia](https://github.com/lukemelia)) 78 | 79 | 80 | 81 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ember-cli-deploy-manifest 2 | 3 | [![](https://ember-cli-deploy.github.io/ember-cli-deploy-version-badges/plugins/ember-cli-deploy-manifest.svg)](http://ember-cli-deploy.github.io/ember-cli-deploy-version-badges/) 4 | 5 | This plugin generates a [manifest file](https://en.wikipedia.org/wiki/Manifest_file) listing the versioned asset files generated by your app's build process. By comparing the latest manifest to the previous one, your deployment plugin (such as [ember-cli-deploy-s3](https://github.com/ember-cli-deploy/ember-cli-deploy-s3)) can determine which files have changed and only upload those, improving efficiency. 6 | 7 | **How does this work in detail?** 8 | 9 | When you build your ember-cli app in development, your files get globbed together into a bunch of asset files such as myapp.js vendor.js, myapp.css, and vendor.css (see your project's dist/assets dir). 10 | 11 | When you do a production build, your build process will produce fingerprinted copies of these asset files. Fingerprints are used for versioning as described [here](https://en.wikipedia.org/wiki/Fingerprint_(computing)). In practice fingerprints are long hash strings, but for exposition we'll pretend our fingerprints look like a version number. So our manifest will look like: 12 | 13 | ``` 14 | myapp-1.js 15 | vendor-1.js 16 | myapp-1.css 17 | vendor-1.css 18 | ``` 19 | 20 | The first time we deploy, our deployment plugin uploads everything, including our manifest file. 21 | 22 | Say we then edit our app javascript but everything else remains the same. After rebuilding, when we generate our new manifest, it will look something like: 23 | 24 | ``` 25 | myapp-2.js 26 | vendor-1.js 27 | myapp-1.css 28 | vendor-1.css 29 | ``` 30 | 31 | When our deployment plugin is ready to deploy, it retrieves the old manifest (from S3 or wherever its stored), diffs it with the current one, and determines it only has to upload myapp-2.js. For large asset files, this can save alot of time and bandwidth. 32 | 33 | ## Installation 34 | 35 | * `ember install ember-cli-deploy-manifest` 36 | 37 | ## ember-cli-deploy Hooks Implemented 38 | 39 | * `configure` 40 | * `willUpload` 41 | 42 | ## Configuration Options 43 | 44 | ### filePattern 45 | 46 | Files matching this pattern will be included in the manifest. 47 | 48 | _Default:_ `"**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2,json}"` 49 | 50 | ### fileIgnorePattern 51 | 52 | Files matching this pattern will _not_ be included in the manifest even if they match filePattern. 53 | 54 | _Default:_ `null` 55 | 56 | ### manifestPath 57 | 58 | The relative path that the manifest is written to. 59 | 60 | _Default:_ `"manifest.txt"` 61 | 62 | ### distDir 63 | 64 | Directory where assets have been written to 65 | 66 | _Default:_ the `distDir` property of the deployment context 67 | 68 | ### distFiles 69 | 70 | The Array of built assets. 71 | 72 | _Default:_ the `distFiles` property of the deployment context 73 | 74 | ## Prerequisites 75 | 76 | The default configuration of this plugin expects the deployment context to have `distDir` and `distFiles` properties. These are conveniently created by the [ember-cli-deploy-build](https://github.com/ember-cli-deploy/ember-cli-deploy-build) plugin so will work out of the box if you are using that plugin. 77 | 78 | ## Plugins known to work well with this one 79 | 80 | [ember-cli-deploy-s3](https://github.com/ember-cli-deploy/ember-cli-deploy-s3) 81 | 82 | ## Tests 83 | 84 | * yarn test 85 | 86 | ## Why `ember build` and `ember test` don't work 87 | 88 | Since this is a node-only ember-cli addon, this package does not include many files and dependencies which are part of ember-cli's typical `ember build` and `ember test` processes. 89 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(/* environment, appConfig */) { 4 | return { }; 5 | }; 6 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*eslint-env node*/ 2 | 'use strict'; 3 | 4 | var RSVP = require('rsvp'); 5 | var fs = require('fs'); 6 | var path = require('path'); 7 | var minimatch = require('minimatch'); 8 | 9 | var DeployPluginBase = require('ember-cli-deploy-plugin'); 10 | 11 | module.exports = { 12 | name: 'ember-cli-deploy-manifest', 13 | 14 | createDeployPlugin: function(options) { 15 | var DeployPlugin = DeployPluginBase.extend({ 16 | name: options.name, 17 | defaultConfig: { 18 | filePattern: '**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2,json}', 19 | fileIgnorePattern: null, 20 | manifestPath: 'manifest.txt', 21 | distDir: function(context) { 22 | return context.distDir; 23 | }, 24 | distFiles: function(context) { 25 | return context.distFiles || []; 26 | } 27 | }, 28 | 29 | willUpload: function(/* context */) { 30 | var filePattern = this.readConfig('filePattern'); 31 | var distDir = this.readConfig('distDir'); 32 | var distFiles = this.readConfig('distFiles'); 33 | var manifestPath = this.readConfig('manifestPath'); 34 | var fileIgnorePattern = this.readConfig('fileIgnorePattern'); 35 | 36 | this.log('generating manifest at `' + manifestPath + '`', { verbose: true }); 37 | try { 38 | var filesToInclude = distFiles.filter(minimatch.filter(filePattern, { matchBase: true })); 39 | if (fileIgnorePattern != null) { 40 | filesToInclude = filesToInclude.filter(function(path) { 41 | return !minimatch(path, fileIgnorePattern, { matchBase: true }); 42 | }); 43 | } 44 | filesToInclude.sort(); 45 | var outputPath = path.join(distDir, manifestPath); 46 | fs.writeFileSync(outputPath, filesToInclude.join('\n')); 47 | this.log('generated manifest including ' + filesToInclude.length + ' files ok', { verbose: true }); 48 | return { manifestPath: manifestPath }; 49 | } catch (error) { 50 | this.log(error, { color: 'red' }); 51 | return RSVP.reject(error); 52 | } 53 | } 54 | }); 55 | return new DeployPlugin(); 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-cli-deploy-manifest", 3 | "version": "3.0.0", 4 | "description": "Ember CLI Deploy plugin to generate a manifest.", 5 | "directories": { 6 | "doc": "doc", 7 | "test": "tests" 8 | }, 9 | "scripts": { 10 | "release": "release-it", 11 | "test": "node tests/runner.js && ./node_modules/.bin/eslint index.js tests/**/*.js" 12 | }, 13 | "repository": "https://github.com/ember-cli-deploy/ember-cli-deploy-manifest", 14 | "engines": { 15 | "node": "14.x || 16.x || 18.x || >= 20.*" 16 | }, 17 | "author": "Luke Melia and ember-cli-deploy team", 18 | "license": "MIT", 19 | "devDependencies": { 20 | "chai": "^4.3.7", 21 | "chai-as-promised": "^7.1.1", 22 | "ember-cli": "^3.28.6", 23 | "ember-cli-deploy-plugin": "^0.2.9", 24 | "eslint": "^8.42.0", 25 | "glob": "^10.2.6", 26 | "mocha": "^8.2.1", 27 | "release-it": "^14.2.1", 28 | "release-it-lerna-changelog": "^3.1.0", 29 | "rimraf": "^3.0.2" 30 | }, 31 | "dependencies": { 32 | "chalk": "^4.1.0", 33 | "core-object": "^3.1.5", 34 | "minimatch": "^3.0.4", 35 | "rsvp": "^4.8.5" 36 | }, 37 | "keywords": [ 38 | "ember-addon", 39 | "ember-cli-deploy-plugin" 40 | ], 41 | "ember-addon": {}, 42 | "publishConfig": { 43 | "registry": "https://registry.npmjs.org/" 44 | }, 45 | "release-it": { 46 | "plugins": { 47 | "release-it-lerna-changelog": { 48 | "infile": "CHANGELOG.md", 49 | "launchEditor": false 50 | } 51 | }, 52 | "git": { 53 | "requireCleanWorkingDir": false 54 | }, 55 | "github": { 56 | "release": true 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | globals: { 3 | "describe": true, 4 | "afterEach": true, 5 | "beforeEach": true, 6 | "it": true 7 | }, 8 | env: { 9 | embertest: true 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /tests/index-test.js: -------------------------------------------------------------------------------- 1 | /*eslint-env node*/ 2 | 'use strict'; 3 | 4 | var RSVP = require('rsvp'); 5 | var fs = require('fs'); 6 | var path = require('path'); 7 | var rimraf = RSVP.denodeify(require('rimraf')); 8 | var chai = require('chai'); 9 | var chaiAsPromised = require("chai-as-promised"); 10 | chai.use(chaiAsPromised); 11 | var assert = chai.assert; 12 | 13 | describe('manifest plugin', function() { 14 | var subject, mockUi; 15 | 16 | beforeEach(function() { 17 | subject = require('../index'); 18 | mockUi = { 19 | verbose: true, 20 | messages: [], 21 | write: function() { }, 22 | writeLine: function(message) { 23 | this.messages.push(message); 24 | } 25 | }; 26 | }); 27 | 28 | it('has a name', function() { 29 | var result = subject.createDeployPlugin({ 30 | name: 'test-plugin' 31 | }); 32 | 33 | assert.equal(result.name, 'test-plugin'); 34 | }); 35 | 36 | it('implements the correct hooks', function() { 37 | var result = subject.createDeployPlugin({ 38 | name: 'test-plugin' 39 | }); 40 | 41 | assert.equal(typeof result.configure, 'function'); 42 | assert.equal(typeof result.willUpload, 'function'); 43 | }); 44 | 45 | describe('configure hook', function() { 46 | it('resolves if config is ok', function() { 47 | var plugin = subject.createDeployPlugin({ 48 | name: 'manifest' 49 | }); 50 | 51 | var context = { 52 | ui: mockUi, 53 | config: { 54 | manifest: { 55 | filePattern: '**/*', 56 | manifestPath: 'manifest.txt' 57 | } 58 | } 59 | }; 60 | 61 | plugin.beforeHook(context); 62 | plugin.configure(context); 63 | assert.ok(true); // it didn't throw 64 | }); 65 | describe('without providing config', function () { 66 | var plugin, context, config; 67 | beforeEach(function() { 68 | config = { }; 69 | plugin = subject.createDeployPlugin({ 70 | name: 'manifest' 71 | }); 72 | context = { 73 | ui: mockUi, 74 | config: config 75 | }; 76 | plugin.beforeHook(context); 77 | }); 78 | it('warns about missing optional config', function() { 79 | plugin.configure(context); 80 | var messages = mockUi.messages.reduce(function(previous, current) { 81 | if (/- Missing config:\s.*, using default:\s/.test(current)) { 82 | previous.push(current); 83 | } 84 | 85 | return previous; 86 | }, []); 87 | assert.equal(messages.length, 5); 88 | }); 89 | 90 | it('adds default config to the config object', function() { 91 | plugin.configure(context); 92 | assert.isDefined(config.manifest.filePattern); 93 | assert.isDefined(config.manifest.manifestPath); 94 | assert.isDefined(config.manifest.distDir); 95 | assert.isDefined(config.manifest.distFiles); 96 | assert.isDefined(config.manifest.fileIgnorePattern); 97 | }); 98 | }); 99 | }); 100 | 101 | describe('willUpload hook', function() { 102 | var plugin; 103 | var context; 104 | 105 | beforeEach(function() { 106 | plugin = subject.createDeployPlugin({ 107 | name: 'manifest' 108 | }); 109 | 110 | context = { 111 | distDir: 'tmp/test-dist', 112 | distFiles: [ 113 | 'assets/foo-178d195608c0b18cf0ec5e982b39cad8.js', 114 | 'assets/bar-da3d0fb7db52f8273550c11403df178f.css', 115 | 'index.html', 116 | 'baz.txt', 117 | ], 118 | ui: mockUi, 119 | project: { name: function() { return 'test-project'; } }, 120 | config: { 121 | manifest: { 122 | filePattern: '**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2}', 123 | manifestPath: 'manifest.txt', 124 | distDir: function(context){ return context.distDir; }, 125 | distFiles: function(context){ return context.distFiles; } 126 | } 127 | } 128 | }; 129 | if (!fs.existsSync('tmp')) { fs.mkdirSync('tmp'); } 130 | if (!fs.existsSync(context.distDir)) { fs.mkdirSync(context.distDir); } 131 | if (!fs.existsSync(path.join(context.distDir, 'assets'))) { fs.mkdirSync(path.join(context.distDir, 'assets')); } 132 | fs.writeFileSync(path.join(context.distDir, context.distFiles[0]), 'alert("Hello foo world!");', 'utf8'); 133 | fs.writeFileSync(path.join(context.distDir, context.distFiles[1]), 'body { color: red; }', 'utf8'); 134 | fs.writeFileSync(path.join(context.distDir, context.distFiles[2]), 'Hello world', 'utf8'); 135 | fs.writeFileSync(path.join(context.distDir, context.distFiles[3]), 'Here are some notes.', 'utf8'); 136 | plugin.beforeHook(context); 137 | }); 138 | 139 | afterEach(function(){ 140 | return rimraf(context.distDir); 141 | }); 142 | 143 | it('includes the matching files in a manifest', function(done) { 144 | var result = plugin.willUpload(context); 145 | try { 146 | var manifestContents = fs.readFileSync(path.join(context.distDir, 'manifest.txt'), { encoding: 'utf8' }); 147 | var lines = manifestContents.split("\n"); 148 | assert.equal(lines.length, 3); 149 | assert.equal(lines[0], "assets/bar-da3d0fb7db52f8273550c11403df178f.css"); 150 | assert.equal(lines[1], "assets/foo-178d195608c0b18cf0ec5e982b39cad8.js"); 151 | assert.equal(lines[2], "baz.txt"); 152 | assert.deepEqual(result, { manifestPath: 'manifest.txt' }); 153 | done(); 154 | } catch(err) { 155 | done(err); 156 | } 157 | }); 158 | 159 | it('excludes files matching the fileIgnorePattern from the manifest', function(done) { 160 | context.config.manifest.fileIgnorePattern = 'baz.txt' 161 | var result = plugin.willUpload(context); 162 | try { 163 | var manifestContents = fs.readFileSync(path.join(context.distDir, 'manifest.txt'), { encoding: 'utf8' }); 164 | var lines = manifestContents.split("\n"); 165 | assert.equal(lines.length, 2); 166 | assert.equal(lines[0], "assets/bar-da3d0fb7db52f8273550c11403df178f.css"); 167 | assert.equal(lines[1], "assets/foo-178d195608c0b18cf0ec5e982b39cad8.js"); 168 | assert.deepEqual(result, { manifestPath: 'manifest.txt' }); 169 | done(); 170 | } catch(err) { 171 | done(err); 172 | } 173 | }); 174 | }); 175 | }); 176 | -------------------------------------------------------------------------------- /tests/runner.js: -------------------------------------------------------------------------------- 1 | /*eslint-env node*/ 2 | 'use strict'; 3 | 4 | var glob = require('glob'); 5 | var Mocha = require('mocha'); 6 | 7 | var mocha = new Mocha({ 8 | reporter: 'spec' 9 | }); 10 | 11 | var arg = process.argv[2]; 12 | var root = 'tests/'; 13 | 14 | function addFiles(mocha, files) { 15 | glob.sync(root + files).forEach(mocha.addFile.bind(mocha)); 16 | } 17 | 18 | addFiles(mocha, '/**/*-test.js'); 19 | 20 | if (arg === 'all') { 21 | addFiles(mocha, '/**/*-test-slow.js'); 22 | } 23 | 24 | mocha.run(function(failures) { 25 | process.on('exit', function() { 26 | process.exit(failures); 27 | }); 28 | }); 29 | --------------------------------------------------------------------------------