Skip to content

Commit

Permalink
Merge pull request #9 from revdavethompson/main
Browse files Browse the repository at this point in the history
Add cli and remove manuscript
  • Loading branch information
revdavethompson authored Apr 7, 2023
2 parents 8641cf4 + 4832ba6 commit c724f18
Show file tree
Hide file tree
Showing 24 changed files with 5,545 additions and 1,592 deletions.
Binary file renamed build/.DS_Store → .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Don't include node_modules
node_modules

# Don't include build files
build
14 changes: 12 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
"title:": "The front matter block must start and end with `---`",
"front_matter_title_2": "regex",
"front_matter_regex": "^---(\\n|.)+?---$"
}
}
},
"MD033":false,
"MD007": {
"indent": 4
},
"MD024":false
},
"editor.hover.delay": 1500,
"workbench.colorTheme": "Default Dark+",
"editor.fontFamily": "Inter, Monaco, 'Courier New', monospace",
"editor.fontSize": 14,
"editor.fontWeight": "500"
}
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Changelog

## [0.2.0] - 2023-3-17

### Added

* Themes
* `./manuscript/theme` directory will now be the default location for themes. The hope is to provide a consistent structure for themeing that can simply be dropped into the manuscript/ folder.
* current structure is:
```markdown
theme/
|--BOOM!-README // README describing theme
|--css/styles.css // Main Stylesheet
|--fonts/ // Additional Fonts
|--media/ // Any other media to include: imgs/vids/etc
```

### Changed

* Unified Pipeline
* Removed rehype from the pipeline for simplicity
* using rehype was making things more complicated
* found a way to accomplish the same thing with less packages/code
* Employing a new convention for referencing issues
* - Fixed a bug that caused the app to crash when clicking the "Submit" button. ([#1234])


* Following the [GitHub guidelines](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-to-issues-and-pull-requests#linking-to-issues-in-your-information-resources):
```markdown
[#1234]: <https://github.com/your-username/your-repo/issues/1234>
```

### Fixed

* Spaces or indentation before @includes caused them to be ignored.
* This was a problem with includerJS
* The includerjs package was updated to latest version that included a mod to the RegExp used to discover @includes. Blank spaces are now ignored.

### Removed

* `lib/plugins`
* Included directive plugin within the `convert.js` module for simplicity
* May abstract this in the future, back to having a plugin/ folder where custom directives can be added back in
13 changes: 0 additions & 13 deletions NOTES.md

This file was deleted.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ Bookhsop is a markdown-based book publishing framework for small firms, allowing

* Composing the source of a manuscript in markdown.
* With the ability to extend the markdown language with custom formatting (GFM, Custom Comments, etc.)Able to be extended with additional

## Developer Notes

* bookshop is CommonJS by default, but runs its main libraries as ES Modules by adding .mjs as needed.
* As a general rule, we've attempted to use ES Modules whenever possible.
* This is done to ensure compatibility with legacy modules, like browser-sync, which is used when writing your manuscript with live previews in the browser.
7 changes: 0 additions & 7 deletions book.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions bs-config.js

This file was deleted.

19 changes: 0 additions & 19 deletions build/html/index.html

This file was deleted.

143 changes: 143 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/usr/bin/env node

// cli.js
import fs from 'fs';
import { fileURLToPath } from 'url';
import { Command } from 'commander';
import convert from './lib/convert.js';
import path from 'path';
import nodemon from 'nodemon';
import { readFileSync, existsSync } from 'fs';
import { spawn } from 'child_process';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8'));

const manuscriptDir = path.join(process.cwd(), 'manuscript');

const program = new Command();
program.version(packageJson.version);

async function buildHtml(manuscriptDir, outputDir, outputType) {
await convert(manuscriptDir, outputDir, outputType);
}

async function buildPdf(manuscriptDir, outputDir, outputType) {
await buildHtml(manuscriptDir, outputDir, outputType);

// Run the prince command-line tool
const prince = spawn('prince', ['build/pdf/index.html'], { stdio: 'inherit' });

prince.on('error', (error) => {
console.error(`Error: ${error.message}`);
});

return prince;
}

program
.command('build')
.option('-t, --type <type>', 'Specify the output type (html or pdf)', 'html')
.description('Build the output from the manuscript markdown files')
.action(async (options) => {
console.log(`Building ${options.type.toUpperCase()}...`);

if (options.type === 'html') {
await buildHtml(manuscriptDir, path.join(process.cwd(), 'build', 'html'), options.type);
} else if (options.type === 'pdf') {
await buildPdf(manuscriptDir, path.join(process.cwd(), 'build', 'pdf'), options.type);
} else {
console.error('Invalid output type specified. Use either "html" or "pdf".');
}
});

program
.command('dev')
.option('-t, --type <type>', 'Specify the output type (html or pdf)', 'html')
.description('Run the development server with live-reloading')
.action(async (options) => {
console.log(`Running Nodemon and Webpack Server for ${options.type.toUpperCase()}...`);

if (options.type === 'html') {
await buildHtml(manuscriptDir, path.join(process.cwd(), 'build', 'html'), options.type);
await runWebpackDevServerAsync('html');
await runNodemonAsync('html');
} else if (options.type === 'pdf') {
await buildPdf(manuscriptDir, path.join(process.cwd(), 'build', 'pdf'), options.type);
await runWebpackDevServerAsync('pdf');
await runNodemonAsync('pdf');
} else {
console.error('Invalid output type specified. Use either "html" or "pdf".');
}
});

// Setup nodemon function to return as a Promise
function runNodemonAsync(outputType) {
return new Promise((resolve, reject) => {
runNodemon(outputType).on('quit', resolve).on('error', reject);
});
}

// Run the webpack server using the user's webpack.config.js
function runWebpackDevServerAsync(outputType) {
const server = spawn(
'npx',
['webpack', 'serve', '--env', `outputType=${outputType}`],
{ stdio: 'inherit' }
);

server.on('error', (error) => {
console.error(`Error: ${error.message}`);
});

return server;
}

// Use Nodemon to watch for changes and rebuild/serve/refresh

// Helper function to validate the user's nodemon.json file
function validateUserNodemonConfig(config) {
if (!config || !config.execMap || !config.execMap.html) {
return false;
}
return true;
}

function runNodemon(outputType) {
const userNodemonConfigPath = path.join(process.cwd(), 'nodemon.json');
let nodemonConfig = {};

// Check if the user's nodemon.json file exists
if (existsSync(userNodemonConfigPath)) {
const userNodemonConfig = JSON.parse(readFileSync(userNodemonConfigPath, 'utf-8'));

// Validate the user's nodemon.json configuration
if (validateUserNodemonConfig(userNodemonConfig)) {
nodemonConfig = { configFile: userNodemonConfigPath };
}
}

// If the user's nodemon.json file is not found or is not valid, use default settings
if (!nodemonConfig.configFile) {
console.log(`Using default Nodemon settings with outputType: ${outputType}.`);
nodemonConfig = {
script: __filename,
ext: outputType === 'pdf' ? 'md,mdx,js,ejs,json,html,css,yaml' : 'md,mdx,js,ejs,json,html,css,yaml',
exec: `bookshop build --type ${outputType}`,
watch: 'manuscript',
};
}

return nodemon(nodemonConfig).on('restart', async () => {
console.log(`Rebuilding ${outputType.toUpperCase()}...`);
if (outputType === 'html') {
await buildHtml(manuscriptDir, path.join(process.cwd(), 'build', 'html'), outputType);
} else if (outputType === 'pdf') {
await buildPdf(manuscriptDir, path.join(process.cwd(), 'build', 'pdf'), outputType);
}
});
}


program.parseAsync(process.argv);
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import convert from './lib/convert.js';

convert();
3 changes: 0 additions & 3 deletions index.mjs

This file was deleted.

Loading

0 comments on commit c724f18

Please sign in to comment.