Skip to content

Commit

Permalink
Merge pull request #1984 from ember-learn/fix-version-links-processing
Browse files Browse the repository at this point in the history
Fix version links processing
  • Loading branch information
jaredgalanis authored Dec 15, 2023
2 parents 97b0981 + d4cefa4 commit 2d07d2b
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 88 deletions.
106 changes: 106 additions & 0 deletions node-tests/replace-url-versions.js
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/');
});
});
68 changes: 61 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"babel-eslint": "^10.1.0",
"broccoli-asset-rev": "^3.0.0",
"chai": "^4.3.4",
"commander": "^11.1.0",
"compare-versions": "^6.0.0-rc.2",
"ember-auto-import": "^2.6.1",
"ember-cli": "~4.0.1",
Expand Down
37 changes: 37 additions & 0 deletions scripts/helpers/replace-url-versions.js
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;
};
Loading

0 comments on commit 2d07d2b

Please sign in to comment.