Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use prember #815

Merged
merged 26 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aabb5aa
Notes and placeholder for prember
jenweber Aug 5, 2022
97e97db
making it use local data
mansona Sep 16, 2022
ec1c191
add prember
mansona Sep 16, 2022
f5436bf
move json data to in-repo-addon for prember
mansona Sep 16, 2022
5db2112
add premberUrls function to build the full list of urls
mansona Sep 16, 2022
b862233
add each version landing page to premberUrls
mansona Oct 14, 2022
54ddf53
add all routes for classes namespaces and modules
mansona Oct 15, 2022
0031d73
add each function to prember-urls
mansona Nov 22, 2022
e091a88
limit prember to only a few versions
mansona Dec 2, 2022
84d3109
fix issue with module names having `/`
mansona Dec 2, 2022
105916d
use the right class in prember-urls
mansona Jan 31, 2023
6438c63
stop encoding files too much
mansona Jan 31, 2023
a299b12
make sure that we only encode parts of premberurls
mansona Feb 7, 2023
d6d19f5
only render methods properties and events if exist
mansona May 22, 2023
bb85393
WIP: test ci-workflow branch
mansona May 22, 2023
84d5240
Update clone script to use main branch
jenweber Jul 7, 2023
7fd26fe
make sure that it works with case-insensitive ids
mansona Aug 11, 2023
5f08fa6
fix for missing files
mansona Aug 11, 2023
8f73979
don't redirect when you have a 404
mansona Aug 11, 2023
741cb92
prember fewer versions
mansona Aug 11, 2023
a565e29
Add release URLs for prember
jenweber Aug 25, 2023
009be66
add SPA redirect
mansona Sep 1, 2023
970c142
fix lint
mansona Sep 21, 2023
f27c627
update lock file
mansona Sep 21, 2023
d74d8d9
fix invalid test
mansona Sep 22, 2023
ab36313
override node-sass to allow us to use later node
mansona Sep 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

# data git checkout
/ember-api-docs-data/
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
- name: Install dependencies
run: npm ci

- run: npm run clone

- name: Test
env:
PERCY_PARALLEL_NONCE: ${{ env.PERCY_PARALLEL_NONCE }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ local.log
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

/ember-api-docs-data/
/ember-api-docs-data
6 changes: 2 additions & 4 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { inject as service } from '@ember/service';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import fetch from 'fetch';
import ENV from 'ember-api-docs/config/environment';
import { pluralize } from 'ember-inflector';
import { isBlank } from '@ember/utils';

export default class Application extends JSONAPIAdapter {
host = ENV.API_HOST;
currentProject = '';
currentProjectVersion = '';

Expand Down Expand Up @@ -47,7 +45,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) {
Expand Down Expand Up @@ -85,7 +83,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();
Expand Down
36 changes: 35 additions & 1 deletion app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class AppRouter extends EmberRouter {
}

AppRouter.map(function () {
this.route('404');
this.route('ember-cli');
this.route('project', { path: '/:project' });

Expand Down Expand Up @@ -92,4 +91,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;
8 changes: 7 additions & 1 deletion app/routes/project-version/classes/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ export default class ClassRoute extends Route.extend(ScrollTracker) {
}

if (model.isError) {
this.router.transitionTo('404');
let error = new Error(
'Error retrieving model in routes/project-version/classes/class'
);

error.status = 404;

throw error;
}
}

Expand Down
12 changes: 12 additions & 0 deletions app/serializers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ export default class Application extends JSONAPISerializer {
@service
metaStore;

extractId(_, hash) {
return hash.id.toLowerCase();
}

extractRelationship(relationship) {
// for some reason we only need to update the id to lowercase when it's an object relationship and not an array 🤷
if (relationship?.data?.id) {
relationship.data.id = relationship.data.id.toLowerCase();
}
return super.extractRelationship(relationship);
}

normalizeFindRecordResponse(store, primaryModelClass, payload, id) {
let normalizedDocument = super.normalizeFindRecordResponse(...arguments);

Expand Down
10 changes: 8 additions & 2 deletions app/services/meta-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ export default class MetaStoreService extends Service {
}

getRevId(project, version, type, id) {
let encodedId = encodeURIComponent(id);
return this.projectRevMap[`${project}-${version}`][type][encodedId];
let encodedId = id;
let revType = this.projectRevMap[`${project}-${version}`][type];

let matchingKey = Object.keys(revType).find(
(key) => key.toLowerCase() === encodedId.toLowerCase()
);

return this.projectRevMap[`${project}-${version}`][type][matchingKey];
}

getEncodedModulesFromProjectRev(id) {
Expand Down
10 changes: 0 additions & 10 deletions app/templates/404.hbs

This file was deleted.

5 changes: 5 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ 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: premberUrls(),
},
fingerprint: {
extensions: [
'js',
Expand Down Expand Up @@ -63,5 +67,6 @@ module.exports = function (defaults) {
include: ['mappings.json'],
destDir: '/assets/',
});

return mergeTrees([app.toTree(), mappingsTree]);
};
17 changes: 17 additions & 0 deletions lib/api-docs-data/index.js
Original file line number Diff line number Diff line change
@@ -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/**'],
});
},
};
9 changes: 9 additions & 0 deletions lib/api-docs-data/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "api-docs-data",
"keywords": [
"ember-addon"
],
"peerDependencies": {
"broccoli-funnel": "*"
}
}
Loading