-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from revdavethompson/main
Add cli and remove manuscript
- Loading branch information
Showing
24 changed files
with
5,545 additions
and
1,592 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import convert from './lib/convert.js'; | ||
|
||
convert(); |
Oops, something went wrong.