Skip to content

Commit

Permalink
Get development environment working on non-windows machines and newer…
Browse files Browse the repository at this point in the history
… versions of node
  • Loading branch information
kodie committed Oct 19, 2021
1 parent e077cb0 commit 9667422
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
node_modules
/log
/tmp
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"scripts": {
"copy": "cpx \"src/img/*.*\" dist/img/",
"clean": "if exist dist rmdir dist /s /q && mkdir dist",
"clean": "node task/clean",
"build:css": "lessc src/css/winbox.less src/css/winbox.css",
"build:css:bundle": "node task/bundle --image && lessc --autoprefix=\">=1%\" --csswring=\"--sourcemap --preserve-hacks\" --clean-css=\"--s1 --advanced --rebase\" tmp/bundle.less dist/css/winbox.min.css && csso dist/css/winbox.min.css --output dist/css/winbox.min.css",
"build:css:theme-modern": "lessc --autoprefix=\">=1%\" --csswring=\"--sourcemap --preserve-hacks\" --clean-css=\"--s1 --advanced --rebase\" src/css/themes/modern.less dist/css/themes/modern.min.css && csso dist/css/themes/modern.min.css --output dist/css/themes/modern.min.css",
Expand Down Expand Up @@ -60,7 +60,7 @@
"less": "^4.1.1",
"less-plugin-autoprefix": "^2.0.0",
"less-plugin-clean-css": "^1.5.1",
"less-plugin-csswring": "^0.0.1",
"less-plugin-csswring": "git+https://github.com/kodie/less-plugin-csswring#patch-1",
"svgo": "^2.3.0",
"web-servo": "^0.5.1"
}
Expand Down
13 changes: 8 additions & 5 deletions task/bundle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const { base64Sync } = require('base64-img');
const { writeFileSync, readFileSync } = require('fs');
const fs = require('fs');

fs.existsSync("log") || fs.mkdirSync("log");
fs.existsSync("tmp") || fs.mkdirSync("tmp");

const image = process.argv[2] === "--image";
//const template = process.argv[2] === "--template";
Expand Down Expand Up @@ -30,18 +33,18 @@ const style = process.argv[2] === "--style";
}
}

writeFileSync("tmp/images.less", tmp);
writeFileSync("tmp/bundle.less", '@import "../src/css/winbox.less"; @import "images.less";');
fs.writeFileSync("tmp/images.less", tmp);
fs.writeFileSync("tmp/bundle.less", '@import "../src/css/winbox.less"; @import "images.less";');
}

// ----------------------

if(style){

writeFileSync("tmp/style.js",
fs.writeFileSync("tmp/style.js",

'const style = document.createElement("style");' +
'style.innerHTML = "' + readFileSync("dist/css/winbox.min.css", "utf8").replace(/"/g, "'") + '";' +
'style.innerHTML = "' + fs.readFileSync("dist/css/winbox.min.css", "utf8").replace(/"/g, "'") + '";' +
'const head = document.getElementsByTagName("head")[0];' +
'if(head.firstChild) head.insertBefore(style, head.firstChild); else head.appendChild(style);'
);
Expand Down
26 changes: 26 additions & 0 deletions task/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require("fs");
const path = require("path");

const removeDir = function(path) {
if (fs.existsSync(path)) {
const files = fs.readdirSync(path);

if (files.length > 0) {
files.forEach(function(filename) {
if (fs.statSync(path + "/" + filename).isDirectory()) {
removeDir(path + "/" + filename);
} else {
fs.unlinkSync(path + "/" + filename);
}
});

fs.rmdirSync(path);
} else {
fs.rmdirSync(path);
}
}
}

const distPath = path.join(__dirname, 'dist')

removeDir(distPath);

0 comments on commit 9667422

Please sign in to comment.