Skip to content

Commit

Permalink
🦄 Merge PR #49 from luxonauta/remove-gulp-dep
Browse files Browse the repository at this point in the history
🔥 Remove Gulp
  • Loading branch information
luxonauta committed Jan 15, 2024
2 parents 674ce29 + 90c22f9 commit 4049317
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ We recommend that you first [suggest your feature idea in our discussion forums]

[`dev`](https://github.com/luxonauta/luxacss/tree/dev) branch is open to pull requests.

**Do not edit [`/dist`](https://github.com/luxonauta/luxacss/tree/master/dist) files directly.** Edit the source files in [`/sass`](https://github.com/luxonauta/luxacss/tree/master/sass), then recompile the [`/dist`](https://github.com/luxonauta/luxacss/tree/master/dist) files with `npm run gulp`.
**Do not edit [`/dist`](https://github.com/luxonauta/luxacss/tree/master/dist) files directly.** Edit the source files in [`/sass`](https://github.com/luxonauta/luxacss/tree/master/sass), then recompile the [`/dist`](https://github.com/luxonauta/luxacss/tree/master/dist) files with `npm build`.
4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

118 changes: 118 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import fs from "fs";
import * as sass from "sass";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
import chokidar from "chokidar";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const sassFilePath = join(__dirname, "sass", "luxa.scss");

const outputDir = join(__dirname, "dist");
const minifiedOutputPath = join(outputDir, "compressed", "luxa.min.css");
const expandedOutputPath = join(outputDir, "expanded", "luxa.css");

const log = async (type, message) => {
const timestamp = new Date().toLocaleTimeString("pt-BR", {
hour: "2-digit",
minute: "2-digit",
hour12: false,
});

let typeTag;

switch (type) {
case "info":
typeTag = "ℹ️ Info";
break;
case "error":
typeTag = "💩 Error";
break;
case "success":
typeTag = "✅ Success";
break;
default:
typeTag = "🪵 Log";
}

console.log(`${timestamp} ${typeTag}: ${message}`);
};

const ensureDirectoryExistence = async (filePath) => {
const dir = dirname(filePath);
try {
await fs.promises.access(dir, fs.constants.F_OK);
} catch {
await fs.promises.mkdir(dir, { recursive: true });
}
};

const compileSass = async (filePath, outputPath, options) => {
try {
const result = sass.compile(filePath, {
style: options.minify ? "compressed" : "expanded",
sourceMap: options.sourceMap,
});

ensureDirectoryExistence(outputPath);

let cssData = result.css;
if (typeof cssData !== "string") {
cssData = JSON.stringify(cssData);
}
await fs.promises.writeFile(outputPath, cssData, "utf8");

if (options.sourceMap && result.sourceMap) {
let sourceMapData = result.sourceMap;
if (
typeof sourceMapData !== "string" &&
!Buffer.isBuffer(sourceMapData)
) {
sourceMapData = JSON.stringify(sourceMapData);
}
await fs.promises.writeFile(`${outputPath}.map`, sourceMapData, "utf8");
}

log("success", `Sass compiled to ${outputPath}`);
} catch (error) {
log("error", `Error compiling Sass: ${error}`);
}
};

const run = async () => {
try {
await compileSass(sassFilePath, minifiedOutputPath, {
minify: true,
sourceMap: false,
});
await compileSass(sassFilePath, expandedOutputPath, {
minify: false,
sourceMap: true,
});

log("success", "Compilation process completed successfully.");
} catch (error) {
log("error", `Error in the compilation process: ${error}`);
}
};

const watchFiles = () => {
log("info", "Observing changes in files...");

const watcher = chokidar.watch(join(__dirname, "sass"), {
ignored: /^\./,
persistent: true,
});

watcher.on("change", (path) => {
log("info", `File ${path} was changed, recompiling...`);
run();
});
};

run()
.then(watchFiles)
.catch((error) => {
log("error", `Error in the overall process: ${error}`);
});
1 change: 0 additions & 1 deletion dist/compressed/luxa.css

This file was deleted.

1 change: 1 addition & 0 deletions dist/compressed/luxa.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions dist/expanded/luxa.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ body {
}

html {
-webkit-text-size-adjust: 100%;
-moz-text-size-adjust: 100%;
text-size-adjust: 100%;
text-size-adjust: 100%;
font-size: var(--base-size);
font-variation-settings: normal;
}
Expand Down Expand Up @@ -436,4 +434,3 @@ hr {
visibility: hidden;
}
}
/*# sourceMappingURL=maps/luxa.css.map */
1 change: 1 addition & 0 deletions dist/expanded/luxa.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dist/expanded/maps/luxa.css.map

This file was deleted.

50 changes: 0 additions & 50 deletions gulpfile.mjs

This file was deleted.

19 changes: 5 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "luxacss",
"version": "1.0.4",
"version": "1.0.5",
"description": "A minimalist CSS framework",
"author": "luxonauta",
"license": "MIT",
Expand All @@ -15,22 +15,13 @@
"main": "dist/compressed/luxa.css",
"type": "module",
"scripts": {
"gulp": "gulp",
"prepare": "husky install"
"build": "node build.js",
"format": "prettier --write ."
},
"devDependencies": {
"autoprefixer": "^10.4.16",
"gulp-postcss": "^9.0.1",
"gulp-sass": "^5.1.0",
"gulp-sourcemaps": "^3.0.0",
"gulp": "^4.0.2",
"husky": "^8.0.3",
"lint-staged": "^15.0.2",
"chokidar": "^3.5.3",
"prettier": "3.0.3",
"sass-embedded": "^1.69.5"
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
"sass": "^1.69.7"
},
"keywords": [
"clean-code",
Expand Down
Loading

0 comments on commit 4049317

Please sign in to comment.