Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit 4d8a45e

Browse files
committed
feat(debug): enabling debug log environment variable
1 parent c842ba6 commit 4d8a45e

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/cli.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22
import chalk from 'chalk';
33
import * as commandLineArgs from 'command-line-args';
4+
import './verbose';
45

56
/**
67
* Supported output style. Mirrors `style_option_strings[]` in sassc
@@ -34,6 +35,17 @@ const optionDefinitions = [
3435
{ name: 'help', alias: 'h', description: 'Display this help message.', type: Boolean }
3536
];
3637

38+
/**
39+
* Definitions of help display for command line options.
40+
*/
41+
const helpDefinitions = [
42+
{ header: chalk.reset('Options'), optionList: optionDefinitions },
43+
{
44+
header: chalk.reset('Enabling verbose debug log'),
45+
content: [`Set 'DEBUG' environment variable to any to enable debug log`, '$ DEBUG=* sass ...']
46+
}
47+
];
48+
3749
/**
3850
* Get usage definition for library version.
3951
*
@@ -43,29 +55,29 @@ const buildDisplayVersion = async () => {
4355
const sassFactory = await loadModule();
4456
const { libsassAsm, libsass, sassLang, sass2scss } = await sassFactory.getVersion();
4557

46-
return {
47-
header: chalk.reset('Version'),
48-
content: [
49-
{ name: 'libsass-asm', summary: libsassAsm },
50-
{ name: 'libsass', summary: libsass },
51-
{ name: 'sass', summary: sassLang },
52-
{ name: 'sass2scss', summary: sass2scss }
53-
]
54-
};
58+
return [
59+
{
60+
header: chalk.reset('Version'),
61+
content: [
62+
{ name: 'libsass-asm', summary: libsassAsm },
63+
{ name: 'libsass', summary: libsass },
64+
{ name: 'sass', summary: sassLang },
65+
{ name: 'sass2scss', summary: sass2scss }
66+
]
67+
}
68+
];
5569
};
5670

5771
(async () => {
5872
const options = commandLineArgs(optionDefinitions, { camelCase: true });
59-
73+
//(options as any).test();
6074
const displayHelp = options.help || Object.keys(options).length === 0;
6175
const displayVersion = options.version;
6276

6377
if (displayHelp || displayVersion) {
6478
const cmdUsage = await import('command-line-usage');
65-
const usageDefinition = displayHelp
66-
? { header: chalk.reset('Options'), optionList: optionDefinitions }
67-
: await buildDisplayVersion();
68-
const usage = cmdUsage([usageDefinition]);
79+
const usageDefinition = displayHelp ? helpDefinitions : await buildDisplayVersion();
80+
const usage = cmdUsage([...usageDefinition]);
6981
console.log(usage);
7082
return;
7183
}

src/verbose.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** side effect module to enable few verbose logging */
2+
/* tslint:disable:no-var-requires no-require-imports */
3+
if (!!process.env.DEBUG) {
4+
require('source-map-support').install();
5+
const { log, enableLogger } = require('./util/logger');
6+
enableLogger(require('debug')('libsass:logger'));
7+
log('Enabling verbose log');
8+
}

0 commit comments

Comments
 (0)