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

Website/issue 98 getting started guide #139

Merged
merged 16 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"scripts": {
"clean": "rimraf ./**/.greenwood/** && rimraf ./**/public/** && rimraf ./coverage",
"lint": "eslint \"./packages/**/**/*.js\" \"./test/**/**/*.js\"",
"lint": "eslint \"./packages/**/**/*.js\" \"./test/**/**/*.js\" \"./www/**/**/*.js\"",
"build": "yarn clean && node ./packages/cli/index.js build",
"serve": "yarn build && cd ./public && ws",
"develop": "yarn clean && node ./packages/cli/index.js develop",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/templates/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
label: 'index'
---

### Greenwood

This is the home page built by Greenwood. Make your own pages in src/pages/index.js!
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Use Case
* Run Greenwood build command and reproduce building the Getting Started docs companion repo
* https://github.com/thescientist13/greenwood-getting-started
*
* User Result
* Should generate a Greenwood build that generally reproduces the Getting Started guide
*
* User Command
* greenwood build
*
* Default Config
*
* Custom Workspace
* src/
* assets/
* greenwood-logo.png
* components/
* footer.js
* header.js
* pages/
* first-post.md
* second-post.md
* styles/
* theme.css
* templates/
* app-template.js
* blog-template.js
*/
const expect = require('chai').expect;
const fs = require('fs');
const glob = require('glob-promise');
const { JSDOM } = require('jsdom');
const path = require('path');
const TestBed = require('../../test-bed');

describe('Build Greenwood With: ', function() {
const LABEL = 'Custom Workspace based on the Getting Started guide and repo';
let setup;

before(async function() {
setup = new TestBed();
this.context = setup.setupTestBed(__dirname);
});

describe(LABEL, function() {
before(async function() {
await setup.runGreenwoodCommand('build');
});

describe('Folder Structure and Home Page', function() {
beforeEach(async function() {
dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'index.html'));
});

it('should create a public directory', function() {
expect(fs.existsSync(this.context.publicDir)).to.be.true;
});

it('should create a new assets directory', function() {
expect(fs.existsSync(path.join(this.context.publicDir, 'assets'))).to.be.true;
});

it('should contain files from the asset directory', async function() {
expect(fs.existsSync(path.join(this.context.publicDir, 'assets', './greenwood-logo.png'))).to.be.true;
});

it('should output an index.html file (home page)', function() {
expect(fs.existsSync(path.join(this.context.publicDir, './index.html'))).to.be.true;
});

it('should output a single 404.html file (not found page)', function() {
expect(fs.existsSync(path.join(this.context.publicDir, './404.html'))).to.be.true;
});

it('should output one JS bundle file', async function() {
expect(await glob.promise(path.join(this.context.publicDir, './index.*.bundle.js'))).to.have.lengthOf(1);
});

it('should have a <header> tag in the <body>', function() {
const header = dom.window.document.querySelectorAll('body header');

expect(header.length).to.be.equal(1);
});

it('should have a <footer> tag in the <body>', function() {
const footer = dom.window.document.querySelectorAll('body footer');

expect(footer.length).to.be.equal(1);
});

it('should have the expected font import', async function() {
const styles = '@import url(//fonts.googleapis.com/css?family=Source+Sans+Pro&display=swap);';
const styleTags = dom.window.document.querySelectorAll('head style');
let importCount = 0;

styleTags.forEach((tag) => {
if (tag.textContent.indexOf(styles) >= 0) {
importCount += 1;
}
});

expect(importCount).to.equal(1);
});
});

describe('Blog Posts', function() {
it('should create a blog directory', function() {
expect(fs.existsSync(path.join(this.context.publicDir, 'blog'))).to.be.true;
});

it('should output an index.html file (home page)', function() {
expect(fs.existsSync(path.join(this.context.publicDir, 'blog', 'first-post', './index.html'))).to.be.true;
});

it('should output a single 404.html file (not found page)', function() {
expect(fs.existsSync(path.join(this.context.publicDir, 'blog', 'second-post', './index.html'))).to.be.true;
});

it('should output one JS bundle file', async function() {
expect(await glob.promise(path.join(this.context.publicDir, './index.*.bundle.js'))).to.have.lengthOf(1);
});

it('should have a <header> tag in the <body> in first-post.md', async function() {
const dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'blog', 'first-post', 'index.html'));
const header = dom.window.document.querySelectorAll('body header');

expect(header.length).to.be.equal(1);
});

it('should have a <footer> tag in the <body>', async function() {
const dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'blog', 'first-post', 'index.html'));
const footer = dom.window.document.querySelectorAll('body footer');

expect(footer.length).to.be.equal(1);
});

it('should have the expected font import', async function() {
const styles = '@import url(//fonts.googleapis.com/css?family=Source+Sans+Pro&display=swap);';
const styleTags = dom.window.document.querySelectorAll('head style');
let importCount = 0;

styleTags.forEach((tag) => {
if (tag.textContent.indexOf(styles) >= 0) {
importCount += 1;
}
});

expect(importCount).to.equal(1);
});
});

});

after(function() {
setup.teardownTestBed();
});

});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class FooterComponent extends HTMLElement {
constructor() {
super();

// create a Shadow DOM
this.root = this.attachShadow({ mode: 'open' });
}

// run some code when the component is ready
connectedCallback() {
this.root.innerHTML = this.getTemplate();
}

// create templates that interpolate variables and HTML!
getTemplate() {
return `
<style>
</style>
<footer>This is the footer component.</footer>
`;
}
}

customElements.define('app-footer', FooterComponent);
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class HeaderComponent extends HTMLElement {
constructor() {
super();

// create a Shadow DOM
this.root = this.attachShadow({ mode: 'open' });
}

// run some code when the component is ready
connectedCallback() {
this.root.innerHTML = this.getTemplate();
}

// create templates that interpolate variables and HTML!
getTemplate() {
return `
<style>
</style>
<header>This is the header component.</header>
`;
}
}

customElements.define('app-header', HeaderComponent);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
template: 'blog'
---

## My First Blog Post
Lorem Ipsum

[back](/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
template: 'blog'
---

## My Second Blog Post
Lorem Ipsum

[back](/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Home Page

This is the Getting Started home page!

### My Posts
- [my-second-post](/blog/second-post/)
- [my-first-post](/blog/first-post/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@import url('//fonts.googleapis.com/css?family=Source+Sans+Pro&display=swap');

* {
margin: 0;
padding: 0;
font-family: 'Source Sans Pro', sans-serif;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { html, LitElement } from 'lit-element';
import '../components/footer';
import '../components/header';

MDIMPORT;
METAIMPORT;
METADATA;

class BlogTemplate extends LitElement {

constructor() {
super();
}

render() {
return html`
<style>

</style>

METAELEMENT

<div class='container'>
<app-header></app-header>
<entry></entry>
<app-footer></app-footer>
</div>
`;
}
}

customElements.define('page-template', BlogTemplate);
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { html, LitElement } from 'lit-element';
import '../components/footer';
import '../components/header';
import '../styles/theme.css';

MDIMPORT;

class PageTemplate extends LitElement {

constructor() {
super();
}

render() {
return html`

<style>
section {
margin: 0 auto;
width: 70%;
}
</style>


<div>
<app-header></app-header>
<entry></entry>
<app-footer></app-footer>
</div>
`;
}
}

customElements.define('page-template', PageTemplate);
Binary file added www/assets/greenwood-netlify-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading