Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions docs/userGuide/cliCommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@ An overview of MarkBind's Command Line Interface (CLI) can be referenced with `m
```
$ markbind --help
Usage: markbind <command>

Options:
-V, --version output the version number
-h, --help output usage information

Commands:
init|i [options] [root] init a markbind website project
serve|s [options] [root] build then serve a website from a directory
build|b [options] [root] [output] build a website
deploy|d [options] [root] deploy the latest build of the site to the repo's Github pages

Options:
-V, --version output the version number
-h, --help display help for command

Setup Commands
init|i [options] [root] init a markbind site

Site Commands
serve|s [options] [root] Build then serve a website from a directory
build|b [options] [root] [output] Build a website
deploy|d [options] [root] Deploy the latest build of the site to GitHub Pages

Commands:
help [command] display help for command
```
<hr><!-- ========================================================================== -->
<div id="markbind-init">
Expand Down Expand Up @@ -132,6 +137,9 @@ The caveat is that not building all pages during the initial process, or not reb
* `-p <port>`, `--port <port>`<br>
Serve the website in the specified port (Default is 8080).

* `-v`, `--verbose`<br>
Enable verbose logging. This is useful for diagnosing page-specific errors (e.g., Vue rendering warnings) by showing which page is currently being processed.

{{ icon_examples }}
* `markbind serve` : Serves the site from the current working directory.
* `markbind serve ./myWebsite` : Serves the site from the `./myWebsite` directory.
Expand Down Expand Up @@ -171,6 +179,9 @@ The caveat is that not building all pages during the initial process, or not reb
Specify the site config file (default: `site.json`)<br>
{{ icon_example }} `-s otherSite.json`

* `-v`, `--verbose`<br>
Enable verbose logging. This is useful for diagnosing page-specific errors (e.g., Vue rendering warnings) by showing which page is currently being processed.

**{{ icon_examples }}**
* `markbind build` : Generates the site from the current working directory.
* `markbind build ./myWebsite` : Generates the site from the `./myWebsite` directory.
Expand Down Expand Up @@ -210,6 +221,9 @@ The caveat is that not building all pages during the initial process, or not reb
Specify the site config file (default: `site.json`).<br>
{{ icon_example }} `-s otherSite.json`

* `-v`, `--verbose`<br>
Enable verbose logging. This is useful for diagnosing page-specific errors during the build phase of deployment.

%%{{ icon_info }} Related: [User Guide: Deploying the Website](deployingTheSite.html).%%

**{{ icon_examples }}**
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ program
program.createOption('-a, --address <address>', 'specify the server address/host (Default is 127.0.0.1)'))
.addOption(
program.createOption('-s, --site-config <file>', 'specify the site config file (default: site.json)'))

// Development mode is hidden as it is not user facing and only works during local development
.addOption(
program.createOption('-v, --verbose', 'enable verbose logging (e.g., page building logs)'))
// Development mode is hidden as it is not user facing and only works in local development environment
.addOption(
new Option('-d, --dev', 'development mode, enabling live & hot reload for frontend source files.')
.hideHelp())
Expand All @@ -101,6 +102,7 @@ program
.option('--baseUrl [baseUrl]',
'optional flag which overrides baseUrl in site.json, leave argument empty for empty baseUrl')
.option('-s, --site-config <file>', 'specify the site config file (default: site.json)')
.option('-v, --verbose', 'enable verbose logging (e.g., page building logs)')
.summary('Build a website')
.description('Build a website')
.action((userSpecifiedRoot, output, options) => {
Expand All @@ -113,6 +115,7 @@ program
.option('-c, --ci [githubTokenName]', 'deploy the site in CI Environment [GITHUB_TOKEN]')
.option('-n, --no-build', 'do not automatically build the site before deployment')
.option('-s, --site-config <file>', 'specify the site config file (default: site.json)')
.option('-v, --verbose', 'enable verbose logging (e.g., page building logs)')
.summary('Deploy the latest build of the site to GitHub Pages')
.description('Deploy the latest build of the site to the repo\'s GitHub Pages')
.action((userSpecifiedRoot, options) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/cmd/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import * as cliUtil from '../util/cliUtil.js';
import * as logger from '../util/logger.js';

function build(userSpecifiedRoot: string, output: string, options: any) {
if (options.verbose) {
logger.useVerboseConsole();
}

// if --baseUrl contains no arguments (options.baseUrl === true) then set baseUrl to empty string
const baseUrl = _.isBoolean(options.baseUrl) ? '' : options.baseUrl;

Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/cmd/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import * as logger from '../util/logger.js';

function deploy(userSpecifiedRoot: string, options: any) {
let rootFolder;
if (options.verbose) {
logger.useVerboseConsole();
}
try {
rootFolder = cliUtil.findRootFolder(userSpecifiedRoot, options.siteConfig);
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/cmd/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ function questionAsync(question: string): Promise<string> {
function serve(userSpecifiedRoot: string, options: any) {
if (options.dev) {
logger.useDebugConsole();
} else if (options.verbose) {
logger.useVerboseConsole();
}

let rootFolder;
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function useDebugConsole(): void {
consoleTransport.level = 'debug';
}

function useVerboseConsole(): void {
consoleTransport.level = 'verbose';
}
Comment on lines +33 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had some concerns with using consoleTransport as a module level global variable but ig it's fine for our use case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think so


const dailyRotateFileTransport = new DailyRotateFile({
format: fileFormat,
datePattern: 'YYYY-MM-DD',
Expand Down Expand Up @@ -60,6 +64,7 @@ export {

export {
useDebugConsole,
useVerboseConsole,
};

// eslint-disable-next-line no-console
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ export class Page {
*/
async generate(externalManager: ExternalManager) {
this.resetState(); // Reset for live reload

const fileConfig: NodeProcessorConfig = {
baseUrl: this.siteConfig.baseUrl,
ignore: this.siteConfig.ignore,
Expand Down Expand Up @@ -594,6 +593,7 @@ export class Page {
* However, for automated testings (e.g. snapshots), we will output the pre SSR-processed HTML content
* as we want to retain the unrendered DOM for easier reference and checking.
*/
logger.verbose(`Rendering page: ${this.pageConfig.sourcePath}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the only instance where we are using verbose logging?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeap, for now it is the only use of verbose logging

const vueSsrHtml = await pageVueServerRenderer.renderVuePage(renderFn);
this.filterIconAssets(content, vueSsrHtml);
if (process.env.TEST_MODE) {
Expand Down
40 changes: 10 additions & 30 deletions packages/core/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,28 @@ winston.configure({
transports: [consoleTransport],
});

// create a wrapper for error messages
const errorWrap = (input: any) => {
const createLoggerThatInterruptsProgressBar = (level: string) => (...args: any[]) => {
if (progressBar) {
progressBar.interruptBegin();
winston.error(input);
(winston as any).log(level, ...args);
progressBar.interruptEnd();
} else {
winston.error(input);
(winston as any).log(level, ...args);
}
};

// create a wrapper for warning messages
const warnWrap = (input: any) => {
if (progressBar) {
progressBar.interruptBegin();
winston.warn(input);
progressBar.interruptEnd();
} else {
winston.warn(input);
}
};

// create a wrapper for info messages
const infoWrap = (input: any) => {
if (progressBar) {
progressBar.interruptBegin();
winston.info(input);
progressBar.interruptEnd();
} else {
winston.info(input);
}
};

const { debug } = winston;
const { verbose } = winston;
const errorWrap = createLoggerThatInterruptsProgressBar('error');
const warnWrap = createLoggerThatInterruptsProgressBar('warn');
const infoWrap = createLoggerThatInterruptsProgressBar('info');
const verboseWrap = createLoggerThatInterruptsProgressBar('verbose');
const debugWrap = createLoggerThatInterruptsProgressBar('debug');
Comment on lines +31 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice abstraction


export {
errorWrap as error,
warnWrap as warn,
infoWrap as info,
verbose,
debug,
verboseWrap as verbose,
debugWrap as debug,
setProgressBar,
removeProgressBar,
};
Loading