├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .npmignore ├── .prettierignore ├── .prettierrc.js ├── .template-lintrc.js ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── MODULE_REPORT.md ├── README.md ├── addon ├── .gitkeep ├── components │ ├── new-version-notifier.hbs │ └── new-version-notifier.js ├── services │ └── new-version.js └── styles │ └── components │ └── new-version-notifier.css ├── app ├── .gitkeep ├── components │ └── new-version-notifier.js └── services │ └── new-version.js ├── blueprints └── ember-cli-new-version │ └── index.js ├── config ├── ember-try.js └── environment.js ├── ember-cli-build.js ├── index.js ├── jsconfig.json ├── package-lock.json ├── package.json ├── testem.js ├── tests ├── acceptance │ └── index-test.js ├── dummy │ ├── app │ │ ├── app.js │ │ ├── components │ │ │ └── .gitkeep │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── helpers │ │ │ └── .gitkeep │ │ ├── index.html │ │ ├── models │ │ │ └── .gitkeep │ │ ├── router.js │ │ ├── routes │ │ │ └── .gitkeep │ │ ├── styles │ │ │ └── app.css │ │ └── templates │ │ │ └── application.hbs │ ├── config │ │ ├── ember-cli-update.json │ │ ├── environment.js │ │ ├── optional-features.json │ │ └── targets.js │ ├── mirage │ │ ├── config.js │ │ ├── scenarios │ │ │ └── default.js │ │ └── serializers │ │ │ └── application.js │ └── public │ │ ├── VERSION.txt │ │ ├── crossdomain.xml │ │ └── robots.txt ├── helpers │ └── .gitkeep ├── index.html ├── integration │ ├── .gitkeep │ └── components │ │ └── new-version-notifier-test.js ├── test-helper.js └── unit │ ├── .gitkeep │ └── services │ └── new-version-test.js └── vendor └── .gitkeep /.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 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | indent_style = space 13 | indent_size = 2 14 | 15 | [*.hbs] 16 | insert_final_newline = false 17 | 18 | [*.{diff,md}] 19 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | /vendor/ 4 | 5 | # compiled output 6 | /dist/ 7 | /tmp/ 8 | 9 | # dependencies 10 | /bower_components/ 11 | /node_modules/ 12 | 13 | # misc 14 | /coverage/ 15 | !.* 16 | .*/ 17 | .eslintcache 18 | 19 | # ember-try 20 | /.node_modules.ember-try/ 21 | /bower.json.ember-try 22 | /package.json.ember-try 23 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | globals: { 5 | server: true, 6 | }, 7 | root: true, 8 | parser: 'babel-eslint', 9 | parserOptions: { 10 | ecmaVersion: 2018, 11 | sourceType: 'module', 12 | ecmaFeatures: { 13 | legacyDecorators: true, 14 | }, 15 | }, 16 | plugins: ['ember'], 17 | extends: [ 18 | 'eslint:recommended', 19 | 'plugin:ember/recommended', 20 | 'plugin:prettier/recommended', 21 | ], 22 | env: { 23 | browser: true, 24 | }, 25 | rules: { 26 | 'no-unsafe-finally': 'off', 27 | }, 28 | overrides: [ 29 | // node files 30 | { 31 | files: [ 32 | './.eslintrc.js', 33 | './.prettierrc.js', 34 | './.template-lintrc.js', 35 | './ember-cli-build.js', 36 | './index.js', 37 | './testem.js', 38 | './blueprints/*/index.js', 39 | './config/**/*.js', 40 | './tests/dummy/config/**/*.js', 41 | ], 42 | parserOptions: { 43 | sourceType: 'script', 44 | }, 45 | env: { 46 | browser: false, 47 | node: true, 48 | }, 49 | plugins: ['node'], 50 | extends: ['plugin:node/recommended'], 51 | }, 52 | { 53 | // Test files: 54 | files: ['tests/**/*-test.{js,ts}'], 55 | extends: ['plugin:qunit/recommended'], 56 | }, 57 | ], 58 | }; 59 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # This file was autogenerated by create-github-actions-setup-for-ember-addons. 2 | # 3 | # You can upgrade the GitHub Actions workflow to the latest blueprints used 4 | # by Create GitHub Actions setup for Ember Addons by running it again: 5 | # 6 | # - `yarn create github-actions-setup-for-ember-addons` if using yarn and 7 | # - `npm init github-actions-setup-for-ember-addons` if using NPM. 8 | # 9 | # See https://github.com/jelhan/create-github-actions-setup-for-ember-addon for 10 | # details. 11 | # 12 | # The following lines contain the configuration used in the last run. Please do 13 | # not change them. Doing so could break upgrade flow. 14 | # 15 | #$ browsers: 16 | #$ - chrome 17 | #$ emberTryScenarios: 18 | #$ - scenario: ember-lts-3.16 19 | #$ - scenario: ember-lts-3.20 20 | #$ - scenario: ember-release 21 | #$ - scenario: ember-beta 22 | #$ - scenario: ember-canary 23 | #$ - scenario: ember-default-with-jquery 24 | #$ - scenario: ember-classic 25 | #$ - scenario: embroider-safe 26 | #$ - scenario: embroider-optimized 27 | #$ nodeVersion: 10.x 28 | #$ packageManager: npm 29 | # 30 | 31 | name: CI 32 | 33 | on: 34 | push: 35 | branches: 36 | - master 37 | pull_request: 38 | 39 | env: 40 | NODE_VERSION: '20.x' 41 | 42 | jobs: 43 | lint: 44 | name: Lint 45 | runs-on: ubuntu-latest 46 | steps: 47 | - uses: actions/checkout@v4 48 | with: 49 | fetch-depth: 1 50 | 51 | - uses: actions/setup-node@v4 52 | with: 53 | node-version: '${{ env.NODE_VERSION }}' 54 | 55 | - name: Get package manager's global cache path 56 | id: global-cache-dir-path 57 | run: echo "::set-output name=dir::$(npm config get cache)" 58 | 59 | - name: Cache package manager's global cache and node_modules 60 | id: cache-dependencies 61 | uses: actions/cache@v4 62 | with: 63 | path: | 64 | ${{ steps.global-cache-dir-path.outputs.dir }} 65 | node_modules 66 | key: ${{ runner.os }}-${{ matrix.node-version }}-${{ 67 | hashFiles('**/package-lock.json' 68 | ) }} 69 | restore-keys: | 70 | ${{ runner.os }}-${{ matrix.node-version }}- 71 | 72 | - name: Install Dependencies 73 | run: npm ci 74 | if: | 75 | steps.cache-dependencies.outputs.cache-hit != 'true' 76 | 77 | - name: Lint 78 | run: npm run-script lint 79 | 80 | test: 81 | name: Tests 82 | runs-on: ${{ matrix.os }} 83 | needs: lint 84 | 85 | strategy: 86 | matrix: 87 | os: [ubuntu-latest] 88 | browser: [chrome] 89 | 90 | steps: 91 | - uses: actions/checkout@v4 92 | with: 93 | fetch-depth: 1 94 | 95 | - uses: actions/setup-node@v4 96 | with: 97 | node-version: '${{ env.NODE_VERSION }}' 98 | 99 | - name: Get package manager's global cache path 100 | id: global-cache-dir-path 101 | run: echo "::set-output name=dir::$(npm config get cache)" 102 | 103 | - name: Cache package manager's global cache and node_modules 104 | id: cache-dependencies 105 | uses: actions/cache@v4 106 | with: 107 | path: | 108 | ${{ steps.global-cache-dir-path.outputs.dir }} 109 | node_modules 110 | key: ${{ runner.os }}-${{ matrix.node-version }}-${{ 111 | hashFiles('**/package-lock.json' 112 | ) }} 113 | restore-keys: | 114 | ${{ runner.os }}-${{ matrix.node-version }}- 115 | 116 | - name: Install Dependencies 117 | run: npm ci 118 | if: | 119 | steps.cache-dependencies.outputs.cache-hit != 'true' 120 | 121 | - name: Test 122 | run: npm run-script test:ember --launch ${{ matrix.browser }} 123 | 124 | floating-dependencies: 125 | name: Floating Dependencies 126 | runs-on: ${{ matrix.os }} 127 | needs: lint 128 | 129 | strategy: 130 | matrix: 131 | os: [ubuntu-latest] 132 | browser: [chrome] 133 | 134 | steps: 135 | - uses: actions/checkout@v4 136 | with: 137 | fetch-depth: 1 138 | 139 | - uses: actions/setup-node@v4 140 | with: 141 | node-version: '${{ env.NODE_VERSION }}' 142 | 143 | - name: Get package manager's global cache path 144 | id: global-cache-dir-path 145 | run: echo "::set-output name=dir::$(npm config get cache)" 146 | 147 | - name: Cache package manager's global cache and node_modules 148 | id: cache-dependencies 149 | uses: actions/cache@v4 150 | with: 151 | path: | 152 | ${{ steps.global-cache-dir-path.outputs.dir }} 153 | node_modules 154 | key: ${{ runner.os }}-${{ matrix.node-version }}-floating-deps 155 | restore-keys: | 156 | ${{ runner.os }}-${{ matrix.node-version }}- 157 | 158 | - name: Install Dependencies 159 | run: npm install --no-package-lock 160 | 161 | - name: Test 162 | run: npm run-script test:ember --launch ${{ matrix.browser }} 163 | 164 | try-scenarios: 165 | name: Tests - ${{ matrix.ember-try-scenario }} 166 | runs-on: ubuntu-latest 167 | continue-on-error: true 168 | needs: test 169 | 170 | strategy: 171 | fail-fast: true 172 | matrix: 173 | ember-try-scenario: 174 | [ 175 | ember-lts-3.20, 176 | ember-lts-3.24, 177 | ember-release, 178 | ember-beta, 179 | ember-canary, 180 | ember-default-with-jquery, 181 | ember-classic, 182 | embroider-safe, 183 | embroider-optimized, 184 | ] 185 | 186 | steps: 187 | - uses: actions/checkout@v4 188 | with: 189 | fetch-depth: 1 190 | 191 | - uses: actions/setup-node@v4 192 | with: 193 | node-version: '${{ env.NODE_VERSION }}' 194 | 195 | - name: Get package manager's global cache path 196 | id: global-cache-dir-path 197 | run: echo "::set-output name=dir::$(npm config get cache)" 198 | 199 | - name: Cache package manager's global cache and node_modules 200 | id: cache-dependencies 201 | uses: actions/cache@v2 202 | with: 203 | path: | 204 | ${{ steps.global-cache-dir-path.outputs.dir }} 205 | node_modules 206 | key: ${{ runner.os }}-${{ matrix.node-version }}-${{ 207 | hashFiles('**/package-lock.json' 208 | ) }} 209 | restore-keys: | 210 | ${{ runner.os }}-${{ matrix.node-version }}- 211 | 212 | - name: Install Dependencies 213 | run: npm ci 214 | if: | 215 | steps.cache-dependencies.outputs.cache-hit != 'true' 216 | 217 | - name: Test 218 | env: 219 | EMBER_TRY_SCENARIO: ${{ matrix.ember-try-scenario }} 220 | run: node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO 221 | -------------------------------------------------------------------------------- /.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 | /bower_components/ 9 | /node_modules/ 10 | 11 | # misc 12 | /.env* 13 | /.pnp* 14 | /.sass-cache 15 | /.eslintcache 16 | /connect.lock 17 | /coverage/ 18 | /libpeerconnection.log 19 | /npm-debug.log* 20 | /testem.log 21 | /yarn-error.log 22 | 23 | # ember-try 24 | /.node_modules.ember-try/ 25 | /bower.json.ember-try 26 | /package.json.ember-try 27 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist/ 3 | /tmp/ 4 | 5 | # dependencies 6 | /bower_components/ 7 | 8 | # misc 9 | /.bowerrc 10 | /.editorconfig 11 | /.ember-cli 12 | /.env* 13 | /.eslintcache 14 | /.eslintignore 15 | /.eslintrc.js 16 | /.git/ 17 | /.gitignore 18 | /.prettierignore 19 | /.prettierrc.js 20 | /.template-lintrc.js 21 | /.watchmanconfig 22 | /bower.json 23 | /config/ember-try.js 24 | /CONTRIBUTING.md 25 | /ember-cli-build.js 26 | /testem.js 27 | /tests/ 28 | /yarn-error.log 29 | /yarn.lock 30 | .gitkeep 31 | 32 | # ember-try 33 | /.node_modules.ember-try/ 34 | /bower.json.ember-try 35 | /package.json.ember-try 36 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | /vendor/ 4 | 5 | # compiled output 6 | /dist/ 7 | /tmp/ 8 | 9 | # dependencies 10 | /bower_components/ 11 | /node_modules/ 12 | 13 | # misc 14 | /coverage/ 15 | !.* 16 | .eslintcache 17 | 18 | # ember-try 19 | /.node_modules.ember-try/ 20 | /bower.json.ember-try 21 | /package.json.ember-try 22 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | singleQuote: true, 5 | }; 6 | -------------------------------------------------------------------------------- /.template-lintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: 'recommended', 5 | }; 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ## [4.1.0](https://github.com/sethwebster/ember-cli-new-version/compare/v4.0.2...v4.1.0) (2022-03-30) 6 | 7 | 8 | ### Features 9 | 10 | * Allow disabling in dev ([#117](https://github.com/sethwebster/ember-cli-new-version/issues/117)) ([6eb5a64](https://github.com/sethwebster/ember-cli-new-version/commit/6eb5a648697972d34df9e8b1e119005ce7cd7237)) 11 | 12 | 13 | ### Bug Fixes 14 | 15 | * add @ember/test-waiters dep ([6df382f](https://github.com/sethwebster/ember-cli-new-version/commit/6df382fe7858767a84c1aba6bbc6b6893835e91d)) 16 | * replace/remove old test helpers/resolver ([66db025](https://github.com/sethwebster/ember-cli-new-version/commit/66db025353271c2d451e1c76290856a31730a7f9)) 17 | 18 | ### [4.0.2](https://github.com/sethwebster/ember-cli-new-version/compare/v4.0.1...v4.0.2) (2022-01-12) 19 | 20 | 21 | ### Bug Fixes 22 | 23 | * add tracking context to ignoredVersions ([#109](https://github.com/sethwebster/ember-cli-new-version/issues/109)) ([a2fcf70](https://github.com/sethwebster/ember-cli-new-version/commit/a2fcf708a15f877726e04e1ab4f3178fa2d7c6e3)) 24 | 25 | ### [4.0.1](https://github.com/sethwebster/ember-cli-new-version/compare/v4.0.0...v4.0.1) (2021-12-20) 26 | 27 | 28 | ### Bug Fixes 29 | 30 | * action decorators not used in places ([#107](https://github.com/sethwebster/ember-cli-new-version/issues/107)) ([4cefaea](https://github.com/sethwebster/ember-cli-new-version/commit/4cefaeaf4a620d89f5342223ce634a7fad383fb2)), closes [#105](https://github.com/sethwebster/ember-cli-new-version/issues/105) 31 | 32 | ## [4.0.0](https://github.com/sethwebster/ember-cli-new-version/compare/v3.0.0...v4.0.0) (2021-12-15) 33 | 34 | 35 | ### ⚠ BREAKING CHANGES 36 | 37 | * The version file is always created, you must opt out now instead of opt in, see the README 38 | 39 | The way to opt out of this behavior is to include a VERSION.txt in the 40 | app, otherwise the file will be created automatically. When a 41 | VERSION.txt file exists the treeForPublic build step won't overwrite it. 42 | 43 | Co-authored-by: Ilya Radchenko 44 | * config options come from a new place, see the readme 45 | 46 | ### Features 47 | 48 | * Always create the version file ([da01a6f](https://github.com/sethwebster/ember-cli-new-version/commit/da01a6f5c19f6cf2fc37f9c45d522d7f3824c507)) 49 | 50 | 51 | ### Bug Fixes 52 | 53 | * Do configuration during build ([2fe8486](https://github.com/sethwebster/ember-cli-new-version/commit/2fe8486cf55fd6ce07309f1f772b77a042df10fc)) 54 | 55 | ## [3.0.0](https://github.com/sethwebster/ember-cli-new-version/compare/v2.0.2...v3.0.0) (2021-11-24) 56 | 57 | 58 | ### ⚠ BREAKING CHANGES 59 | 60 | * Drop Node < 12 61 | * Drop Ember.js < 3.20 and CLI < 3.20 62 | * use GC for notifier 63 | 64 | * fix: update waitFor 65 | 66 | * fix: update deps 67 | * introduces a new version service. Some arguments from the components have been moved here and other moved to the configuration. 68 | * How the version check happens has also changed, see https://github.com/sethwebster/ember-cli-new-version/pull/94 69 | 70 | * Enable JS code checking 71 | 72 | * Extract new version fetching and checking from the NewVersionNotifier component in a service 73 | 74 | The logic is now in a service so that it can be used independently of the action. 75 | 76 | There are slight behaviour changes and new behaviours as well. 77 | 78 | The service contains an observable `isNewVersionAvailable` property. 79 | This property is set to true when a new version is available. 80 | 81 | The version checking is slightly different: before, the first check was ignored because the component was comparing the previously fetched version and the latest fetched version. 82 | Now, the version is always checked against the version provided in environment.js. This thus means the comparison is always done against the compiled version of the app. 83 | 84 | The component had a way to ignore a version, by setting the next version to check to the latest fetched version. To keep the compatibility with this behaviour, there is now an explicit list of "ignore versions" in the service, populated when the user closes the `NewVersionNotifier`. Note that this list is kept in memory only and when the user reloads the page, the list is empty again. This is the same behaviour as before. 85 | 86 | I kept the code related to testing in the service to limit the changes, but this could be moved in the TestNewVersionService implementation so that the original NewVersionService is kept clean of testing behaviour. 87 | 88 | The onNewVersion action still exists but is now in the service. If one needs this callback, he/she can overload the NewVersionService and override onNewVersion. Same thing for onError. 89 | 90 | Some properties that were arguments of the component have been moved to the configuration. 91 | 92 | * Fix dependencies declaration 93 | 94 | Some addon dependencies were declared in devDependencies while they are needed by the addon to run. 95 | 96 | * Make MAX_COUNT_IN_TESTING a configuration variable 97 | 98 | This let tests override this option as needed. 99 | 100 | * fix: keep the initial slash for fetching VERSION.txt 101 | 102 | Before this commit, the fetch of VERSION.txt with a default configuration would result to calling "VERSION.txt", which means "fetch the file relative to the current page URL". 103 | 104 | This may lead to issue in production, but leads to issues in some tests situation when using `ember test` where the full path to VERSION.txt is resolved to `/VERSION.txt` when declaring it in tests, while it is resolved to `http://localhost:7357/some-random-numbers/tests/VERSION.txt` when fetching the file. 105 | 106 | This commit fixes the issue by not removing the `/` in front of VERSION.txt. 107 | 108 | This fixes the isse for my scenarios; but I am not sure why there was this check and removal of the `/` in the first place, this thus may lead to breaking changes for some. 109 | 110 | Co-authored-by: Ilya Radchenko 111 | * introduces a new version service. Some arguments from the components have been moved here and other moved to the configuration. 112 | * How the version check happens has also changed, see https://github.com/sethwebster/ember-cli-new-version/pull/94 113 | 114 | * Enable JS code checking 115 | 116 | * Extract new version fetching and checking from the NewVersionNotifier component in a service 117 | 118 | The logic is now in a service so that it can be used independently of the action. 119 | 120 | There are slight behaviour changes and new behaviours as well. 121 | 122 | The service contains an observable `isNewVersionAvailable` property. 123 | This property is set to true when a new version is available. 124 | 125 | The version checking is slightly different: before, the first check was ignored because the component was comparing the previously fetched version and the latest fetched version. 126 | Now, the version is always checked against the version provided in environment.js. This thus means the comparison is always done against the compiled version of the app. 127 | 128 | The component had a way to ignore a version, by setting the next version to check to the latest fetched version. To keep the compatibility with this behaviour, there is now an explicit list of "ignore versions" in the service, populated when the user closes the `NewVersionNotifier`. Note that this list is kept in memory only and when the user reloads the page, the list is empty again. This is the same behaviour as before. 129 | 130 | I kept the code related to testing in the service to limit the changes, but this could be moved in the TestNewVersionService implementation so that the original NewVersionService is kept clean of testing behaviour. 131 | 132 | The onNewVersion action still exists but is now in the service. If one needs this callback, he/she can overload the NewVersionService and override onNewVersion. Same thing for onError. 133 | 134 | Some properties that were arguments of the component have been moved to the configuration. 135 | 136 | * Fix dependencies declaration 137 | 138 | Some addon dependencies were declared in devDependencies while they are needed by the addon to run. 139 | * use GC for notifier 140 | * Drop ember-concurrency < v1, update Ember deps. 141 | * Drop Ember < 3.16 (might still work, but untested going forward) 142 | * Drop Node < 10 143 | 144 | ### Features 145 | 146 | * Extract new version fetching and checking from the NewVersionNotifier component in a service ([#94](https://github.com/sethwebster/ember-cli-new-version/issues/94)) ([83c3528](https://github.com/sethwebster/ember-cli-new-version/commit/83c35280e847aa27a831334ff55ed29424396df4)) 147 | * Make MAX_COUNT_IN_TESTING a configuration variable ([#95](https://github.com/sethwebster/ember-cli-new-version/issues/95)) ([ba20169](https://github.com/sethwebster/ember-cli-new-version/commit/ba20169a58551b7e775aefb7b3c25e8a445981d2)) 148 | 149 | 150 | ### Bug Fixes 151 | 152 | * allow ec v1 as well ([32d086d](https://github.com/sethwebster/ember-cli-new-version/commit/32d086dfd9b5c3c60a376b311f297294c92a738c)) 153 | * Ember v3.22.0...v3.26.1 ([e27600c](https://github.com/sethwebster/ember-cli-new-version/commit/e27600ca18e78584831336ce52edef04657e5761)) 154 | * Fix tests & Upgrade ember concurrency to 2.0 ([#81](https://github.com/sethwebster/ember-cli-new-version/issues/81)) ([5e111b1](https://github.com/sethwebster/ember-cli-new-version/commit/5e111b1cd2775aa9c180c80845c003df23ed54fb)) 155 | * keep the initial slash for fetching VERSION.txt ([#99](https://github.com/sethwebster/ember-cli-new-version/issues/99)) ([1daf826](https://github.com/sethwebster/ember-cli-new-version/commit/1daf826874dc166e15d94258f399f7fc2ce6c0c3)), closes [#94](https://github.com/sethwebster/ember-cli-new-version/issues/94) 156 | * regenerator v1 ([22bde5d](https://github.com/sethwebster/ember-cli-new-version/commit/22bde5d3e39fee99da163cb280d6ac78fd6f2ee5)) 157 | * update dep path and lockfile ([f446068](https://github.com/sethwebster/ember-cli-new-version/commit/f446068b9b1a05fd1a3e3a01bfd21ee44eee3189)) 158 | * update deps ([0fa7890](https://github.com/sethwebster/ember-cli-new-version/commit/0fa7890d1fe5a8d42dba711550c11ae11787cc15)) 159 | * update to glimmer component ([9b2abb7](https://github.com/sethwebster/ember-cli-new-version/commit/9b2abb7e7e2fd8ee76a95da83d8f540307220c3d)) 160 | * update waitFor ([244011e](https://github.com/sethwebster/ember-cli-new-version/commit/244011eecc4cbec02e6edde9888c5143bb981f0f)) 161 | * Upgrade v3.11.0...v3.22.0 ([3ecab5c](https://github.com/sethwebster/ember-cli-new-version/commit/3ecab5c358aa403d398ba42b4fb5cbed53924f91)) 162 | * use https version of import regen dep for ci ([1b8adc3](https://github.com/sethwebster/ember-cli-new-version/commit/1b8adc3c31b5e281edfc47ad37dea9bb9ce76930)) 163 | * use node 14 in tests and pin volta ([43d98f0](https://github.com/sethwebster/ember-cli-new-version/commit/43d98f0cc5594e01916062cfc297ba888e5557ea)) 164 | * v3.26.1...v3.28.4 ([9722fdf](https://github.com/sethwebster/ember-cli-new-version/commit/9722fdff976a7fbac3f201bf9c898b64f94c5a33)) 165 | 166 | ### [2.0.2](https://github.com/sethwebster/ember-cli-new-version/compare/v2.0.1...v2.0.2) (2020-11-11) 167 | 168 | 169 | ### Bug Fixes 170 | 171 | * default update message dynamic values ([22f9bb9](https://github.com/sethwebster/ember-cli-new-version/commit/22f9bb939df4f8960c986ae1a570570079c1cc41)), closes [#64](https://github.com/sethwebster/ember-cli-new-version/issues/64) 172 | 173 | 174 | ## [2.0.1](https://github.com/sethwebster/ember-cli-new-version/compare/v2.0.0...v2.0.1) (2019-09-30) 175 | 176 | 177 | ### Bug Fixes 178 | 179 | * security update for deps ([e7bf1af](https://github.com/sethwebster/ember-cli-new-version/commit/e7bf1af)) 180 | * Update ember-concurrency for Ember 3.13+ ([#62](https://github.com/sethwebster/ember-cli-new-version/issues/62)) ([c22a6f5](https://github.com/sethwebster/ember-cli-new-version/commit/c22a6f5)) 181 | * update more deps ([f79e6c2](https://github.com/sethwebster/ember-cli-new-version/commit/f79e6c2)) 182 | 183 | 184 | 185 | 186 | # [2.0.0](https://github.com/sethwebster/ember-cli-new-version/compare/v1.6.0...v2.0.0) (2019-08-06) 187 | 188 | 189 | ### Bug Fixes 190 | 191 | * add v1 to concurrency dep ([27511bb](https://github.com/sethwebster/ember-cli-new-version/commit/27511bb)), closes [#60](https://github.com/sethwebster/ember-cli-new-version/issues/60) 192 | * don't use double curlies for version updateMessage vars ([1269833](https://github.com/sethwebster/ember-cli-new-version/commit/1269833)) 193 | * drop node 6 and test Ember 3.4+ ([7253281](https://github.com/sethwebster/ember-cli-new-version/commit/7253281)) 194 | 195 | 196 | ### BREAKING CHANGES 197 | 198 | * `@updateMessage` now takes `{oldVersion}` and `{newVersion}` instead of `{{oldVersion}}` to `{{newVersion}}` since curlies can be used in strings in hbs and with angle bracket syntax you are far more likely to write strings like that. 199 | * Drop node 6 support and Ember < 3.4 200 | 201 | Might still work on <3.4 but untested 202 | 203 | 204 | 205 | 206 | # [1.6.0](https://github.com/sethwebster/ember-cli-new-version/compare/v1.5.0...v1.6.0) (2019-08-06) 207 | 208 | 209 | ### Bug Fixes 210 | 211 | * **security:** fix audit vulnerabilities ([65d2821](https://github.com/sethwebster/ember-cli-new-version/commit/65d2821)) 212 | 213 | 214 | ### Features 215 | 216 | * allow to set initial delay for first check and disable in fastboot mode ([#61](https://github.com/sethwebster/ember-cli-new-version/issues/61)) ([a650b3d](https://github.com/sethwebster/ember-cli-new-version/commit/a650b3d)) 217 | 218 | 219 | 220 | 221 | # [1.5.0](https://github.com/sethwebster/ember-cli-new-version/compare/v1.4.4...v1.5.0) (2019-05-03) 222 | 223 | 224 | ### Features 225 | 226 | * Allow custom version comparison function ([#57](https://github.com/sethwebster/ember-cli-new-version/issues/57)) ([9b0207d](https://github.com/sethwebster/ember-cli-new-version/commit/9b0207d)) 227 | 228 | 229 | 230 | 231 | ## [1.4.4](https://github.com/sethwebster/ember-cli-new-version/compare/v1.4.3...v1.4.4) (2019-03-26) 232 | 233 | 234 | ### Bug Fixes 235 | 236 | * Update ember-concurrency to the latest version ([#56](https://github.com/sethwebster/ember-cli-new-version/issues/56)) ([53ded44](https://github.com/sethwebster/ember-cli-new-version/commit/53ded44)) 237 | 238 | 239 | 240 | 241 | ## [1.4.3](https://github.com/sethwebster/ember-cli-new-version/compare/v1.4.2...v1.4.3) (2019-01-09) 242 | 243 | 244 | ### Bug Fixes 245 | 246 | * add ember-fetch via a default blueprint instead ([78d97d5](https://github.com/sethwebster/ember-cli-new-version/commit/78d97d5)) 247 | * call super in included ([9ab9941](https://github.com/sethwebster/ember-cli-new-version/commit/9ab9941)) 248 | 249 | 250 | 251 | 252 | ## [1.4.2](https://github.com/sethwebster/ember-cli-new-version/compare/v1.4.1...v1.4.2) (2019-01-05) 253 | 254 | 255 | ### Bug Fixes 256 | 257 | * **lint:** quotes in template ([8dc5c94](https://github.com/sethwebster/ember-cli-new-version/commit/8dc5c94)) 258 | * concurrency updated to fix https://github.com/machty/ember-concurrency/issues/261 ([ede4be3](https://github.com/sethwebster/ember-cli-new-version/commit/ede4be3)) 259 | * run codemods, update tests ([b076032](https://github.com/sethwebster/ember-cli-new-version/commit/b076032)) 260 | * update using ember-cli-update ([0ca640e](https://github.com/sethwebster/ember-cli-new-version/commit/0ca640e)) 261 | 262 | 263 | 264 | 265 | ## [1.4.1](https://github.com/sethwebster/ember-cli-new-version/compare/v1.4.0...v1.4.1) (2019-01-04) 266 | 267 | 268 | ### Bug Fixes 269 | 270 | * replace ember-ajax with ember-fetch ([#54](https://github.com/sethwebster/ember-cli-new-version/issues/54)) ([5e1c79c](https://github.com/sethwebster/ember-cli-new-version/commit/5e1c79c)) 271 | * update deps and move ember-fetch to dep ([99c1c6e](https://github.com/sethwebster/ember-cli-new-version/commit/99c1c6e)) 272 | 273 | 274 | 275 | 276 | # [1.4.0](https://github.com/sethwebster/ember-cli-new-version/compare/v1.3.1...v1.4.0) (2018-09-28) 277 | 278 | 279 | ### Features 280 | 281 | * Add an 'onError' handler that can be used to do something in response to a server error ([#51](https://github.com/sethwebster/ember-cli-new-version/issues/51)) ([1a491c9](https://github.com/sethwebster/ember-cli-new-version/commit/1a491c9)) 282 | 283 | 284 | 285 | 286 | ## [1.3.1](https://github.com/sethwebster/ember-cli-new-version/compare/v1.3.0...v1.3.1) (2018-08-11) 287 | 288 | 289 | ### Bug Fixes 290 | 291 | * Log exceptions instead of throwing them ([#50](https://github.com/sethwebster/ember-cli-new-version/issues/50)) ([46e009b](https://github.com/sethwebster/ember-cli-new-version/commit/46e009b)) 292 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How To Contribute 2 | 3 | ## Installation 4 | 5 | * `git clone ` 6 | * `cd my-addon` 7 | * `npm install` 8 | 9 | ## Linting 10 | 11 | * `npm run lint` 12 | * `npm run lint:fix` 13 | 14 | ## Running tests 15 | 16 | * `ember test` – Runs the test suite on the current Ember version 17 | * `ember test --server` – Runs the test suite in "watch mode" 18 | * `ember try:each` – Runs the test suite against multiple Ember versions 19 | 20 | ## Running the dummy application 21 | 22 | * `ember serve` 23 | * Visit the dummy application at [http://localhost:4200](http://localhost:4200). 24 | 25 | For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/). 26 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 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 | -------------------------------------------------------------------------------- /MODULE_REPORT.md: -------------------------------------------------------------------------------- 1 | ## Module Report 2 | ### Unknown Global 3 | 4 | **Global**: `Ember.testing` 5 | 6 | **Location**: `addon/components/new-version-notifier/component.js` at line 30 7 | 8 | ```js 9 | onNewVersion(/* version, lastVersion */) {}, 10 | onError(e) { 11 | if (!Ember.testing) { 12 | console.log(e); 13 | } 14 | ``` 15 | 16 | ### Unknown Global 17 | 18 | **Global**: `Ember.testing` 19 | 20 | **Location**: `addon/components/new-version-notifier/component.js` at line 63 21 | 22 | ```js 23 | } 24 | 25 | if (Ember.testing) { taskRunCounter = 0; } 26 | 27 | if (!Ember.testing || get(this, 'enableInTests')) { 28 | ``` 29 | 30 | ### Unknown Global 31 | 32 | **Global**: `Ember.testing` 33 | 34 | **Location**: `addon/components/new-version-notifier/component.js` at line 65 35 | 36 | ```js 37 | if (Ember.testing) { taskRunCounter = 0; } 38 | 39 | if (!Ember.testing || get(this, 'enableInTests')) { 40 | if (this.firstCheckInterval > 0) { 41 | later(this, () => { this.get('updateVersion').perform(); }, this.firstCheckInterval); 42 | ``` 43 | 44 | ### Unknown Global 45 | 46 | **Global**: `Ember.testing` 47 | 48 | **Location**: `addon/components/new-version-notifier/component.js` at line 76 49 | 50 | ```js 51 | updateIntervalWithTesting: computed('updateInterval', 'enableInTests', function() { 52 | let enableInTests = get(this, 'enableInTests'); 53 | return (!enableInTests && Ember.testing) ? 0 : get(this, 'updateInterval'); 54 | }), 55 | 56 | ``` 57 | 58 | ### Unknown Global 59 | 60 | **Global**: `Ember.testing` 61 | 62 | **Location**: `addon/components/new-version-notifier/component.js` at line 115 63 | 64 | ```js 65 | yield timeout(updateInterval); 66 | 67 | if (Ember.testing && ++taskRunCounter > MAX_COUNT_IN_TESTING) { return; } 68 | 69 | if (Ember.testing && !get(this, 'enableInTests')) { return; } 70 | ``` 71 | 72 | ### Unknown Global 73 | 74 | **Global**: `Ember.testing` 75 | 76 | **Location**: `addon/components/new-version-notifier/component.js` at line 117 77 | 78 | ```js 79 | if (Ember.testing && ++taskRunCounter > MAX_COUNT_IN_TESTING) { return; } 80 | 81 | if (Ember.testing && !get(this, 'enableInTests')) { return; } 82 | this.get('updateVersion').perform(); 83 | } 84 | ``` 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ember-cli-new-version 2 | 3 | A convention-based version update notifier. Use it to notify users already on the page that a new version has been deployed. 4 | 5 | ## Compatibility 6 | 7 | - Ember.js v3.20 or above 8 | - Ember CLI v3.20 or above 9 | - Node.js v20 or above (should still work with older versions) 10 | 11 | ## Usage 12 | 13 | 1. Add this add-on as you would any other: 14 | 15 | ```bash 16 | > ember install ember-cli-new-version 17 | ``` 18 | 19 | 2. Add a version file to your app, eg: 20 | _./public/VERSION.txt_ 21 | 22 | ```bash 23 | 1.0.0 24 | ``` 25 | 26 | 3. Include the component in your view: 27 | 28 | ```handlebars 29 | 30 | ``` 31 | 32 | **voila**! 33 | 34 | ## Configuration 35 | 36 | To setup, you should first configure the service through `config/environment`: 37 | 38 | ```javascript 39 | module.exports = function (environment) { 40 | var ENV = { 41 | newVersion: { 42 | currentVersion: null, 43 | versionFileName: 'VERSION.txt', 44 | updateInterval: 60000, 45 | firstCheckInterval: 0, 46 | enableInTests: false, 47 | enableInDev: false, 48 | maxCountInTesting: 10, 49 | }, 50 | }; 51 | }; 52 | ``` 53 | 54 | --- 55 | 56 | - `currentVersion` - The current version of the app if not using [Automatic VERSION file creation][#automatic version file creation] **default: null** 57 | - `versionFileName` - the name of the file on the server to check **default: /VERSION.txt** 58 | - `updateInterval` - the amount of time, in milliseconds, to wait between version checks **default: 60000** 59 | - `firstCheckInterval` - the amount of time, in milliseconds, to wait before the first version check is run after booting the application **default: 0** 60 | - `enableInTests` - Should the version checking run in test environments? **default: false** 61 | - `enableInDev` - Should the version checking run in the dev environments? **default: false** 62 | - `maxCountInTesting` - How many times to check for a new version in tests. **default: 10** 63 | 64 | ## Automatic Version File Creation 65 | 66 | If no `VERSION.txt` file exists it will be automatically generated during the build process 67 | with the value of `currentVersion` or the `version` from `package.json`. 68 | 69 | ### Supports `ember-cli-app-version` 70 | 71 | Since version 4.0.0 this addons will use the version string provided by [ember-cli-app-version](https://github.com/ember-cli/ember-cli-app-version) if no `currentVersion` is configured. 72 | 73 | All you have to do is install `ember-cli-app-version`. 74 | 75 | Then an update is triggered based on full version strings with build metadata such as `1.0.0-beta-2-e1dffe1`. 76 | 77 | ### Notifier Configuration and Interface 78 | 79 | --- 80 | 81 | - `updateMessage` - the message to show to users when update has been detected. There are two tokens allowed in this string: `{newVersion}` and `{oldVersion}` which will replaced with their respective values. 82 | eg. (and **default**). "This application has been updated from version {oldVersion} to {newVersion}. Please save any work, then refresh browser to see changes." 83 | - `showReload` - _true_ shows a reload button the user can click to refresh. _false_ hides the button. **default: true** 84 | - `reloadButtonText` - Sets the text for the default reload button. **default: "Reload"** 85 | 86 | ```handlebars 87 | 91 | ``` 92 | 93 | ### Custom Notification 94 | 95 | By default the notification is styled as a Bootstrap Alert. If you want custom layouts or 96 | to use a different framework, then you can define your own markup for the notification. 97 | 98 | ```hbs 99 | 100 |
101 | Reload to update to the new version ({{version}}) of this application 102 | 103 | 104 |
105 |
106 | ``` 107 | 108 | ## Contributing 109 | 110 | See the [Contributing](CONTRIBUTING.md) guide for details. 111 | 112 | ## License 113 | 114 | This project is licensed under the [MIT License](LICENSE.md). 115 | -------------------------------------------------------------------------------- /addon/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/addon/.gitkeep -------------------------------------------------------------------------------- /addon/components/new-version-notifier.hbs: -------------------------------------------------------------------------------- 1 | {{#if this.message}} 2 | {{#if (has-block)}} 3 | {{yield this.newVersion.latestVersion this.newVersion.currentVersion this.reload this.close}} 4 | {{else}} 5 |
6 | {{this.message}} 7 | {{#if this.showReload}} 8 | 9 | {{this.reloadButtonText}} 10 | 11 | {{/if}} 12 | 13 | × 14 | 15 |
16 | {{/if}} 17 | {{/if}} -------------------------------------------------------------------------------- /addon/components/new-version-notifier.js: -------------------------------------------------------------------------------- 1 | import Component from '@glimmer/component'; 2 | import { tracked } from '@glimmer/tracking'; 3 | import { inject as service } from '@ember/service'; 4 | import { action } from '@ember/object'; 5 | 6 | export default class NewVersionNotifier extends Component { 7 | /** @type {import("ember-cli-new-version/services/new-version").default} */ 8 | @service newVersion; 9 | 10 | @tracked updateMessage = 11 | this.args.updateMessage ?? 12 | 'This application has been updated from version {oldVersion} to {newVersion}. Please save any work, then refresh browser to see changes.'; 13 | @tracked showReload = this.args.showReload ?? true; 14 | @tracked reloadButtonText = this.args.reloadButtonText ?? 'Reload'; 15 | 16 | /** 17 | * @returns {string | undefined} 18 | */ 19 | get message() { 20 | if (this.newVersion.isNewVersionAvailable) { 21 | return this.updateMessage 22 | .replace('{oldVersion}', this.newVersion.currentVersion) 23 | .replace('{newVersion}', this.newVersion.latestVersion); 24 | } 25 | 26 | return undefined; 27 | } 28 | 29 | @action 30 | close(event) { 31 | event.preventDefault(); 32 | this.newVersion.ignoreVersion(this.newVersion.latestVersion); 33 | 34 | return false; 35 | } 36 | 37 | @action 38 | reload(event) { 39 | event.preventDefault(); 40 | if (typeof window !== 'undefined' && window.location) { 41 | window.location.reload(true); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /addon/services/new-version.js: -------------------------------------------------------------------------------- 1 | import { getOwner } from '@ember/application'; 2 | import { later } from '@ember/runloop'; 3 | import Service from '@ember/service'; 4 | import { waitFor } from '@ember/test-waiters'; 5 | import { tracked } from '@glimmer/tracking'; 6 | import Ember from 'ember'; 7 | import { task, timeout } from 'ember-concurrency'; 8 | import fetch from 'fetch'; 9 | 10 | let taskRunCounter = 0; 11 | const ONE_MINUTE = 60000; 12 | 13 | /** 14 | * @typedef {object} Configuration 15 | * @property {string} versionFileName 16 | * @property {number} firstCheckInterval 17 | * @property {number} updateInterval 18 | * @property {boolean} enableInTests 19 | * @property {boolean} enableInDev 20 | * @property {number} maxCountInTesting 21 | * @property {string} currentVersion 22 | */ 23 | 24 | export default class NewVersionService extends Service { 25 | get _fastboot() { 26 | let owner = getOwner(this); 27 | return owner.lookup('service:fastboot'); 28 | } 29 | 30 | get _config() { 31 | return getOwner(this).resolveRegistration('config:environment'); 32 | } 33 | 34 | get isDev() { 35 | return this._config.environment === 'development'; 36 | } 37 | 38 | /** 39 | * @type Configuration 40 | */ 41 | get _newVersionConfig() { 42 | return this._config.newVersion; 43 | } 44 | 45 | /** 46 | * @type {string} 47 | */ 48 | get currentVersion() { 49 | return this._newVersionConfig.currentVersion; 50 | } 51 | 52 | /** 53 | * @type {string | undefined} 54 | */ 55 | @tracked latestVersion = undefined; 56 | 57 | @tracked ignoredVersions = []; 58 | 59 | /** 60 | * Templates can use this attribute to show or hide a proposition to reload the page. 61 | * This getter can be overriden to change the update strategy. 62 | * 63 | * By default, a new version is considered available when there is a difference 64 | * between the local version and the remote version. 65 | * 66 | * @returns {boolean} true if a new version is available. 67 | */ 68 | get isNewVersionAvailable() { 69 | return ( 70 | !this.ignoredVersions.includes(this.latestVersion) && 71 | this.latestVersion && 72 | this.currentVersion != this.latestVersion 73 | ); 74 | } 75 | 76 | get url() { 77 | const versionFileName = this._newVersionConfig.versionFileName; 78 | const baseUrl = 79 | this._config.prepend || this._config.rootURL || this._config.baseURL; 80 | return baseUrl + versionFileName; 81 | } 82 | 83 | get updateIntervalWithTesting() { 84 | let enableInTests = this._newVersionConfig.enableInTests; 85 | return !enableInTests && Ember.testing 86 | ? 0 87 | : this._newVersionConfig.updateInterval; 88 | } 89 | 90 | constructor() { 91 | super(...arguments); 92 | 93 | if (this._fastboot?.isFastBoot) { 94 | return; 95 | } 96 | 97 | // TODO: move the testing logic to a test version of the service 98 | if (Ember.testing) { 99 | taskRunCounter = 0; 100 | } 101 | 102 | if ( 103 | (!Ember.testing || this._newVersionConfig.enableInTests) && 104 | (!this.isDev || this._newVersionConfig.enableInDev) 105 | ) { 106 | if (this._newVersionConfig.firstCheckInterval > 0) { 107 | later( 108 | this, 109 | () => { 110 | this.updateVersion.perform(); 111 | }, 112 | this._newVersionConfig.firstCheckInterval 113 | ); 114 | } else { 115 | this.updateVersion.perform(); 116 | } 117 | } 118 | } 119 | 120 | @task 121 | @waitFor 122 | *updateVersion() { 123 | const url = this.url; 124 | 125 | try { 126 | yield fetch(url + '?_=' + Date.now()) 127 | .then((response) => { 128 | if (!response.ok) throw new Error(response.statusText); 129 | return response.text(); 130 | }) 131 | .then((res) => { 132 | this.latestVersion = res ? res.trim() : undefined; 133 | 134 | // Call kept for compatibility with older version of the lib 135 | if (this.isNewVersionAvailable) { 136 | this.onNewVersion( 137 | this.latestVersion, 138 | this.ignoredVersions[this.ignoredVersions.length - 1] || 139 | this.currentVersion 140 | ); 141 | } 142 | }); 143 | } catch (e) { 144 | this.onError(e); 145 | } finally { 146 | let updateInterval = this.updateIntervalWithTesting; 147 | if (updateInterval === null || updateInterval === undefined) { 148 | updateInterval = ONE_MINUTE; 149 | } 150 | 151 | yield timeout(updateInterval); 152 | 153 | if ( 154 | Ember.testing && 155 | ++taskRunCounter > this._newVersionConfig.maxCountInTesting 156 | ) { 157 | return; 158 | } 159 | 160 | if (Ember.testing && !this._newVersionConfig.enableInTests) { 161 | return; 162 | } 163 | this.updateVersion.perform(); 164 | } 165 | } 166 | 167 | /** 168 | * Tells NewVersionService to ignore the given version. 169 | * If ignored, it won't trigger set `isNewVersionAvailable` to `true`. 170 | * The list of ignored is kept in memory only: if the site is reloaded, the list is empty. 171 | * @param {string} version 172 | */ 173 | ignoreVersion(version) { 174 | this.ignoredVersions = [...this.ignoredVersions, version]; 175 | } 176 | 177 | // eslint-disable-next-line no-unused-vars 178 | onNewVersion(newVersion, currentVersion) { 179 | // Kept for compatibility with older version of the lib 180 | } 181 | 182 | onError(error) { 183 | if (!Ember.testing) { 184 | console.log(error); 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /addon/styles/components/new-version-notifier.css: -------------------------------------------------------------------------------- 1 | .update-notification { 2 | position: fixed; 3 | z-index: 9999; 4 | top: 0; 5 | left: 0; 6 | right: 0; 7 | text-align: center; 8 | color: #8a6d3b; 9 | background-color: #fcf8e3; 10 | border-color: #faebcc; 11 | padding: 15px; 12 | border: 1px solid transparent; 13 | } 14 | 15 | .update-notification__btn { 16 | color: #333; 17 | background-color: #fff; 18 | border-color: #ccc; 19 | display: inline-block; 20 | padding: 6px 12px; 21 | margin-bottom: 0; 22 | font-size: 14px; 23 | font-weight: 400; 24 | line-height: 1.42857143; 25 | text-align: center; 26 | white-space: nowrap; 27 | vertical-align: middle; 28 | touch-action: manipulation; 29 | cursor: pointer; 30 | user-select: none; 31 | background-image: none; 32 | border: 1px solid transparent; 33 | border-radius: 4px; 34 | text-decoration: none; 35 | } 36 | 37 | .update-notification__close { 38 | margin-left: 5px; 39 | width: 20px; 40 | text-decoration: none; 41 | display: inline-block; 42 | } 43 | -------------------------------------------------------------------------------- /app/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/app/.gitkeep -------------------------------------------------------------------------------- /app/components/new-version-notifier.js: -------------------------------------------------------------------------------- 1 | export { default } from 'ember-cli-new-version/components/new-version-notifier'; 2 | -------------------------------------------------------------------------------- /app/services/new-version.js: -------------------------------------------------------------------------------- 1 | export { default } from 'ember-cli-new-version/services/new-version'; 2 | -------------------------------------------------------------------------------- /blueprints/ember-cli-new-version/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | normalizeEntityName() {}, // no-op since we're just adding dependencies 3 | 4 | afterInstall() { 5 | // Add addons to package.json and run defaultBlueprint 6 | return this.addAddonToProject('ember-fetch'); 7 | }, 8 | }; 9 | -------------------------------------------------------------------------------- /config/ember-try.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const getChannelURL = require('ember-source-channel-url'); 4 | const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup'); 5 | 6 | module.exports = async function () { 7 | return { 8 | scenarios: [ 9 | { 10 | name: 'ember-lts-3.20', 11 | npm: { 12 | devDependencies: { 13 | 'ember-source': '~3.20.5', 14 | }, 15 | }, 16 | }, 17 | { 18 | name: 'ember-lts-3.24', 19 | npm: { 20 | devDependencies: { 21 | 'ember-source': '~3.24.3', 22 | }, 23 | }, 24 | }, 25 | { 26 | name: 'ember-release', 27 | npm: { 28 | devDependencies: { 29 | 'ember-source': await getChannelURL('release'), 30 | }, 31 | }, 32 | }, 33 | { 34 | name: 'ember-beta', 35 | npm: { 36 | devDependencies: { 37 | 'ember-source': await getChannelURL('beta'), 38 | }, 39 | }, 40 | }, 41 | { 42 | name: 'ember-canary', 43 | npm: { 44 | devDependencies: { 45 | 'ember-source': await getChannelURL('canary'), 46 | }, 47 | }, 48 | }, 49 | { 50 | name: 'ember-default-with-jquery', 51 | env: { 52 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 53 | 'jquery-integration': true, 54 | }), 55 | }, 56 | npm: { 57 | devDependencies: { 58 | '@ember/jquery': '^1.1.0', 59 | }, 60 | }, 61 | }, 62 | { 63 | name: 'ember-classic', 64 | env: { 65 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 66 | 'application-template-wrapper': true, 67 | 'default-async-observers': false, 68 | 'template-only-glimmer-components': false, 69 | }), 70 | }, 71 | npm: { 72 | devDependencies: { 73 | 'ember-source': '~3.28.0', 74 | }, 75 | ember: { 76 | edition: 'classic', 77 | }, 78 | }, 79 | }, 80 | embroiderSafe(), 81 | embroiderOptimized(), 82 | ], 83 | }; 84 | }; 85 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | module.exports = function (/* environment, appConfig */) { 5 | return {}; 6 | }; 7 | -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 5 | 6 | module.exports = function (defaults) { 7 | let app = new EmberAddon(defaults, {}); 8 | 9 | /* 10 | This build file specifies the options for the dummy test app of this 11 | addon, located in `/tests/dummy` 12 | This build file does *not* influence how the addon or the app using it 13 | behave. You most likely want to be modifying `./index.js` or app's build file 14 | */ 15 | 16 | const { maybeEmbroider } = require('@embroider/test-setup'); 17 | return maybeEmbroider(app, { 18 | staticAddonTestSupportTrees: true, 19 | staticAddonTrees: true, 20 | staticHelpers: true, 21 | staticComponents: true, 22 | skipBabel: [ 23 | { 24 | package: 'qunit', 25 | }, 26 | ], 27 | }); 28 | }; 29 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | const writeFile = require('broccoli-file-creator'); 5 | 6 | module.exports = { 7 | name: require('./package').name, 8 | 9 | /** 10 | * Setup default configuration options and auto detect the currentVersion if it isn't set manually 11 | */ 12 | config(env, baseConfig) { 13 | const defaultConfiguration = { 14 | versionFileName: 'VERSION.txt', 15 | firstCheckInterval: 0, 16 | updateInterval: 60000, 17 | enableInTests: false, 18 | enableInDev: false, 19 | maxCountInTesting: 10, 20 | }; 21 | 22 | baseConfig.newVersion = Object.assign( 23 | defaultConfiguration, 24 | baseConfig.newVersion 25 | ); 26 | 27 | if (!baseConfig.newVersion.currentVersion) { 28 | if (baseConfig.APP.version) { 29 | //if `ember-cli-app-version` is installed use the detected version from that addon 30 | baseConfig.newVersion.currentVersion = baseConfig.APP.version; 31 | } else { 32 | //otherwise use what is in package.json. 33 | baseConfig.newVersion.currentVersion = this.parent.pkg.version; 34 | } 35 | } 36 | 37 | this._config = baseConfig.newVersion; 38 | 39 | return baseConfig; 40 | }, 41 | 42 | /** 43 | * Write version file 44 | */ 45 | treeForPublic() { 46 | const { currentVersion, versionFileName } = this._config; 47 | if (currentVersion) { 48 | this.ui.writeLine(`Created ${versionFileName} with ${currentVersion}`); 49 | return writeFile(versionFileName, currentVersion); 50 | } 51 | }, 52 | }; 53 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "experimentalDecorators": true, 4 | "checkJs": true, 5 | "target": "es2018", 6 | "moduleResolution": "node", 7 | "baseUrl": ".", 8 | "paths": { 9 | "ember-cli-new-version/*": [ 10 | "addon/*" 11 | ] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-cli-new-version", 3 | "version": "5.0.0", 4 | "description": "A convention based update notification for Ember. With this addon, you can detect a new version and notify the user to refresh the page", 5 | "scripts": { 6 | "build": "ember build --environment=production", 7 | "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix", 8 | "lint:hbs": "ember-template-lint .", 9 | "lint:hbs:fix": "ember-template-lint . --fix", 10 | "lint:js": "eslint . --cache", 11 | "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"", 12 | "lint:js:fix": "eslint . --fix", 13 | "start": "ember server", 14 | "test": "npm-run-all lint test:*", 15 | "test:ember": "ember test", 16 | "test:ember-compatibility": "ember try:each", 17 | "release": "standard-version" 18 | }, 19 | "engines": { 20 | "node": ">= 20" 21 | }, 22 | "devDependencies": { 23 | "@ember/optional-features": "^2.0.0", 24 | "@ember/test-helpers": "^2.4.2", 25 | "@ember/test-waiters": "^2.4.5", 26 | "@embroider/test-setup": "^1.5.0", 27 | "babel-eslint": "^10.1.0", 28 | "broccoli-asset-rev": "^3.0.0", 29 | "ember-cli": "~3.28.4", 30 | "ember-cli-dependency-checker": "^3.2.0", 31 | "ember-cli-inject-live-reload": "^2.1.0", 32 | "ember-cli-mirage": "^2.4.0", 33 | "ember-cli-sri": "^2.1.1", 34 | "ember-cli-terser": "^4.0.2", 35 | "ember-disable-prototype-extensions": "^1.1.3", 36 | "ember-export-application-global": "^2.0.1", 37 | "ember-load-initializers": "^2.1.2", 38 | "ember-maybe-import-regenerator": "^1.0.0", 39 | "ember-page-title": "^7.0.0", 40 | "ember-qunit": "^5.1.4", 41 | "ember-resolver": "^8.0.2", 42 | "ember-source": "~3.28.0", 43 | "ember-source-channel-url": "^3.0.0", 44 | "ember-template-lint": "^3.6.0", 45 | "ember-try": "^1.4.0", 46 | "eslint": "^7.32.0", 47 | "eslint-config-prettier": "^8.3.0", 48 | "eslint-plugin-ember": "^10.5.4", 49 | "eslint-plugin-node": "^11.1.0", 50 | "eslint-plugin-prettier": "^3.4.1", 51 | "eslint-plugin-qunit": "^6.2.0", 52 | "loader.js": "^4.7.0", 53 | "npm-run-all": "^4.1.5", 54 | "prettier": "^2.3.2", 55 | "qunit": "^2.16.0", 56 | "qunit-dom": "^1.6.0", 57 | "standard-version": "^9.3.0", 58 | "webpack": "^5.70.0" 59 | }, 60 | "keywords": [ 61 | "ember-addon", 62 | "version", 63 | "update", 64 | "alert", 65 | "new version" 66 | ], 67 | "repository": { 68 | "type": "git", 69 | "url": "https://github.com/sethwebster/ember-cli-new-version.git" 70 | }, 71 | "license": "MIT", 72 | "author": "", 73 | "directories": { 74 | "doc": "doc", 75 | "test": "tests" 76 | }, 77 | "dependencies": { 78 | "@glimmer/component": "^1.0.4", 79 | "@glimmer/tracking": "^1.0.4", 80 | "broccoli-file-creator": "^2.1.1", 81 | "ember-auto-import": "^2.4.1", 82 | "ember-cli-babel": "^7.26.6", 83 | "ember-cli-htmlbars": "^5.7.1", 84 | "ember-concurrency": "^2.0.3", 85 | "ember-fetch": "^8.0.4" 86 | }, 87 | "ember": { 88 | "edition": "octane" 89 | }, 90 | "ember-addon": { 91 | "configPath": "tests/dummy/config" 92 | }, 93 | "volta": { 94 | "node": "20.18.0" 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | test_page: 'tests/index.html?hidepassed', 5 | disable_watching: true, 6 | launch_in_ci: ['Chrome'], 7 | launch_in_dev: ['Chrome'], 8 | browser_start_timeout: 120, 9 | browser_args: { 10 | Chrome: { 11 | ci: [ 12 | // --no-sandbox is needed when running Chrome inside a container 13 | process.env.CI ? '--no-sandbox' : null, 14 | '--headless', 15 | '--disable-dev-shm-usage', 16 | '--disable-software-rasterizer', 17 | '--mute-audio', 18 | '--remote-debugging-port=0', 19 | '--window-size=1440,900', 20 | ].filter(Boolean), 21 | }, 22 | }, 23 | }; 24 | -------------------------------------------------------------------------------- /tests/acceptance/index-test.js: -------------------------------------------------------------------------------- 1 | import { currentURL, visit } from '@ember/test-helpers'; 2 | import { module, test } from 'qunit'; 3 | import { setupApplicationTest } from 'ember-qunit'; 4 | import { setupMirage } from 'ember-cli-mirage/test-support'; 5 | 6 | module('Acceptance | index', function (hooks) { 7 | setupApplicationTest(hooks); 8 | setupMirage(hooks); 9 | 10 | test('visiting /', async function (assert) { 11 | this.server.get('/VERSION.txt', function () { 12 | return 'v1.0.3'; 13 | }); 14 | 15 | await visit('/'); 16 | 17 | assert.equal(currentURL(), '/'); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Application from '@ember/application'; 2 | import Resolver from 'ember-resolver'; 3 | import loadInitializers from 'ember-load-initializers'; 4 | import config from 'dummy/config/environment'; 5 | 6 | export default class App extends Application { 7 | modulePrefix = config.modulePrefix; 8 | podModulePrefix = config.podModulePrefix; 9 | Resolver = Resolver; 10 | } 11 | 12 | loadInitializers(App, config.modulePrefix); 13 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/tests/dummy/app/controllers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | 12 | 13 | 14 | 15 | {{content-for "head-footer"}} 16 | 17 | 18 | {{content-for "body"}} 19 | 20 | 21 | 22 | 23 | {{content-for "body-footer"}} 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/tests/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/router.js: -------------------------------------------------------------------------------- 1 | import EmberRouter from '@ember/routing/router'; 2 | import config from 'dummy/config/environment'; 3 | 4 | export default class Router extends EmberRouter { 5 | location = config.locationType; 6 | rootURL = config.rootURL; 7 | } 8 | 9 | Router.map(function () {}); 10 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/tests/dummy/app/routes/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/tests/dummy/app/styles/app.css -------------------------------------------------------------------------------- /tests/dummy/app/templates/application.hbs: -------------------------------------------------------------------------------- 1 | {{page-title 'Ember New Version'}} 2 | 3 |

4 | Ember New Version 5 |

6 | 7 | {{outlet}} 8 | 9 | -------------------------------------------------------------------------------- /tests/dummy/config/ember-cli-update.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": "1.0.0", 3 | "packages": [ 4 | { 5 | "name": "ember-cli", 6 | "version": "3.28.4", 7 | "blueprints": [ 8 | { 9 | "name": "addon", 10 | "outputRepo": "https://github.com/ember-cli/ember-addon-output", 11 | "codemodsSource": "ember-addon-codemods-manifest@1", 12 | "isBaseBlueprint": true, 13 | "options": [ 14 | "--no-welcome" 15 | ] 16 | } 17 | ] 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | module.exports = function (environment) { 5 | let ENV = { 6 | modulePrefix: 'dummy', 7 | environment, 8 | rootURL: '/', 9 | locationType: 'auto', 10 | EmberENV: { 11 | FEATURES: { 12 | // Here you can enable experimental features on an ember canary build 13 | // e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true 14 | }, 15 | EXTEND_PROTOTYPES: { 16 | // Prevent Ember Data from overriding Date.parse. 17 | Date: false, 18 | }, 19 | }, 20 | 21 | APP: { 22 | // Here you can pass flags/options to your application instance 23 | // when it is created 24 | }, 25 | 26 | 'ember-cli-mirage': { 27 | enabled: false, 28 | }, 29 | }; 30 | 31 | if (environment === 'development') { 32 | // ENV.APP.LOG_RESOLVER = true; 33 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 34 | // ENV.APP.LOG_TRANSITIONS = true; 35 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 36 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 37 | } 38 | 39 | if (environment === 'test') { 40 | // Testem prefers this... 41 | ENV['ember-cli-mirage'].enabled = true; 42 | 43 | ENV.locationType = 'none'; 44 | 45 | // keep test console output quieter 46 | ENV.APP.LOG_ACTIVE_GENERATION = false; 47 | ENV.APP.LOG_VIEW_LOOKUPS = false; 48 | 49 | ENV.APP.rootElement = '#ember-testing'; 50 | ENV.APP.autoboot = false; 51 | } 52 | 53 | if (environment === 'production') { 54 | // here you can enable a production-specific feature 55 | } 56 | 57 | return ENV; 58 | }; 59 | -------------------------------------------------------------------------------- /tests/dummy/config/optional-features.json: -------------------------------------------------------------------------------- 1 | { 2 | "application-template-wrapper": false, 3 | "default-async-observers": true, 4 | "jquery-integration": false, 5 | "template-only-glimmer-components": true 6 | } 7 | -------------------------------------------------------------------------------- /tests/dummy/config/targets.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const browsers = [ 4 | 'last 1 Chrome versions', 5 | 'last 1 Firefox versions', 6 | 'last 1 Safari versions', 7 | ]; 8 | 9 | // Ember's browser support policy is changing, and IE11 support will end in 10 | // v4.0 onwards. 11 | // 12 | // See https://deprecations.emberjs.com/v3.x#toc_3-0-browser-support-policy 13 | // 14 | // If you need IE11 support on a version of Ember that still offers support 15 | // for it, uncomment the code block below. 16 | // 17 | // const isCI = Boolean(process.env.CI); 18 | // const isProduction = process.env.EMBER_ENV === 'production'; 19 | // 20 | // if (isCI || isProduction) { 21 | // browsers.push('ie 11'); 22 | // } 23 | 24 | module.exports = { 25 | browsers, 26 | }; 27 | -------------------------------------------------------------------------------- /tests/dummy/mirage/config.js: -------------------------------------------------------------------------------- 1 | export default function () { 2 | // These comments are here to help you get started. Feel free to delete them. 3 | /* 4 | Config (with defaults). 5 | 6 | Note: these only affect routes defined *after* them! 7 | */ 8 | // this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server 9 | // this.namespace = ''; // make this `/api`, for example, if your API is namespaced 10 | // this.timing = 400; // delay for each request, automatically set to 0 during testing 11 | /* 12 | Shorthand cheatsheet: 13 | 14 | this.get('/posts'); 15 | this.post('/posts'); 16 | this.get('/posts/:id'); 17 | this.put('/posts/:id'); // or this.patch 18 | this.del('/posts/:id'); 19 | 20 | http://www.ember-cli-mirage.com/docs/v0.3.x/shorthands/ 21 | */ 22 | } 23 | -------------------------------------------------------------------------------- /tests/dummy/mirage/scenarios/default.js: -------------------------------------------------------------------------------- 1 | export default function (/* server */) { 2 | /* 3 | Seed your development database using your factories. 4 | This data will not be loaded in your tests. 5 | 6 | Make sure to define a factory for each model you want to create. 7 | */ 8 | // server.createList('post', 10); 9 | } 10 | -------------------------------------------------------------------------------- /tests/dummy/mirage/serializers/application.js: -------------------------------------------------------------------------------- 1 | import { JSONAPISerializer } from 'ember-cli-mirage'; 2 | 3 | export default JSONAPISerializer.extend({}); 4 | -------------------------------------------------------------------------------- /tests/dummy/public/VERSION.txt: -------------------------------------------------------------------------------- 1 | 1.0.5 2 | -------------------------------------------------------------------------------- /tests/dummy/public/crossdomain.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /tests/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/tests/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy Tests 7 | 8 | 9 | 10 | {{content-for "head"}} {{content-for "test-head"}} 11 | 12 | 13 | 14 | 15 | 16 | {{content-for "head-footer"}} {{content-for "test-head-footer"}} 17 | 18 | 19 | {{content-for "body"}} {{content-for "test-body"}} 20 | 21 |
22 |
23 |
24 |
25 |
26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | {{content-for "body-footer"}} {{content-for "test-body-footer"}} 35 | 36 | 37 | -------------------------------------------------------------------------------- /tests/integration/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/tests/integration/.gitkeep -------------------------------------------------------------------------------- /tests/integration/components/new-version-notifier-test.js: -------------------------------------------------------------------------------- 1 | import { render, waitUntil } from '@ember/test-helpers'; 2 | import NewVersionService from 'ember-cli-new-version/services/new-version'; 3 | import { setupRenderingTest } from 'ember-qunit'; 4 | import hbs from 'htmlbars-inline-precompile'; 5 | import { module, test } from 'qunit'; 6 | import { setupMirage } from 'ember-cli-mirage/test-support'; 7 | 8 | class TestNewVersionService extends NewVersionService { 9 | get _newVersionConfig() { 10 | const config = super._newVersionConfig; 11 | config.enableInTests = true; 12 | config.updateInterval = 100; 13 | config.currentVersion = 'v1.0.1'; 14 | return config; 15 | } 16 | } 17 | 18 | module('Integration | Component | new version notifier', function (hooks) { 19 | setupRenderingTest(hooks); 20 | setupMirage(hooks); 21 | 22 | hooks.beforeEach(function () { 23 | this.owner.register('service:new-version', TestNewVersionService); 24 | }); 25 | 26 | test('it shows when a new version is available', async function (assert) { 27 | let called = false; 28 | 29 | this.server.get('/VERSION.txt', function () { 30 | setTimeout(() => { 31 | called = true; 32 | }, 20); 33 | return 'v1.0.2'; 34 | }); 35 | 36 | render(hbs``); 37 | 38 | await waitUntil(() => called, { timeout: 50 }); 39 | 40 | assert 41 | .dom('.update-notification') 42 | .containsText( 43 | 'This application has been updated from version v1.0.1 to v1.0.2. Please save any work, then refresh browser to see changes.' 44 | ); 45 | }); 46 | 47 | test('it yields the current and last version to the block', async function (assert) { 48 | assert.expect(9); 49 | 50 | let called = false; 51 | let callCount = 0; 52 | 53 | this.server.get('/VERSION.txt', function () { 54 | setTimeout(() => { 55 | called = true; 56 | }, 20); // dirty workaround, because fetch sometimes returns after waitUntil if this is set to 0 57 | ++callCount; 58 | 59 | return callCount < 4 ? 'v1.0.' + callCount : 'v1.0.3'; 60 | }); 61 | 62 | render(hbs` 63 | 64 |
{{version}}
65 |
{{lastVersion}}
66 |
67 | `); 68 | 69 | await waitUntil(() => called, { timeout: 50 }); 70 | 71 | assert.equal(callCount, 1, '1 call was made'); 72 | assert 73 | .dom('#version-value') 74 | .doesNotExist('no version displayed when no upgrade available'); 75 | assert 76 | .dom('#last-version-value') 77 | .doesNotExist('no last version displayed when no upgrade available'); 78 | called = false; 79 | 80 | await waitUntil(() => called, { timeout: 150 }); 81 | 82 | assert.equal(callCount, 2); 83 | assert.dom('#version-value').hasText('v1.0.2'); 84 | assert.dom('#last-version-value').hasText('v1.0.1'); 85 | called = false; 86 | 87 | await waitUntil(() => called, { timeout: 250 }); 88 | assert.equal(callCount, 3); 89 | assert.dom('#version-value').hasText('v1.0.3'); 90 | assert.dom('#last-version-value').hasText('v1.0.1'); 91 | }); 92 | }); 93 | -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import Application from 'dummy/app'; 2 | import config from 'dummy/config/environment'; 3 | import * as QUnit from 'qunit'; 4 | import { setApplication } from '@ember/test-helpers'; 5 | import { setup } from 'qunit-dom'; 6 | import { start } from 'ember-qunit'; 7 | 8 | setApplication(Application.create(config.APP)); 9 | 10 | setup(QUnit.assert); 11 | 12 | start(); 13 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/tests/unit/.gitkeep -------------------------------------------------------------------------------- /tests/unit/services/new-version-test.js: -------------------------------------------------------------------------------- 1 | import { waitUntil } from '@ember/test-helpers'; 2 | import Mirage from 'ember-cli-mirage'; 3 | import NewVersionService from 'ember-cli-new-version/services/new-version'; 4 | import { setupTest } from 'ember-qunit'; 5 | import { module, test } from 'qunit'; 6 | import { setupMirage } from 'ember-cli-mirage/test-support'; 7 | 8 | class TestNewVersionService extends NewVersionService { 9 | get _newVersionConfig() { 10 | const config = super._newVersionConfig; 11 | config.enableInTests = true; 12 | config.updateInterval = 100; 13 | config.currentVersion = 'v1.0.1'; 14 | return config; 15 | } 16 | } 17 | 18 | module('Unit | Service | new-version', function (hooks) { 19 | setupTest(hooks); 20 | setupMirage(hooks); 21 | 22 | test('one version', async function (assert) { 23 | assert.expect(1); 24 | 25 | let callCount = 0; 26 | 27 | this.server.get('/VERSION.txt', function () { 28 | ++callCount; 29 | return 'v1.0.3'; 30 | }); 31 | 32 | this.owner.register( 33 | 'service:new-version', 34 | class extends TestNewVersionService { 35 | onNewVersion(newVersion, oldVersion) { 36 | throw `unexpected call to onNewVersion with ${newVersion}, ${oldVersion}`; 37 | } 38 | } 39 | ); 40 | 41 | this.owner.lookup('service:new-version'); 42 | 43 | await waitUntil(() => callCount === 4, { timeout: 490 }); 44 | assert.equal(callCount, 4); 45 | }); 46 | 47 | test('it calls onNewVersion when a new version is detected', async function (assert) { 48 | assert.expect(22); 49 | 50 | let callCount = 0; 51 | 52 | this.server.get('/VERSION.txt', function () { 53 | callCount++; 54 | return `v1.0.${callCount}`; 55 | }); 56 | 57 | this.owner.register( 58 | 'service:new-version', 59 | class extends TestNewVersionService { 60 | onNewVersion(newVersion, oldVersion) { 61 | assert.equal( 62 | newVersion, 63 | `v1.0.${callCount}`, 64 | `newVersion v1.0.${callCount} is sent to onNewVersion` 65 | ); 66 | assert.equal( 67 | oldVersion, 68 | 'v1.0.1', 69 | 'oldVersion v1.0.1 is sent to onNewVersion' 70 | ); 71 | } 72 | } 73 | ); 74 | 75 | this.owner.lookup('service:new-version'); 76 | 77 | await waitUntil(() => callCount === 1, { timeout: 95 }); 78 | assert.equal(callCount, 1, '1 call was made'); 79 | 80 | await waitUntil(() => callCount === 2, { timeout: 190 }); 81 | assert.equal(callCount, 2); 82 | }); 83 | 84 | test('it calls onError when request fails', async function (assert) { 85 | assert.expect(1); 86 | 87 | let called = false; 88 | 89 | this.server.get('/VERSION.txt', function () { 90 | setTimeout(() => { 91 | called = true; 92 | }, 100); 93 | return new Mirage.Response(500, {}, { message: '' }); 94 | }); 95 | 96 | let onErrorCalled = false; 97 | 98 | this.owner.register( 99 | 'service:new-version', 100 | class extends TestNewVersionService { 101 | onError() { 102 | onErrorCalled = true; 103 | } 104 | } 105 | ); 106 | 107 | this.owner.lookup('service:new-version'); 108 | 109 | await waitUntil(() => called, { timeout: 150 }); 110 | assert.ok(onErrorCalled, 'onError was called'); 111 | }); 112 | 113 | test('repeat on bad response', async function (assert) { 114 | assert.expect(1); 115 | 116 | let callCount = 0; 117 | 118 | this.server.get('/VERSION.txt', function () { 119 | ++callCount; 120 | 121 | if (callCount === 1) { 122 | return new Mirage.Response(500, {}, { message: '' }); 123 | } 124 | 125 | return 'v1.0.3'; 126 | }); 127 | 128 | this.owner.register( 129 | 'service:new-version', 130 | class extends TestNewVersionService { 131 | onNewVersion(newVersion, oldVersion) { 132 | throw `unexpected call to onNewVersion with ${newVersion}, ${oldVersion}`; 133 | } 134 | } 135 | ); 136 | 137 | this.owner.lookup('service:new-version'); 138 | 139 | await waitUntil(() => callCount === 4, { timeout: 490 }); 140 | assert.equal(callCount, 4); 141 | }); 142 | }); 143 | -------------------------------------------------------------------------------- /vendor/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethwebster/ember-cli-new-version/984af20dc216106687a42b38ec4c3de16fb33c08/vendor/.gitkeep --------------------------------------------------------------------------------