Skip to content

Commit

Permalink
feat(configs): add scaffolding into init command
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Jul 6, 2019
1 parent 3c1bcf0 commit 0d10187
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 7 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ $ tree -a

1 directory, 1 files

# -------- init ---------
# you can use `init` command

$ npx fusuma init
$ tree -a

.
├── .fusumarc.yml
├── slides
│ └── 0-title.md
└── style.css

1 directory, 3 files

# --- executable tasks---
$ npx fusuma init # customize fusuma configuration
$ npx fusuma start # development
Expand Down
2 changes: 1 addition & 1 deletion packages/configs/__tests__/__snapshots__/fusumarc.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ slide:
math: false
extends:
js:
css:
css: ./style.css
"
`;

Expand Down
27 changes: 27 additions & 0 deletions packages/configs/__tests__/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
:root {
--color-white: #f5f5f5;
--color-black: #333;
}

html {
/* set the base font-size */
font-size: 62.5%;
}

body {
/* set the default background */
background: var(--color-white);

/* set the default font-color */
color: var(--color-black);
}

/* code blocks */
code[class*='language-'],
pre[class*='language-'] {
font-size: 2rem;
}

/* https://hiroppy.github.io/fusuma/docs/guides/slide-syntax#declaring-section-title */
.section-title {
}
24 changes: 22 additions & 2 deletions packages/configs/src/fusumarc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

const { readFile, writeFile } = require('fs');
const { readFile, writeFile, mkdir } = require('fs');
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 mkdirAsync = promisify(mkdir);
const readFileAsync = promisify(readFile);
const writeFileAsync = promisify(writeFile);

Expand Down Expand Up @@ -35,7 +36,7 @@ const config = {
},
extends: {
js: null,
css: null
css: './style.css'
}
};

Expand All @@ -56,6 +57,25 @@ function getConfigYaml() {
async function init(baseDir) {
try {
await writeFileAsync(join(baseDir, '.fusumarc.yml'), getConfigYaml());
console.info('Created .fusumarc.yml');

// scaffold
await mkdirAsync(join(baseDir, 'slides'));
console.info('Created slides directory');

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

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

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

await writeFileAsync(join(baseDir, 'style.css'), data);
console.info('Created style.css');
}
} catch (e) {
throw e;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/configs/src/templates/0-title.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- classes: title -->

# Title
30 changes: 30 additions & 0 deletions packages/configs/src/templates/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
:root {
--color-white: #f5f5f5;
--color-black: #333;
}

html {
/* set the base font-size */
font-size: 62.5%;
}

body {
/* set the default background */
background: var(--color-white);

/* set the default font-color */
color: var(--color-black);
}

/* code blocks */
code[class*='language-'],
pre[class*='language-'] {
font-size: 2rem;
}

/* https://hiroppy.github.io/fusuma/docs/guides/slide-syntax#declaring-section-title */
.section-title {
}

.title {
}
19 changes: 15 additions & 4 deletions packages/webpack/src/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// use `let` for rewire
let path = require('path');
const { existsSync } = require('fs');
const webpack = require('webpack');
const merge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
Expand All @@ -10,11 +11,20 @@ const { babel: babelrc } = require('@fusuma/configs');
const css = require('./css');

const configsEntryPoint = require.resolve('@fusuma/configs');
const configsBasePath = configsEntryPoint.split('/src').slice(0, -1).join('/src');
const configsBasePath = configsEntryPoint
.split('/src')
.slice(0, -1)
.join('/src');
const clientEntryPoint = require.resolve('@fusuma/client');
const clientBasePath = clientEntryPoint.split('/src').slice(0, -1).join('/src');
const clientBasePath = clientEntryPoint
.split('/src')
.slice(0, -1)
.join('/src');
const mdxLoaderEntryPoint = require.resolve('@fusuma/mdx-loader');
const mdxLoaderBasePath = mdxLoaderEntryPoint.split('/src').slice(0, -1).join('/src');
const mdxLoaderBasePath = mdxLoaderEntryPoint
.split('/src')
.slice(0, -1)
.join('/src');

module.exports = (type, { meta, slide, extends: fileExtends, internal = {}, server = {} }) => {
// name is deprecated TODO: delete
Expand Down Expand Up @@ -173,7 +183,8 @@ module.exports = (type, { meta, slide, extends: fileExtends, internal = {}, serv
if (jsPath && jsPath.match(/\+*.js$/i)) {
common.entry.push(path.join(basePath, jsPath));
}
if (cssPath && path.extname(cssPath) === '.css') {

if (cssPath && path.extname(cssPath) === '.css' && existsSync(cssPath)) {
common.entry.push(path.join(clientBasePath, 'src', 'utils', 'customCss.js'));
}
}
Expand Down

0 comments on commit 0d10187

Please sign in to comment.