Skip to content

Commit

Permalink
🚚 restructure source file tree (#136)
Browse files Browse the repository at this point in the history
This restructures sources file tree into something hopefully easier to understand:
- `src/app`: source code for the web app that embeds training material
- `src/build`: source code that builds the previously mentioned app, including the training material
- `src/pdf`: source code that builds PDFs from the training material
- `src/cli`: source code for the CLI

🚚 Moved files:
- `bin/webpack.config*` -> `src/build/`
- `bin/sensei.js` -> `src/cli/cli.js`
- `src/loaders` -> `src/build/loaders`
- `src/{slides,labs,index.*,*.js,assets}` -> `src/app/`

🔥 Removed files: build.sh (not very useful), run.sh (duplicated in readme), Makefile (duplicate of the other two)
  • Loading branch information
hgwood authored Jan 20, 2022
1 parent 1e5e3c0 commit ed10b98
Show file tree
Hide file tree
Showing 39 changed files with 48 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ WORKDIR /training-material

USER chrome

ENTRYPOINT [ "/app/bin/sensei.js" ]
ENTRYPOINT [ "node", "/app/src/cli/cli.js" ]
CMD ["serve"]
8 changes: 0 additions & 8 deletions Makefile

This file was deleted.

33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ using a simpler and newer stack. It's not up-to-par in terms of features, but it

> ⚠ If you expect to use this alias within Git Bash for Windows, you might need
> to set `MSYS_NO_PATHCONV` to `1` to disable path conversion on the volume paths.
> This avoids the `C:/Program Files/Git/...: no such file or directory` type of
> errors.
> This avoids the `C:/Program Files/Git/...: no such file or directory` type of
> errors.

### Using a Docker image built from sources 🐳

Expand All @@ -45,7 +45,9 @@ using a simpler and newer stack. It's not up-to-par in terms of features, but it

- Install with `npm install --global https://github.com/Zenika/sensei`

> ⚠ You may use Yarn, however it's been to known to have cache issues when installing packages from GitHub, resulting in failures to update sensei correctly.
> ⚠ You may use Yarn, however it's been known to have cache issues when
> installing packages from GitHub, resulting in failures to update sensei
> correctly.
## Usage
Expand All @@ -59,8 +61,6 @@ Run `sensei --help` for available commands and options.
- Run `sensei pdf`
- PDFs are generated inside `pdf` folder
⚠️ Note about slide sizing and PDF rendering: to avoid any layout inconsistencies, the `width` and `height` values present in [src/slides/slides.js](src/slides/slides.js) file must match the values of the `--size` parameter in the `slides` npm script
### Serving the slides and labs
- `cd` into a training material folder (must have `Slides/slides.json` and `Workbook/parts.json`)
Expand All @@ -77,3 +77,26 @@ The following plugins are enabled:
- Math
Refer to [Reveal's documentation](https://revealjs.com/plugins/#built-in-plugins) for usage.

## Development

### Running

Install dependencies (`npm i`) then use `npm start --` to run the CLI (eg `npm
start -- serve --material=./training-material` where `./training-material`
points to directory with training material in it). You may alternatively use
`npm run dev --` instead to enable restart on change (eg `npm run dev -- serve
--material=./training-material`).

### Source file structure

- `src/app`: source code for the web app that embeds training material
- `src/build`: source code that builds the previously mentioned web app,
including the training material
- `src/pdf`: source code that builds PDFs from the training material
- `src/cli`: source code for the CLI

### Code formating

This project uses Prettier. Don't forget to format before committing! You may
use `npm run prettier:write` to do that.
3 changes: 0 additions & 3 deletions build.sh

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"prettier:write": "npm run prettier -- --write",
"test": "node test.js",
"test:watch": "nodemon test.js --ignore dist",
"start": "node bin/sensei.js",
"dev": "nodemon --watch src/loaders --watch bin bin/sensei.js"
"start": "node src/cli/cli.js",
"dev": "nodemon --watch src/build --watch src/cli src/cli/cli.js"
},
"bin": {
"sensei": "bin/sensei.js"
"sensei": "src/cli/cli.js"
},
"dependencies": {
"css-loader": "6.5.1",
Expand Down
12 changes: 0 additions & 12 deletions run.sh

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions bin/webpack.config.js → src/build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ module.exports = (env = {}, argv = {}) => {
return {
mode: argv.mode || "development",
entry: {
index: path.resolve(__dirname, "../src/index.js"),
slides: path.resolve(__dirname, `../src/slides/${slidesEntry}.js`),
labs: path.resolve(__dirname, "../src/labs/labs.js"),
index: path.resolve(__dirname, "../app/index.js"),
slides: path.resolve(__dirname, `../app/slides/${slidesEntry}.js`),
labs: path.resolve(__dirname, "../app/labs/labs.js"),
},
module: {
rules: [
{
test: [/slides\.json$/, /parts\.json$/],
type: "javascript/auto",
use: path.resolve(__dirname, "../src/loaders/slides-json-loader"),
use: path.resolve(__dirname, "./loaders/slides-json-loader"),
},
{
test: /[\/\\]Slides[\/\\].+\.md$/,
use: [
require.resolve("html-loader"),
{
loader: path.resolve(
path.join(__dirname, "../src/loaders/revealjs-loader")
path.join(__dirname, "./loaders/revealjs-loader")
),
options: { materialVersion },
},
Expand Down Expand Up @@ -112,19 +112,19 @@ module.exports = (env = {}, argv = {}) => {
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "../src/index.html"),
template: path.resolve(__dirname, "../app/index.html"),
chunks: ["index"],
filename: "index.html",
...commonPluginOptions,
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "../src/slides/slides.html"),
template: path.resolve(__dirname, "../app/slides/slides.html"),
chunks: ["slides"],
filename: "slides.html",
...commonPluginOptions,
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "../src/labs/labs.html"),
template: path.resolve(__dirname, "../app/labs/labs.html"),
chunks: ["labs"],
filename: "labs.html",
...commonPluginOptions,
Expand Down
File renamed without changes.
17 changes: 6 additions & 11 deletions bin/sensei.js → src/cli/cli.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fork = require("child_process").fork;
const fs = require("fs");
const path = require("path");
const WebpackDevServer = require("webpack-dev-server");
const webpackConfig = require("./webpack.config");
const webpackConfig = require("../build/webpack.config");
const webpack = require("webpack");
const yargs = require("yargs/yargs");

Expand Down Expand Up @@ -98,9 +98,7 @@ async function pdf(options) {
function pdfSlides({ slug, slideWidth, slideHeight, port }) {
return new Promise((resolve, reject) => {
const child = spawn("node", [
path.resolve(
path.join(__dirname, "../node_modules/decktape/decktape.js")
),
require.resolve("decktape"),
"reveal",
"-p",
"0",
Expand Down Expand Up @@ -137,13 +135,10 @@ function pdfSlides({ slug, slideWidth, slideHeight, port }) {

function pdfLabs({ slug, port }) {
return new Promise((resolve, reject) => {
const child = fork(
path.resolve(path.join(__dirname, "../src/pdf/pdf.js")),
[
`http://localhost:${port}/labs.html`,
`./pdf/Zenika-${slug}-Workbook.pdf`,
]
);
const child = fork(path.resolve(__dirname, "../pdf/pdf.js"), [
`http://localhost:${port}/labs.html`,
`./pdf/Zenika-${slug}-Workbook.pdf`,
]);

child.on("exit", function (code) {
if (code !== 0) {
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require("./src/loaders/slides-json-loader.test.js");
require("./bin/webpack.config.test.js");
require("./src/build/loaders/slides-json-loader.test.js");
require("./src/build/webpack.config.test.js");

0 comments on commit ed10b98

Please sign in to comment.