-
-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1984 from ember-learn/fix-version-links-processing
Fix version links processing
- Loading branch information
Showing
5 changed files
with
224 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
const { expect } = require('chai'); | ||
const replaceURLVersions = require('../scripts/helpers/replace-url-versions'); | ||
|
||
describe('replace url versions', function () { | ||
it('works', function () { | ||
expect( | ||
replaceURLVersions( | ||
'https://api.emberjs.com/ember/release/', | ||
'3.15', | ||
'3.15' | ||
) | ||
).to.equal('https://api.emberjs.com/ember/3.15/'); | ||
expect( | ||
replaceURLVersions( | ||
'https://api.emberjs.com/ember/release', | ||
'3.15', | ||
'3.15' | ||
) | ||
).to.equal('https://api.emberjs.com/ember/3.15'); | ||
expect( | ||
replaceURLVersions('https://api.emberjs.com/ember/3.20/', '3.15', '3.15') | ||
).to.equal('https://api.emberjs.com/ember/3.15/'); | ||
expect( | ||
replaceURLVersions('https://api.emberjs.com/ember/3.20', '3.15', '3.15') | ||
).to.equal('https://api.emberjs.com/ember/3.15'); | ||
expect( | ||
replaceURLVersions( | ||
'https://api.emberjs.com/ember/release/classes/Application', | ||
'3.15', | ||
'3.15' | ||
) | ||
).to.equal('https://api.emberjs.com/ember/3.15/classes/Application'); | ||
expect( | ||
replaceURLVersions( | ||
'https://api.emberjs.com/ember-data/release/', | ||
'3.15', | ||
'3.15' | ||
) | ||
).to.equal('https://api.emberjs.com/ember-data/3.15/'); | ||
expect( | ||
replaceURLVersions( | ||
'https://api.emberjs.com/ember-data/release', | ||
'3.15', | ||
'3.15' | ||
) | ||
).to.equal('https://api.emberjs.com/ember-data/3.15'); | ||
expect( | ||
replaceURLVersions( | ||
'https://api.emberjs.com/ember-data/release', | ||
'3.15', | ||
'3.12' | ||
) | ||
).to.equal('https://api.emberjs.com/ember-data/3.12'); | ||
expect( | ||
replaceURLVersions( | ||
'https://api.emberjs.com/ember/release', | ||
'3.15', | ||
'3.12' | ||
) | ||
).to.equal('https://api.emberjs.com/ember/3.15'); | ||
expect( | ||
replaceURLVersions( | ||
'https://api.emberjs.com/ember-data/release/classes/Model/', | ||
'3.15', | ||
'3.15' | ||
) | ||
).to.equal('https://api.emberjs.com/ember-data/3.15/classes/Model/'); | ||
expect( | ||
replaceURLVersions( | ||
'https://api.emberjs.com/ember-data/3.20/classes/Model/', | ||
'3.15', | ||
'3.15' | ||
) | ||
).to.equal('https://api.emberjs.com/ember-data/3.15/classes/Model/'); | ||
expect( | ||
replaceURLVersions( | ||
'https://api.emberjs.com/ember-data/3.20/classes/Model/', | ||
'3.15', | ||
'3.12' | ||
) | ||
).to.equal('https://api.emberjs.com/ember-data/3.12/classes/Model/'); | ||
expect( | ||
replaceURLVersions( | ||
'https://api.emberjs.com/ember/release/classes/@ember%2Fapplication/methods/getOwner', | ||
'3.15', | ||
'3.15' | ||
) | ||
).to.equal( | ||
'https://api.emberjs.com/ember/3.15/classes/@ember%2Fapplication/methods/getOwner' | ||
); | ||
expect( | ||
replaceURLVersions( | ||
'https://guides.emberjs.com/release/getting-started/', | ||
'3.15', | ||
'3.15' | ||
) | ||
).to.equal('https://guides.emberjs.com/v3.15.0/getting-started/'); | ||
expect( | ||
replaceURLVersions( | ||
'https://guides.emberjs.com/release/getting-started/', | ||
'3.16.0', | ||
'3.16.0' | ||
) | ||
).to.equal('https://guides.emberjs.com/v3.16.0/getting-started/'); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module.exports = function replaceURLVersions( | ||
str, | ||
emberVersion, | ||
emberDataVersion | ||
) { | ||
let output; | ||
|
||
// guides use `v3.20.0` version format | ||
const emberPatchVersion = /\d+\.\d+.\d+/.test(emberVersion) | ||
? emberVersion | ||
: emberVersion + '.0'; | ||
output = str.replace( | ||
/https:\/\/guides.emberjs.com\/(release|v\d+\.\d+.\d+)(\/?)/g, | ||
`https://guides.emberjs.com/v${emberPatchVersion}$2` | ||
); | ||
|
||
const emberDataPatchVersion = /\d+\.\d+.\d+/.test(emberDataVersion) | ||
? emberDataVersion | ||
: emberDataVersion + '.0'; | ||
output = str.replace( | ||
/https:\/\/guides.emberjs.com\/(release|v\d+\.\d+.\d+)(\/?)/g, | ||
`https://guides.emberjs.com/v${emberDataPatchVersion}$2` | ||
); | ||
|
||
// apis use `3.20` version format | ||
output = output.replace( | ||
/https:\/\/api.emberjs.com\/(ember)\/(release|\d+\.\d+)(\/?)/g, | ||
`https://api.emberjs.com/$1/${emberVersion}$3` | ||
); | ||
|
||
output = output.replace( | ||
/https:\/\/api.emberjs.com\/(ember-data)\/(release|\d+\.\d+)(\/?)/g, | ||
`https://api.emberjs.com/$1/${emberDataVersion}$3` | ||
); | ||
|
||
return output; | ||
}; |
Oops, something went wrong.