Skip to content

Commit

Permalink
feat: add option to suppress reload info output
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarmarina committed Nov 29, 2024
1 parent 03a38c1 commit 7f6a0fc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ version(pkg.version, '-v, --version', 'show version number')
.option('-c, --css-file', 'generate a CSS file instead of JS or TS')
.option('-wo, --wo-suffix', 'without suffix string `-styles`')
.option('-j, --js-file <string>', 'file extension')
.option('-d, --destination <string>', 'location of the output file');
.option('-d, --destination <string>', 'location of the output file')
.option('-hr, --hide-reload', 'no reload info output');
```

### Typescript (--js-file option)
Expand Down Expand Up @@ -235,6 +236,10 @@ export const styles = css`<% content %>`;

> location of the output file : `undefined`
##### --hide-reload (-hr)

> suppress reload info output : `false`
---

### Example:
Expand Down
3 changes: 2 additions & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ program
.option('-c, --css-file', 'generate a CSS file instead of JS or TS')
.option('-wo, --wo-suffix', 'without suffix string `-styles`')
.option('-j, --js-file <string>', 'file extension')
.option('-d, --destination <string>', 'location of the output file');
.option('-d, --destination <string>', 'location of the output file')
.option('-hr, --hide-reload', 'suppress reload info output');

program.parse(process.argv);

Expand Down
19 changes: 12 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ class FileHandler {
* @param {string} fileName - The name of the file.
* @param {string} cssResult - The CSS content to write.
*/
async writeTemplate(fileName, cssResult) {
async writeTemplate(fileName, cssResult, hideReload=false) {
try {
await fs.writeFile(fileName, cssResult, 'utf8');
console.info(
`${color.BrightCyan}[sass]${color.green} reload ${color.grey}${fileName}${color.reset}`
);
if (!hideReload) {
console.info(
`${color.BrightCyan}[sass]${color.green} reload ${color.grey}${fileName}${color.reset}`
);
}
} catch (error) {
console.error(`Error writing template to file ${fileName}:`, error);
}
Expand All @@ -101,6 +103,7 @@ export class SassStyleTemplate {
* @param {boolean} [options.woSuffix] - Whether to omit the suffix.
* @param {string} [options.jsFile='js'] - The JavaScript file extension.
* @param {string} [options.destination] - The destination directory.
* @param {boolean} [options.hideReload = false] - suppress reload info output.
* @param {string} [options.template=''] - The template content.
* @param {SassProcessor} [options.sassProcessor=new SassProcessor()] - The SASS processor instance.
* @param {CssProcessor} [options.cssProcessor=new CssProcessor()] - The CSS processor instance.
Expand All @@ -114,6 +117,7 @@ export class SassStyleTemplate {
woSuffix = undefined,
jsFile = 'js',
destination = undefined,
hideReload = false,
template = '',
sassProcessor = new SassProcessor(),
cssProcessor = new CssProcessor(),
Expand All @@ -127,6 +131,7 @@ export class SassStyleTemplate {
woSuffix,
jsFile,
destination,
hideReload,
template,
};
this.sassProcessor = sassProcessor;
Expand Down Expand Up @@ -192,7 +197,7 @@ export class SassStyleTemplate {

const fileNameStyle = `${this.fileInfo.fileDir}/${this.fileInfo.fileNameWithoutExt}${this.fileInfo.fileExt}`;
if (this.options.cssFile) {
return this.fileHandler.writeTemplate(fileNameStyle, cssResult);
return this.fileHandler.writeTemplate(fileNameStyle, cssResult, this.options.hideReload);
}

try {
Expand All @@ -209,7 +214,7 @@ export class SassStyleTemplate {
0,
startReplacePosition + this.options.markerStart.length
)}${cssResult}${this.options.markerEnd}\n`;
return this.fileHandler.writeTemplate(fileNameStyle, content);
return this.fileHandler.writeTemplate(fileNameStyle, content, this.options.hideReload);
} else {
throw new Error(
`${color.red}No found marker start "${this.options.markerStart}" in file.${color.reset}`
Expand All @@ -218,7 +223,7 @@ export class SassStyleTemplate {
}

const content = this.options.template.replace(delimTemplate, cssResult);
return this.fileHandler.writeTemplate(fileNameStyle, content);
return this.fileHandler.writeTemplate(fileNameStyle, content, this.options.hideReload);
} catch (error) {
console.error(`Error processing file ${fileNameStyle}:`, error);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blockquote/sass-style-template",
"version": "4.0.3",
"version": "4.1.0",
"description": "A SCSS watcher with autoprefixer for building Web Components using Lit and SASS.",
"keywords": [
"lit",
Expand Down

0 comments on commit 7f6a0fc

Please sign in to comment.