-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🦄 Merge PR #49 from luxonauta/remove-gulp-dep
🔥 Remove Gulp
- Loading branch information
Showing
11 changed files
with
130 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.