Skip to content

Commit

Permalink
chore: remove require
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarmarina committed Nov 9, 2024
1 parent f32e75f commit c51a716
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
19 changes: 12 additions & 7 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/usr/bin/env node

const fs = require('fs');
const { program } = require('commander');
const path = require('path');
const pkg = require('../package.json');
import fs from 'fs';
import { program } from 'commander';
import { SassStyleTemplate } from '../lib/index.js';
import path from 'path';
import { fileURLToPath } from 'url';

const SassStyleTemplate = require('../lib/index.js');
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const customTemplate = path.resolve('.sass-template.tmpl');
const pkgPath = path.resolve(__dirname, '../package.json');
const customTemplate = path.resolve(__dirname, '../.sass-template.tmpl');

const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

program
.version(pkg.version, '-v, --version', 'show version number')
Expand All @@ -25,6 +30,6 @@ const template = fs.existsSync(customTemplate)
? fs.readFileSync(customTemplate, 'utf8')
: undefined;

const config = Object.assign({}, program.opts(), { template: template });
const config = Object.assign({}, program.opts(), { template });

new SassStyleTemplate(config);
44 changes: 23 additions & 21 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const fs = require('fs');
const glob = require('glob');
const sass = require('sass');
const path = require('path');
const chokidar = require('chokidar');
const mkdirp = require('mkdirp');
const autoprefixer = require('autoprefixer');
const postcss = require('postcss');
import fs from 'fs';
import path from 'path';
import { globSync } from 'tinyglobby';
import chokidar from 'chokidar';
import { fileURLToPath } from 'url';
import * as sass from 'sass';
import autoprefixer from 'autoprefixer';
import postcss from 'postcss';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.join(__filename, '../..');

const color = {
reset: '\x1b[0m',
Expand All @@ -17,7 +20,7 @@ const color = {

const delimTemplate = /<%\s*content\s*%>/;

class SassStyleTemplate {
export class SassStyleTemplate {
constructor({
markerStart = 'const styles = css`',
markerEnd = '`;',
Expand All @@ -27,7 +30,7 @@ class SassStyleTemplate {
jsFile = 'js',
destination = undefined,
template = fs.readFileSync(
`${__dirname}/../tpls/sass-template.tmpl`,
path.join(__dirname, 'tpls/sass-template.tmpl'),
'utf8'
),
} = {}) {
Expand All @@ -41,7 +44,8 @@ class SassStyleTemplate {
destination,
template,
};
this.globFiles = glob.sync(`{${this.options.customGlob},}`);

this.globFiles = globSync(this.options.customGlob.split(','));

this.init();
}
Expand All @@ -64,16 +68,16 @@ class SassStyleTemplate {
return this._fileInfo;
}

set fileInfo(fileInfo = {}) {
this._fileInfo = fileInfo;
set fileInfo(fileInfo) {
this._fileInfo = fileInfo || {};
}

get globFiles() {
return this._globFiles;
}

set globFiles(files = []) {
this._globFiles = files;
set globFiles(files) {
this._globFiles = files || [];
}

cleanDestinationPath() {
Expand All @@ -87,8 +91,7 @@ class SassStyleTemplate {
if (lastCharacter === path.sep) {
strFinal = strFinal.slice(0, strFinal.length - 1);
}
mkdirp.sync(strFinal);

fs.mkdirSync(strFinal, { recursive: true });
return `${path.resolve(strFinal)}`;
}

Expand Down Expand Up @@ -156,6 +159,7 @@ class SassStyleTemplate {
}

watchSass(glob) {
console.log(`Watching ${glob}`);
const watcher = chokidar.watch(glob, { ignoreInitial: true });

watcher.on('change', () => {
Expand Down Expand Up @@ -194,7 +198,7 @@ class SassStyleTemplate {
}

updateGlob() {
this.globFiles = glob.sync(`{${this.options.customGlob}}`);
this.globFiles = globSync(this.options.customGlob.split(','));
}

globSassFile(cb) {
Expand All @@ -204,9 +208,7 @@ class SassStyleTemplate {
}

init() {
this.watchSass(this.options.customGlob.split(','));
this.watchSass(this.globFiles);
this.globSassFile(this.renderStylesTemplate);
}
}

module.exports = SassStyleTemplate;
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blockquote/sass-style-template",
"version": "3.0.5",
"version": "4.0.0-rc.1",
"description": "SASS and LitElement for creating Web Components",
"keywords": [
"LitElement",
Expand All @@ -19,6 +19,7 @@
"url": "https://github.com/oscarmarina/sass-style-template"
},
"main": "./lib/index.js",
"type": "module",
"bin": {
"sass-style-template": "./bin/index.js"
},
Expand All @@ -28,10 +29,9 @@
},
"dependencies": {
"autoprefixer": "^10.4.20",
"chokidar": "^3.6.0",
"chokidar": "^4.0.1",
"commander": "^12.1.0",
"glob": "^11.0.0",
"mkdirp": "^3.0.1",
"tinyglobby": "^0.2.10",
"postcss": "^8.4.47",
"sass": "^1.80.6"
},
Expand Down

0 comments on commit c51a716

Please sign in to comment.