From 5f80fc9f3f5a3c207c9a987c792777cd7d4136b6 Mon Sep 17 00:00:00 2001 From: Jen Weber Date: Fri, 5 Aug 2022 08:58:27 -0400 Subject: [PATCH 01/14] Notes and placeholder for prember --- app/router.js | 35 +++++++++++++++++++++++++++++++++++ ember-cli-build.js | 3 +++ 2 files changed, 38 insertions(+) diff --git a/app/router.js b/app/router.js index 81350a3b..8edfb5dc 100644 --- a/app/router.js +++ b/app/router.js @@ -92,4 +92,39 @@ AppRouter.map(function () { this.route('data-module', { path: '/data/modules/:module' }); }); +/* +404 +ember-cli +project + +/:project/:project_version + /classes/:class + /methods, /properties, /events + /functions/:module (no sub routes) + /namespaces/:namespace + /methods, /properties, /events + /modules/:module + /methods, /properties, /events + +SUB ROUTES + +Instead of https://api.emberjs.com/ember/4.6/classes/Engine/methods/unregister?anchor=unregister +We can do https://api.emberjs.com/ember/4.6/classes/Engine/methods?anchor=unregister + + /methods/:method + /properties/:property + /events/:event + +OTHER STATES +private, deprecated, inherited, protected +inherited is not reflected in URL state but it's checked by default + +MAYBE REDIRECTS + +/data/modules/:module +/data/classes/:class +/modules/:module +/classes/:class +*/ + export default AppRouter; diff --git a/ember-cli-build.js b/ember-cli-build.js index 280943f4..af1b8d82 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -7,6 +7,9 @@ const envIsProduction = process.env.EMBER_ENV === 'production'; module.exports = function (defaults) { let app = new EmberApp(defaults, { + prember: { + urls: [] // fill this in! + }, fingerprint: { extensions: [ 'js', From a8ef8d08fce393af76fe7e83a613eeb80f6b911f Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Fri, 16 Sep 2022 13:30:16 +0100 Subject: [PATCH 02/14] making it use local data --- .gitignore | 2 ++ app/adapters/application.js | 6 +++--- ember-cli-build.js | 7 ++++++- package.json | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4a8e5ae0..982c7aca 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,5 @@ local.log /.node_modules.ember-try/ /bower.json.ember-try /package.json.ember-try + +/ember-api-docs-data/ diff --git a/app/adapters/application.js b/app/adapters/application.js index 684c900f..cb338e22 100644 --- a/app/adapters/application.js +++ b/app/adapters/application.js @@ -6,7 +6,7 @@ import { pluralize } from 'ember-inflector'; import { isBlank } from '@ember/utils'; export default class Application extends JSONAPIAdapter { - host = ENV.API_HOST; + // host = ENV.API_HOST; currentProject = ''; currentProjectVersion = ''; @@ -47,7 +47,7 @@ export default class Application extends JSONAPIAdapter { async findRecord(store, { modelName }, id) { let url; - let host = this.host; + // let host = this.host; let projectName = this.currentProject; if (['namespace', 'class', 'module'].indexOf(modelName) > -1) { @@ -85,7 +85,7 @@ export default class Application extends JSONAPIAdapter { throw new Error('Unexpected model lookup'); } - url = `${host}/${url}.json`; + url = `/${url}.json`; let response = await fetch(url); let json = await response.json(); diff --git a/ember-cli-build.js b/ember-cli-build.js index af1b8d82..f7922f3c 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -66,5 +66,10 @@ module.exports = function (defaults) { include: ['mappings.json'], destDir: '/assets/', }); - return mergeTrees([app.toTree(), mappingsTree]); + + let docsJsonTree = new Funnel('ember-api-docs-data', { + include: ['**/json-docs/**', '**/rev-index/**'], + }); + + return mergeTrees([app.toTree(), mappingsTree, docsJsonTree]); }; diff --git a/package.json b/package.json index 2806adc7..7af55a19 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "test": "tests" }, "scripts": { + "clone": "rm -rf ember-api-docs-data && git clone https://github.com/ember-learn/ember-api-docs-data.git", "build": "ember build --environment=production", "lint": "npm-run-all --aggregate-output --continue-on-error --parallel 'lint:!(fix)'", "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix", From 641fe8ab3817d0324b4c857428019bed2d9f05dc Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Fri, 16 Sep 2022 14:00:48 +0100 Subject: [PATCH 03/14] add prember --- package-lock.json | 185 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 186 insertions(+) diff --git a/package-lock.json b/package-lock.json index 74df2866..794972d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -108,6 +108,7 @@ "minimist": "^1.2.6", "normalize.css": "^8.0.1", "npm-run-all": "^4.1.5", + "prember": "^1.1.1", "prettier": "^2.2.1", "qunit": "^2.16.0", "qunit-dom": "^1.6.0", @@ -11859,6 +11860,12 @@ "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==", "dev": true }, + "node_modules/denodeify": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/denodeify/-/denodeify-1.2.1.tgz", + "integrity": "sha512-KNTihKNmQENUZeKu5fzfpzRqR5S2VMp4gl9RFHiWzj9DfvYQPMJ6XHKNaQxaGCXwPk6y9yme3aUoaiAe+KX+vg==", + "dev": true + }, "node_modules/depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -33117,6 +33124,100 @@ "node": ">= 0.8.0" } }, + "node_modules/prember": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/prember/-/prember-1.1.1.tgz", + "integrity": "sha512-7lG4eNDKp0Udh2PCxibxMSkDFhscD0FGNGwASk5wUhHayz0R12AZqMxcbveDEMHI9smhYoymiFEdT5A3W7vIpw==", + "dev": true, + "dependencies": { + "broccoli-debug": "^0.6.3", + "broccoli-merge-trees": "^2.0.0", + "broccoli-plugin": "^1.3.0", + "chalk": "^2.3.0", + "denodeify": "^1.2.1", + "ember-cli-babel": "^7.26.6", + "express": "^4.16.2", + "fastboot": "^3.1.2", + "mkdirp": "^0.5.1" + }, + "engines": { + "node": "12.* || 14.* || >= 16" + } + }, + "node_modules/prember/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/prember/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/prember/node_modules/color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/prember/node_modules/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "dev": true + }, + "node_modules/prember/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/prember/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dev": true, + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, + "node_modules/prember/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/prettier": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.2.tgz", @@ -48621,6 +48722,12 @@ "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==", "dev": true }, + "denodeify": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/denodeify/-/denodeify-1.2.1.tgz", + "integrity": "sha512-KNTihKNmQENUZeKu5fzfpzRqR5S2VMp4gl9RFHiWzj9DfvYQPMJ6XHKNaQxaGCXwPk6y9yme3aUoaiAe+KX+vg==", + "dev": true + }, "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -65943,6 +66050,84 @@ "integrity": "sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==", "dev": true }, + "prember": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/prember/-/prember-1.1.1.tgz", + "integrity": "sha512-7lG4eNDKp0Udh2PCxibxMSkDFhscD0FGNGwASk5wUhHayz0R12AZqMxcbveDEMHI9smhYoymiFEdT5A3W7vIpw==", + "dev": true, + "requires": { + "broccoli-debug": "^0.6.3", + "broccoli-merge-trees": "^2.0.0", + "broccoli-plugin": "^1.3.0", + "chalk": "^2.3.0", + "denodeify": "^1.2.1", + "ember-cli-babel": "^7.26.6", + "express": "^4.16.2", + "fastboot": "^3.1.2", + "mkdirp": "^0.5.1" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "dev": true + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true + }, + "mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dev": true, + "requires": { + "minimist": "^1.2.6" + } + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, "prettier": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.2.tgz", diff --git a/package.json b/package.json index 7af55a19..c9de0be1 100644 --- a/package.json +++ b/package.json @@ -126,6 +126,7 @@ "minimist": "^1.2.6", "normalize.css": "^8.0.1", "npm-run-all": "^4.1.5", + "prember": "^1.1.1", "prettier": "^2.2.1", "qunit": "^2.16.0", "qunit-dom": "^1.6.0", From 6096619f9e67ec0f036a4f09732239a218674b92 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Fri, 16 Sep 2022 14:01:18 +0100 Subject: [PATCH 04/14] move json data to in-repo-addon for prember --- ember-cli-build.js | 6 +----- lib/api-docs-data/index.js | 17 +++++++++++++++++ lib/api-docs-data/package.json | 9 +++++++++ package.json | 5 +++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 lib/api-docs-data/index.js create mode 100644 lib/api-docs-data/package.json diff --git a/ember-cli-build.js b/ember-cli-build.js index f7922f3c..79929968 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -67,9 +67,5 @@ module.exports = function (defaults) { destDir: '/assets/', }); - let docsJsonTree = new Funnel('ember-api-docs-data', { - include: ['**/json-docs/**', '**/rev-index/**'], - }); - - return mergeTrees([app.toTree(), mappingsTree, docsJsonTree]); + return mergeTrees([app.toTree(), mappingsTree]); }; diff --git a/lib/api-docs-data/index.js b/lib/api-docs-data/index.js new file mode 100644 index 00000000..ef19f698 --- /dev/null +++ b/lib/api-docs-data/index.js @@ -0,0 +1,17 @@ +'use strict'; + +const Funnel = require('broccoli-funnel'); + +module.exports = { + name: require('./package').name, + + isDevelopingAddon() { + return true; + }, + + treeForPublic() { + return new Funnel('ember-api-docs-data', { + include: ['**/json-docs/**', '**/rev-index/**'], + }); + }, +}; diff --git a/lib/api-docs-data/package.json b/lib/api-docs-data/package.json new file mode 100644 index 00000000..9b312d9f --- /dev/null +++ b/lib/api-docs-data/package.json @@ -0,0 +1,9 @@ +{ + "name": "api-docs-data", + "keywords": [ + "ember-addon" + ], + "peerDependencies": { + "broccoli-funnel": "*" + } +} diff --git a/package.json b/package.json index c9de0be1..d9da0f81 100644 --- a/package.json +++ b/package.json @@ -156,5 +156,10 @@ "volta": { "node": "14.17.0", "npm": "8.19.3" + }, + "ember-addon": { + "paths": [ + "lib/api-docs-data" + ] } } From 8196a4d4dfc252a434e576b6fbc605eba5c97714 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Fri, 16 Sep 2022 14:08:36 +0100 Subject: [PATCH 05/14] add premberUrls function to build the full list of urls --- .eslintrc.js | 1 + ember-cli-build.js | 3 ++- prember-urls.js | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 prember-urls.js diff --git a/.eslintrc.js b/.eslintrc.js index a34c6390..083c799b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -44,6 +44,7 @@ module.exports = { 'lib/**/*.js', 'bin/*', 'server/**/*.js', + 'prember-urls.js', ], excludedFiles: ['config/deprecation-workflow.js'], parserOptions: { diff --git a/ember-cli-build.js b/ember-cli-build.js index 79929968..f2703604 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -4,11 +4,12 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app'); const Funnel = require('broccoli-funnel'); const mergeTrees = require('broccoli-merge-trees'); const envIsProduction = process.env.EMBER_ENV === 'production'; +const premberUrls = require('./prember-urls'); module.exports = function (defaults) { let app = new EmberApp(defaults, { prember: { - urls: [] // fill this in! + urls: premberUrls(), }, fingerprint: { extensions: [ diff --git a/prember-urls.js b/prember-urls.js new file mode 100644 index 00000000..f54c6718 --- /dev/null +++ b/prember-urls.js @@ -0,0 +1,19 @@ +const { readdirSync } = require('fs'); + +module.exports = function () { + const projects = readdirSync('ember-api-docs-data/json-docs'); + + const urls = []; + + projects.forEach((p) => urls.push(`/${p}/release`)); + + return urls; +}; + +// this is useful to debug why a url isn't being prembered +// DEBUG=prember-urls node prember-urls.js +if (process.env.DEBUG === 'prember-urls') { + let urls = module.exports(); + + urls.forEach((url) => console.log(url)); +} From 4a5b9fe39712ea8cbfe9cc5ecc35c046cfcc70d6 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Fri, 14 Oct 2022 13:37:41 +0100 Subject: [PATCH 06/14] add each version landing page to premberUrls --- prember-urls.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/prember-urls.js b/prember-urls.js index f54c6718..43b1500f 100644 --- a/prember-urls.js +++ b/prember-urls.js @@ -5,7 +5,22 @@ module.exports = function () { const urls = []; - projects.forEach((p) => urls.push(`/${p}/release`)); + projects.forEach((p) => { + // add release for each of the projects + urls.push(`/${p}/release`); + + // add landing page for each of the projects versions + const projectVersions = readdirSync(`ember-api-docs-data/json-docs/${p}`) + .filter((v) => v.match(/\d+\.\d+\.\d+/)) + .map((v) => { + let [, major, minor] = v.match(/(\d+)\.(\d+)\.\d+/); + return `${major}.${minor}`; + }); // uniq + + [...new Set(projectVersions)].forEach((v) => { + urls.push(`/${p}/${v}`); + }); + }); return urls; }; From dfc3aa79c6bf6f3de87d83a245e22f9bd1f6d6a3 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Sat, 15 Oct 2022 14:02:34 +0100 Subject: [PATCH 07/14] add all routes for classes namespaces and modules --- prember-urls.js | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/prember-urls.js b/prember-urls.js index 43b1500f..b3400ab9 100644 --- a/prember-urls.js +++ b/prember-urls.js @@ -1,4 +1,6 @@ const { readdirSync } = require('fs'); +const cmp = require('semver-compare'); +const semver = require('semver'); module.exports = function () { const projects = readdirSync('ember-api-docs-data/json-docs'); @@ -9,16 +11,43 @@ module.exports = function () { // add release for each of the projects urls.push(`/${p}/release`); + const fullProjectVersions = readdirSync( + `ember-api-docs-data/json-docs/${p}` + ).filter((v) => v.match(/\d+\.\d+\.\d+/)); + // add landing page for each of the projects versions - const projectVersions = readdirSync(`ember-api-docs-data/json-docs/${p}`) - .filter((v) => v.match(/\d+\.\d+\.\d+/)) - .map((v) => { - let [, major, minor] = v.match(/(\d+)\.(\d+)\.\d+/); - return `${major}.${minor}`; - }); // uniq - - [...new Set(projectVersions)].forEach((v) => { - urls.push(`/${p}/${v}`); + const projectVersions = fullProjectVersions.map((v) => { + let [, major, minor] = v.match(/(\d+)\.(\d+)\.\d+/); + return `${major}.${minor}`; + }); // uniq + + const uniqueProjectVersions = [...new Set(projectVersions)]; + + uniqueProjectVersions.forEach((uniqVersion) => { + urls.push(`/${p}/${uniqVersion}`); + + const sortedPatchVersions = fullProjectVersions + .filter((projectVersion) => { + // console.log("comparing", projectVersion, uniqVersion, semver.satisfies(projectVersion, uniqVersion)) + return semver.satisfies(projectVersion, uniqVersion); + }) + .sort(cmp); + + const highestPatchVersion = + sortedPatchVersions[sortedPatchVersions.length - 1]; + + const revIndex = require(`${__dirname}/ember-api-docs-data/rev-index/${p}-${highestPatchVersion}.json`); + + ['classes', 'namespaces', 'modules'].forEach((entity) => { + // add classes + revIndex.data.relationships[entity].data.forEach(({id}) => { + const [, cleanId] = id.match(/^.+-\d+\.\d+\.\d+-(.*)/); + urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}`); + urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/methods`); + urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/properties`); + urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/events`); + }); + }); }); }); @@ -31,4 +60,6 @@ if (process.env.DEBUG === 'prember-urls') { let urls = module.exports(); urls.forEach((url) => console.log(url)); + + console.log(`\n${urls.length} total URLs`); } From 0cc9638743a24f8d31b0fdb61d7e56e5fc3fbf3e Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Tue, 22 Nov 2022 10:12:35 +0000 Subject: [PATCH 08/14] add each function to prember-urls --- prember-urls.js | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/prember-urls.js b/prember-urls.js index b3400ab9..3a3f11f9 100644 --- a/prember-urls.js +++ b/prember-urls.js @@ -1,4 +1,4 @@ -const { readdirSync } = require('fs'); +const { readdirSync, readFileSync } = require('fs'); const cmp = require('semver-compare'); const semver = require('semver'); @@ -40,12 +40,50 @@ module.exports = function () { ['classes', 'namespaces', 'modules'].forEach((entity) => { // add classes - revIndex.data.relationships[entity].data.forEach(({id}) => { + revIndex.data.relationships[entity].data.forEach(({ id }) => { const [, cleanId] = id.match(/^.+-\d+\.\d+\.\d+-(.*)/); urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}`); + + // TODO only include sub routes if that entity has stuff in that route i.e. if it's empty don't pre-render it urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/methods`); urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/properties`); urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/events`); + + if (entity === 'modules') { + // id is + + const moduleKey = `${encodeURIComponent(id)}`; + const fileName = revIndex.meta.module[moduleKey]; + + if (fileName === undefined) { + // rare cases when very strange things make it through this far + // e.g. ember-3.0.0-ember%0A%0ARemove%20after%203.4%20once%20_ENABLE_RENDER_SUPPORT%20flag%20is%20no%20longer%20needed. + // 🤷‍♀️ + return; + } + + const moduleData = require(`${__dirname}/ember-api-docs-data/json-docs/${p}/${highestPatchVersion}/modules/${fileName}.json`); + + const staticFunctions = moduleData.data.attributes.staticfunctions; + + Object.keys(staticFunctions).forEach((k) => { + const listOfFunctions = staticFunctions[k]; + + listOfFunctions.forEach((func) => { + urls.push( + `/${p}/${uniqVersion}/functions/${cleanId.replace( + '/', + '%2F' + )}/${func.name}` + ); + }); + }); + } + + // TODO review that we have got all the URLs that we care about + + // TODO discuss only prembering "supported" versions - maybe last version in a major and supported versions + // alternative is to rely on netlify complex build }); }); }); From c1f145d7c9c6d0523b1719c11eca7148ae27215d Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Fri, 2 Dec 2022 14:03:39 +0000 Subject: [PATCH 09/14] limit prember to only a few versions --- prember-urls.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/prember-urls.js b/prember-urls.js index 3a3f11f9..704b45ac 100644 --- a/prember-urls.js +++ b/prember-urls.js @@ -23,7 +23,29 @@ module.exports = function () { const uniqueProjectVersions = [...new Set(projectVersions)]; + const oldVersions = [ + '1.12', + '1.13', + '2.17', + '2.18', + '3.4', + '3.8', + '3.12', + '3.16', + '3.20', + '3.24', + '3.27', + '3.28', + ]; + uniqueProjectVersions.forEach((uniqVersion) => { + if ( + !oldVersions.includes(uniqVersion) && + !semver.gte(`${uniqVersion}.0`, '4.0.0') + ) { + return; + } + urls.push(`/${p}/${uniqVersion}`); const sortedPatchVersions = fullProjectVersions From 072041edc80f870232ad856984b778e917da7b4b Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Fri, 2 Dec 2022 14:04:16 +0000 Subject: [PATCH 10/14] fix issue with module names having `/` --- prember-urls.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/prember-urls.js b/prember-urls.js index 704b45ac..83c94cd0 100644 --- a/prember-urls.js +++ b/prember-urls.js @@ -2,6 +2,10 @@ const { readdirSync, readFileSync } = require('fs'); const cmp = require('semver-compare'); const semver = require('semver'); +function partialUrlEncode(input) { + return input.replace('/', '%2F'); +} + module.exports = function () { const projects = readdirSync('ember-api-docs-data/json-docs'); @@ -67,9 +71,19 @@ module.exports = function () { urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}`); // TODO only include sub routes if that entity has stuff in that route i.e. if it's empty don't pre-render it - urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/methods`); - urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/properties`); - urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/events`); + urls.push( + `/${p}/${uniqVersion}/${entity}/${partialUrlEncode( + cleanId + )}/methods` + ); + urls.push( + `/${p}/${uniqVersion}/${entity}/${partialUrlEncode( + cleanId + )}/properties` + ); + urls.push( + `/${p}/${uniqVersion}/${entity}/${partialUrlEncode(cleanId)}/events` + ); if (entity === 'modules') { // id is @@ -93,9 +107,8 @@ module.exports = function () { listOfFunctions.forEach((func) => { urls.push( - `/${p}/${uniqVersion}/functions/${cleanId.replace( - '/', - '%2F' + `/${p}/${uniqVersion}/functions/${partialUrlEncode( + cleanId )}/${func.name}` ); }); From 3d4fb2a56eb6f98c808fc4b6c728a4cb2e2666cf Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Tue, 31 Jan 2023 12:05:24 +0000 Subject: [PATCH 11/14] use the right class in prember-urls --- prember-urls.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/prember-urls.js b/prember-urls.js index 83c94cd0..756cb3db 100644 --- a/prember-urls.js +++ b/prember-urls.js @@ -107,9 +107,7 @@ module.exports = function () { listOfFunctions.forEach((func) => { urls.push( - `/${p}/${uniqVersion}/functions/${partialUrlEncode( - cleanId - )}/${func.name}` + `/${p}/${uniqVersion}/functions/${func.class}/${func.name}` ); }); }); From 5ffe73847163e785d744d0e1f99befd73bb05d1e Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Tue, 31 Jan 2023 12:06:00 +0000 Subject: [PATCH 12/14] stop encoding files too much --- app/services/meta-store.js | 2 +- prember-urls.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/services/meta-store.js b/app/services/meta-store.js index 85f1167d..ceabe895 100644 --- a/app/services/meta-store.js +++ b/app/services/meta-store.js @@ -22,7 +22,7 @@ export default class MetaStoreService extends Service { } getRevId(project, version, type, id) { - let encodedId = encodeURIComponent(id); + let encodedId = id; return this.projectRevMap[`${project}-${version}`][type][encodedId]; } diff --git a/prember-urls.js b/prember-urls.js index 756cb3db..89753ea4 100644 --- a/prember-urls.js +++ b/prember-urls.js @@ -86,9 +86,8 @@ module.exports = function () { ); if (entity === 'modules') { - // id is + const moduleKey = id; - const moduleKey = `${encodeURIComponent(id)}`; const fileName = revIndex.meta.module[moduleKey]; if (fileName === undefined) { From b5609f5d82a8676d5873a2df2eb136d00081365f Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Tue, 31 Jan 2023 12:07:14 +0000 Subject: [PATCH 13/14] test with fix-files branch --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d9da0f81..05e96652 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "test": "tests" }, "scripts": { - "clone": "rm -rf ember-api-docs-data && git clone https://github.com/ember-learn/ember-api-docs-data.git", + "clone": "rm -rf ember-api-docs-data && git clone --depth 1 https://github.com/ember-learn/ember-api-docs-data.git -b fix-files", "build": "ember build --environment=production", "lint": "npm-run-all --aggregate-output --continue-on-error --parallel 'lint:!(fix)'", "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix", From 3ac3e60bc08fc388740b2bb9bd26ce6630422c37 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Tue, 7 Feb 2023 14:16:34 +0000 Subject: [PATCH 14/14] make sure that we only encode parts of premberurls --- prember-urls.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/prember-urls.js b/prember-urls.js index 89753ea4..54d51242 100644 --- a/prember-urls.js +++ b/prember-urls.js @@ -68,7 +68,9 @@ module.exports = function () { // add classes revIndex.data.relationships[entity].data.forEach(({ id }) => { const [, cleanId] = id.match(/^.+-\d+\.\d+\.\d+-(.*)/); - urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}`); + urls.push( + `/${p}/${uniqVersion}/${entity}/${partialUrlEncode(cleanId)}` + ); // TODO only include sub routes if that entity has stuff in that route i.e. if it's empty don't pre-render it urls.push( @@ -106,7 +108,9 @@ module.exports = function () { listOfFunctions.forEach((func) => { urls.push( - `/${p}/${uniqVersion}/functions/${func.class}/${func.name}` + `/${p}/${uniqVersion}/functions/${encodeURIComponent( + func.class + )}/${func.name}` ); }); });