Skip to content

Commit

Permalink
Fix graph route assignments (#60)
Browse files Browse the repository at this point in the history
* fix: removing browser renderer exception, updating graph route, removed default route from app-template and all exceptions for default route from scaffold.js and serialize.js

* docs: removing default route for app-template.js instructions
  • Loading branch information
hutchgrant authored and thescientist13 committed Apr 28, 2019
1 parent f96db0d commit c90c662
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 20 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ By default, Greenwood will supply its own [app-template](https://github.com/Proj
An `app-template.js` must follow the [default template](https://github.com/ProjectEvergreen/greenwood/blob/master/packages/cli/templates/app-template.js#L1-L13) in that it must include the lit-redux-router, redux, redux-thunk, lazy-reducer-enhancer and it must create a redux store. You may import any additional components or tools you wish but the `import './list';` [must be included](https://github.com/ProjectEvergreen/greenwood/blob/master/packages/cli/templates/app-template.js#L16) in order to import all your generated static page components. Do not change the path and you can ignore the fact that this file doesn't exist, it will be created on build in memory. In the [render function](https://github.com/ProjectEvergreen/greenwood/blob/master/packages/cli/templates/app-template.js#L21-L26), it must include somewhere:

```html
<lit-route path="/" component="home-page"></lit-route>
MYROUTES
```

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/lib/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const createGraphFromPages = async (pagesDir) => {
template = template || 'page';

// get remaining string after user's pages directory
let subDir = filePath.substring(pagesDir.length, filePath.length);
let subDir = filePath.substring(pagesDir.length - 1, filePath.length);

// get index of seperator between remaining subdirectory and the file's name
const seperatorIndex = subDir.lastIndexOf('/');
Expand All @@ -58,7 +58,7 @@ const createGraphFromPages = async (pagesDir) => {
mdFile = `./${completeNestedPath}${fileRoute}.md`;
relativeExpectedPath = `'../${completeNestedPath}/${fileName}/${fileName}.js'`;
} else {
mdFile = `./${fileRoute}.md`;
mdFile = `.${fileRoute}.md`;
relativeExpectedPath = `'../${fileName}/${fileName}.js'`;
}

Expand Down
4 changes: 1 addition & 3 deletions packages/cli/lib/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ const writeRoutes = async(compilation) => {
let data = await fs.readFileSync(path.join(compilation.context.templatesDir, `${compilation.context.appTemplate}`));

const routes = compilation.graph.map(file => {
if (file.route !== '/') {
return `<lit-route path="${file.route}" component="eve-${file.label}"></lit-route>\n\t\t\t\t`;
}
return `<lit-route path="${file.route}" component="eve-${file.label}"></lit-route>\n\t\t\t\t`;
});

const result = data.toString().replace(/MYROUTES/g, routes.join(''));
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/lib/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ const PORT = '8000';
const runBrowser = async (compilation) => {

try {
return await Promise.all(compilation.graph.map(file => {
const route = file.route === '/' ? '' : file.route;

return browserRunner(`http://127.0.0.1:${PORT}/${route}`, file.label, file.route, compilation.context.publicDir);
return await Promise.all(compilation.graph.map(({ route, label }) => {
return browserRunner(`http://127.0.0.1:${PORT}${route}`, label, route, compilation.context.publicDir);
}));
} catch (err) {
// eslint-disable-next-line no-console
Expand Down
8 changes: 0 additions & 8 deletions packages/cli/lib/util/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ module.exports = async (url, label, route, outputDirectory) => {
const html = dom.serialize();
const target = path.join(outputDirectory, route);

// Exception for index file in root public directory
const endOfPathFolder = target.substring(target.lastIndexOf('/public/'), target.length);
const isRootPublicDirectoryException = endOfPathFolder === '/public/index';

if (isRootPublicDirectoryException) {
return await fs.writeFileSync(path.join(outputDirectory, 'index.html'), html);
}

await fs.mkdirSync(target, { recursive: true });
return await fs.writeFileSync(path.join(target, 'index.html'), html);
};
1 change: 0 additions & 1 deletion packages/cli/templates/app-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ connectRouter(store);
class AppComponent extends LitElement {
render() {
return html`
<lit-route path="/" component="eve-index"></lit-route>
MYROUTES
<lit-route><h1>404 Not found</h1></lit-route>
`;
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/mock-app/src/templates/app-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class AppComponent extends LitElement {
return html`
<eve-header></eve-header>
<eve-navigation></eve-navigation>
<lit-route path="/" component="eve-index"></lit-route>
MYROUTES
`;
}
Expand Down

0 comments on commit c90c662

Please sign in to comment.