Skip to content

Commit

Permalink
Add scaffolding; rename layout.ejs to main.ejs; add CONTRIBUTING.md
Browse files Browse the repository at this point in the history
  • Loading branch information
koistya committed Mar 19, 2016
1 parent 89f3068 commit 9e04681
Show file tree
Hide file tree
Showing 22 changed files with 405 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
# Include your project-specific ignores in this file
# Read about how to use .gitignore: https://help.github.com/articles/ignoring-files

demo
docs/dist
lib
node_modules
Expand Down
4 changes: 1 addition & 3 deletions .npmignore
@@ -1,5 +1,3 @@
.travis.yml
docs
src
.travis.yml
LICENSE.txt
README.md
18 changes: 18 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,18 @@
# Easystatic Change Log

All notable changes to this project will be documented in this file.

### [Unreleased][unreleased]

- Compile `main.js` file with [Babel](https://babeljs.io) and [Browserify](http://browserify.org/) (PLANNED)

### [v0.1.0] - 2016-03-19

- Change the name of the main template from `assets/layout.ejs` to `assets/main.ejs` (BREAKING CHANGE)
- Remove source maps from the generated `main.css` file in production mode
- Add scaffolding and a default template (see `template`)
- Add [CHANGELOG.md](CHANGELOG.md) file with notable changes to this project
- Add [CONTRIBUTING.md](CONTRIBUTING.md) file with instructions on how to contribute to this project

[unreleased]: https://github.com/kriasoft/react-starter-kit/compare/v0.1.0...HEAD
[v0.1.0]: https://github.com/kriasoft/react-starter-kit/compare/v0.0.8...v0.1.0
131 changes: 131 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,131 @@
# Contributing to Easystatic

Want to hack on **[Easystatic](https://easystatic.com)** site generator? Awesome! There are plenty
of ways you can help!

Please take a moment to review this document in order to make the contribution process easy and
effective for everyone involved.

Following these guidelines helps to communicate that you respect the time of the developers
managing and developing this open source project. In return, they should reciprocate that respect
in addressing your issue or assessing patches and features.

## Using the issue tracker

The [issue tracker](https://github.com/easystatic/easystatic/issues) is the preferred channel for
[bug reports](#bugs), [features requests](#features) and [submitting pull requests](#pull-requests),
but please respect the following restrictions:

* Please **do not** use the issue tracker for personal support requests
(use [Stack Overflow](https://stackoverflow.com/questions/tagged/easystatic)).

* Please **do not** derail or troll issues. Keep the discussion on topic and respect the opinions
of others.

<a name="bugs"></a>
## Bug reports

A bug is a _demonstrable problem_ that is caused by the code in the repository. Good bug reports
are extremely helpful - thank you!

Guidelines for bug reports:

1. **Use the GitHub issue search** &mdash; check if the issue has already been reported.

2. **Check if the issue has been fixed** &mdash; try to reproduce it using the latest `master` or
development branch in the repository.

3. **Isolate the problem** &mdash; ideally create a [reduced test case](https://css-tricks.com/reduced-test-cases/)
and a live example.

A good bug report shouldn't leave others needing to chase you up for more information. Please try
to be as detailed as possible in your report. What is your environment? What steps will reproduce
the issue? What browser(s) and OS experience the problem? What would you expect to be the outcome?
All these details will help people to fix any potential bugs.

Example:

> Short and descriptive example bug report title
>
> A summary of the issue and the browser/OS environment in which it occurs. If suitable, include
> the steps required to reproduce the bug.
>
> 1. This is the first step
> 2. This is the second step
> 3. Further steps, etc.
>
> `<url>` - a link to the reduced test case
>
> Any other information you want to share that is relevant to the issue being reported. This might
> include the lines of code that you have identified as causing the bug, and potential solutions
> (and your opinions on their merits).
<a name="features"></a>
## Feature requests

Feature requests are welcome. But take a moment to find out whether your idea fits with the scope
and aims of the project. It's up to *you* to make a strong case to convince the project's developers
of the merits of this feature. Please provide as much detail and context as possible.

<a name="pull-requests"></a>
## Pull requests

Good pull requests - patches, improvements, new features - are a fantastic help. They should remain
focused in scope and avoid containing unrelated commits.

**Please ask first** before embarking on any significant pull request (e.g. implementing features,
refactoring code, porting to a different language), otherwise you risk spending a lot of time
working on something that the project's developers might not want to merge into the project.

Please adhere to the coding conventions used throughout a project (indentation, accurate comments,
etc.) and any other requirements (such as test coverage).

Adhering to the following process is the best way to get your work included in the project:

1. [Fork](https://help.github.com/articles/fork-a-repo/) the project, clone your fork, and
configure the remotes:

```bash
# Clone your fork of the repo into the current directory
git clone https://github.com/<your-username>/easystatic.git
# Navigate to the newly cloned directory
cd easystatic
# Assign the original repo to a remote called "upstream"
git remote add upstream https://github.com/easystatic/easystatic.git
```

2. If you cloned a while ago, get the latest changes from upstream:

```bash
git checkout master
git pull upstream master
```

3. Create a new topic branch (off the main project development branch) to contain your feature,
change, or fix:

```bash
git checkout -b <topic-branch-name>
```

4. Commit your changes in logical chunks. Please adhere to these [git commit message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
or your code is unlikely be merged into the main project. Use Git's [interactive rebase](https://help.github.com/articles/about-git-rebase/)
feature to tidy up your commits before making them public.

5. Locally merge (or rebase) the upstream development branch into your topic branch:

```bash
git pull [--rebase] upstream master
```

6. Push your topic branch up to your fork:

```bash
git push origin <topic-branch-name>
```

7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/) with a clear title
and description.

**IMPORTANT**: By submitting a patch, you agree to allow the project owners to license your work
under the terms of the [Apache 2.0](LICENSE.txt).
9 changes: 9 additions & 0 deletions docs/assets/footer.css
@@ -1,3 +1,12 @@
/**
* Easystatic - static site generator (https://easystatic.com)
*
* Copyright © 2016 Easystatic contributors. All rights reserved.
*
* This source code is licensed under the Apache 2.0 license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

.mdl-mini-footer {
justify-content: center;
}
Expand Down
9 changes: 9 additions & 0 deletions docs/assets/header.css
@@ -1,3 +1,12 @@
/**
* Easystatic - static site generator (https://easystatic.com)
*
* Copyright © 2016 Easystatic contributors. All rights reserved.
*
* This source code is licensed under the Apache 2.0 license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

.l-hero {
display: flex;
width: 100%;
Expand Down
4 changes: 2 additions & 2 deletions docs/assets/header.ejs
Expand Up @@ -19,7 +19,7 @@
<div class="mdl-layout__header-row l-indent l-hero max-width">
<div class="l-hero-left">
<h1 class="l-hero-title">Static site generator</h1>
<p class="l-hero-desc">The easiest way to build a static website for your project.</p>
<p class="l-hero-desc">The easiest way to build a static website for your project. Just create a folder with markdown (.md) files in it, and let Easystatic to do its magic.</p>
<pre class="l-hero-code"><em>$</em> npm install -g easystatic<br><em>$</em> es start &lt;path&gt<span class="blinking-cursor">|</span></pre>
<p>
<a class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" href="/getting-started">
Expand All @@ -38,7 +38,7 @@
<div class="mdl-layout__header-row l-indent layout_header-row--highlight">
<div class="l-container">
<div style="float:right">Join <a href="https://gitter.im/easystatic/easystatic">#easystatic</a> chat room on Gitter to stay up to date</div>
<div>2016-03-18 | v0.0.8</div>
<div>2016-03-19 | <a href="https://www.npmjs.com/package/easystatic">v0.1.0</a></div>
</div>
</div>
</header>
Expand Down
9 changes: 9 additions & 0 deletions docs/assets/main.css
@@ -1,3 +1,12 @@
/**
* Easystatic - static site generator (https://easystatic.com)
*
* Copyright © 2016 Easystatic contributors. All rights reserved.
*
* This source code is licensed under the Apache 2.0 license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

@import 'header.css';
@import 'footer.css';

Expand Down
File renamed without changes.
8 changes: 6 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "easystatic",
"version": "0.0.8",
"version": "0.1.0",
"description": "A simple static site generator",
"homepage": "https://easystatic.com",
"author": "Konstantin Tarkus <hello@tarkus.me> (http://tarkus.me/)",
Expand Down Expand Up @@ -32,7 +32,8 @@
},
"files": [
"bin",
"lib"
"lib",
"template"
],
"engines": ">= 5.0",
"babel": {
Expand All @@ -49,6 +50,7 @@
"autoprefixer": "^6.3.3",
"browser-sync": "^2.11.1",
"bs-html-injector": "^3.0.0",
"cp-file": "^3.1.0",
"cssnano": "^3.5.2",
"debug": "^2.2.0",
"ejs": "^2.4.1",
Expand All @@ -75,6 +77,8 @@
"lint": "eslint src",
"test": "eslint src",
"start": "babel-node ./src/easystatic.js start docs",
"demo": "babel-node ./src/easystatic.js start demo",
"demo:build": "babel-node ./src/easystatic.js build demo",
"docs": "babel-node ./src/easystatic.js start docs",
"docs:build": "babel-node ./src/easystatic.js build docs",
"docs:deploy": "babel-node ./src/easystatic.js deploy docs --repo=easystatic/easystatic.github.io --domain=easystatic.com",
Expand Down
4 changes: 4 additions & 0 deletions src/build.js
Expand Up @@ -11,14 +11,18 @@ import debug from 'debug';
import path from 'path';
import glob from 'globby';
import fs from './fs';
import scaffold from './scaffold';
import compile from './compile';

const log = debug('easystatic:build');

async function build({ baseDir, buildDir, assetsDir, production }) {
log(`build({ baseDir: '${baseDir}' })`);
await scaffold({ baseDir, assetsDir });

log('remove', path.resolve(baseDir, buildDir));
await fs.removeDir(path.resolve(baseDir, buildDir));

const files = await glob([`${baseDir}/**/*.md`, `!${buildDir}`, `!${assetsDir}`]);
await Promise.all(files.map(file => new Promise(async (resolve, reject) => {
try {
Expand Down
11 changes: 7 additions & 4 deletions src/compile.js
Expand Up @@ -27,21 +27,24 @@ const postcss = new Postcss([postcssImport, autoprefixer, cssnano]);
async function md(file, { baseDir, assetsDir }) {
log(`compile.md('${file}', { baseDir: '${baseDir}', assetsDir: '${assetsDir}' })`);
const source = await fs.readFile(path.resolve(file), 'utf-8');
const layoutFile = path.resolve(baseDir, path.join(assetsDir, 'layout.ejs'));
const layoutFile = path.resolve(baseDir, path.join(assetsDir, 'main.ejs'));
const layout = await fs.readFile(layoutFile, 'utf-8');
const fmContent = fm(source);
const content = markdown.render(fmContent.body);
fmContent.attributes.id = fmContent.attributes.id || '';
fmContent.attributes.title = fmContent.attributes.title || '';
fmContent.attributes.description = fmContent.attributes.description || '';
return ejs.render(layout, { ...fmContent.attributes, content, filename: layoutFile });
}

async function css(pathname, { baseDir, assetsDir }) {
log(`compile.css('${pathname}', { baseDir: '${baseDir}', assetsDir: '${assetsDir}' })`);
async function css(pathname, { baseDir, assetsDir, production }) {
log(`compile.css('${pathname}', { baseDir: '${baseDir}', assetsDir: '${assetsDir}', production: ${production} })`);
const filename = path.resolve(baseDir, path.join(assetsDir, pathname));
const source = await fs.readFile(filename, 'utf-8');
return await postcss.process(source, {
from: filename.substr(path.resolve(process.cwd()).length + 1),
to: pathname,
map: { inline: true },
map: production === true ? false : { inline: true },
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/deploy.js
Expand Up @@ -33,7 +33,7 @@ async function deploy({ baseDir, buildDir, assetsDir, repo, domain }) {

log(`git push to https://github.com/${repo}.git`);
const git = await Repo.open(path.resolve(baseDir, buildDir), { init: true });
git.setRemote('origin', `https://${process.env.GH_TOKEN ? `${process.env.GH_TOKEN}@` : ''}github.com/${repo}.git`);
git.setRemote('origin', `https://${process.env.GITHUB_TOKEN ? `${process.env.GITHUB_TOKEN}@` : ''}github.com/${repo}.git`);
await git.add('--all .');
await git.commit('Initial commit');
await git.push('origin', repo.endsWith('.io') ? 'master' : 'gh-pages', { force: true });
Expand Down
3 changes: 2 additions & 1 deletion src/easystatic.js
Expand Up @@ -48,10 +48,11 @@ if (argv.help || argv.h) {
} else if (command === 'start') {
start(options);
} else if (command === 'build') {
build(options).catch(console.error);
build({ ...options, production: true }).catch(console.error);
} else if (command === 'deploy') {
deploy({
...options,
production: true,
repo: argv.repo || argv.r,
domain: argv.domain || argv.d,
}).catch(console.error);
Expand Down
64 changes: 64 additions & 0 deletions src/scaffold.js
@@ -0,0 +1,64 @@
/**
* Easystatic - static site generator (https://easystatic.com)
*
* Copyright © 2016 Easystatic contributors. All rights reserved.
*
* This source code is licensed under the Apache 2.0 license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

import path from 'path';
import debug from 'debug';
import globby from 'globby';
import cp from 'cp-file';
import fs from './fs';

const log = debug('easystatic:init');

async function createIndexFile(baseDir) {
const filename = path.resolve(baseDir, 'index.md');
try {
if ((await fs.stat(filename)).isFile()) {
return;
}
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}

log(`Create ${filename} file`);
await await cp(path.join(__dirname, '../template/index.md'), filename);
}

async function scaffold({ baseDir, assetsDir }) {
log(`scaffold({ baseDir: '${baseDir}', assetsDir: '${assetsDir}' })`);

await createIndexFile(baseDir);

const assetsPath = path.resolve(baseDir, assetsDir);

try {
if ((await fs.stat(assetsPath)).isDirectory()) {
log(`Skip scaffolding because ${assetsPath} folder already exists.`);
return;
}
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}

const files = await globby(path.join(__dirname, '../template/**/*.*'));
for (const file of files) {
if (file.endsWith('index.md')) {
continue;
}

const dest = path.resolve(assetsPath, file.substr(path.join(__dirname, '../template').length + 1));
log(`Copy ${file} to ${dest}`);
await cp(file, dest);
}
}

export default scaffold;

0 comments on commit 9e04681

Please sign in to comment.