Skip to content

Commit

Permalink
feat(init): add github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Feb 9, 2021
1 parent 3488047 commit 6a21405
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 35 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

## Modes

- Init Mode
- Creating a slide, style, configuration file
- Creating GitHub actions that deploy slides to gh-pages automatically
- Development Mode
- Running with HMR
- Just coding Markdown and sometimes CSS
Expand Down Expand Up @@ -59,6 +62,9 @@ $ npx fusuma init
$ tree -a
.
├── .fusumarc.yml
├── .github
│ └── workflows
│ └── fusuma.yml
├── slides
│ └── 0-title.md
└── style.css
Expand Down
54 changes: 23 additions & 31 deletions packages/fusuma/src/configs/fusumarc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
'use strict';

const { readFile, writeFile, mkdir } = require('fs');
const { readFile, writeFile, mkdir } = require('fs').promises;
const { join, extname } = require('path');
const { promisify } = require('util');
const yaml = require('js-yaml');
const pSearch = require('preferred-search');
const { all: mergeAll } = require('deepmerge');
const { info } = require('../cli/log');

const mkdirAsync = promisify(mkdir);
const readFileAsync = promisify(readFile);
const writeFileAsync = promisify(writeFile);

const config = {
meta: {
url: null,
Expand Down Expand Up @@ -51,30 +46,27 @@ const config = {
const configFileNames = ['.fusumarc.yml', '.fusumarc.js'];

async function init(baseDir) {
{
const data = await readFileAsync(join(__dirname, 'templates', 'fusumarc.yml'), 'utf8');

await writeFileAsync(join(baseDir, '.fusumarc.yml'), data);
info('init', 'Created .fusumarc.yml');
}

// scaffold
await mkdirAsync(join(baseDir, 'slides'));
info('init', 'Created /slides');

{
const data = await readFileAsync(join(__dirname, 'templates', '0-title.md'), 'utf8');

await writeFileAsync(join(baseDir, 'slides', '0-title.md'), data);
info('init', 'Created slides/0-title.md');
}

{
const data = await readFileAsync(join(__dirname, 'templates', 'style.css'), 'utf8');

await writeFileAsync(join(baseDir, 'style.css'), data);
info('init', 'Created style.css');
}
const templatePath = join(__dirname, 'templates');

await Promise.all([
mkdir(join(baseDir, 'slides'), { recursive: true }),
mkdir(join(baseDir, '.github', 'workflows'), { recursive: true }),
]);

await Promise.all([
writeFile(join(baseDir, '.fusumarc.yml'), await readFile(join(templatePath, 'fusumarc.yml'))),
writeFile(join(baseDir, 'style.css'), await readFile(join(templatePath, 'style.css'))),
writeFile(
join(baseDir, 'slides', '0-title.md'),
await readFile(join(templatePath, '0-title.md'))
),
writeFile(
join(baseDir, '.github', 'workflows', 'fusuma.yml'),
await readFile(join(templatePath, 'fusuma.yml'))
),
]);

info('init', 'Added slides, style.css, fusumarc, and github actions');
}

async function read(baseDir) {
Expand All @@ -86,7 +78,7 @@ async function read(baseDir) {

switch (extname(file)) {
case '.yml':
return yaml.load(await readFileAsync(file, 'utf8'));
return yaml.load(await readFile(file, 'utf8'));
case '.js':
return require(file);
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
name: 'Fusuma action'
description: 'Deploy slides to github pages'
author: 'hiroppy'
name: 'Deploy slides to github pages'

on:
push:
Expand All @@ -15,7 +13,8 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: 14
- run: npm ci && npx fusuma build
- run: npm ci
- run: npx fusuma build
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 3 additions & 0 deletions samples/intro/slides/02-fusuma.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ $ npx fusuma init
$ tree -a
.
├── .fusumarc.yml
├── .github
│ └── workflows
│ └── fusuma.yml
├── slides
│ └── 0-title.md
└── style.css
Expand Down
3 changes: 3 additions & 0 deletions site/docs/getting-started/preparation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ $ npx fusuma init
$ tree -a
.
├── .fusumarc.yml
├── .github
│ └── workflows
│ └── fusuma.yml
├── slides
│ └── 0-title.md
└── style.css
Expand Down

0 comments on commit 6a21405

Please sign in to comment.