Skip to content

Commit

Permalink
move 'themes' task to node script
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Dec 9, 2019
1 parent 6efa67f commit fd356f8
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 123 deletions.
105 changes: 0 additions & 105 deletions Gruntfile.js
Expand Up @@ -31,34 +31,6 @@ module.exports = function(grunt) {
return data;
}

function processJupyterFiles() {
const files = grunt.file.expand({
filter: "isFile",
cwd: "themes/jupyter"
}, ["*"]);
files.forEach(file => {
const theme = grunt.file.read(`themes/jupyter/${file}`);
grunt.file.write(`themes/jupyter/${file}`, replaceCSSMatches(theme));
});
}

// :any() has been deprecated, and :matches() is not fully supported
// this is a simple replace method.. it'll handle `:matches .selector`, but
// not `selector :matches()`
// `:matches()` renamed to `:is()`
// see https://developer.mozilla.org/en-US/docs/Web/CSS/:is
function replaceCSSMatches(theme) {
return theme.replace(/:is\(([^)]+)\)\s([^,{]+)(,|{)/gm, (_, matches, selector, separator) => {
let result = "";
const m = matches.split(/\s*,\s*/);
const last = m.length - 1;
m.forEach((match, index) => {
result += `${match} ${selector.trim()}${index >= last && separator === "{" ? " {" : ", "}`;
});
return result;
});
}

// modified from http://stackoverflow.com/a/5624139/145346
function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
Expand Down Expand Up @@ -201,69 +173,9 @@ module.exports = function(grunt) {
options: {replacements: "<%= config.replacements %>"}
}
},
clean: {
cssmins: {
src: [
// don't clean combined theme files (older method) until
// we can be assured that everyone has updated GitHub-Dark-Script
// "themes/*.min.css",
"themes/**/*.min.css"
]
}
},
exec: {
usercss: "node tools/usercss.js",
},
cssmin: {
codemirror: {
files: [{
expand: true,
cwd: "themes/src/codemirror/",
src: "*.css",
dest: "themes/codemirror",
ext: ".min.css"
}],
options: {
level: {
2: {
all: true,
specialComments: "all"
}
}
}
},
github: {
files: [{
expand: true,
cwd: "themes/src/github/",
src: "*.css",
dest: "themes/github",
ext: ".min.css"
}],
options: {
// Don't use level 2; background *must* be the first entry; see #599
keepSpecialComments: "*",
advanced: false
}
},
jupyter: {
files: [{
expand: true,
cwd: "themes/src/jupyter/",
src: "*.css",
dest: "themes/jupyter",
ext: ".min.css"
}],
options: {
level: {
2: {
all: true,
specialComments: "all"
}
}
}
}
},
wrap: {
mozrule: {
files: {"<%= config.buildFile %>": "<%= config.buildFile %>"},
Expand All @@ -275,8 +187,6 @@ module.exports = function(grunt) {
});

grunt.loadNpmTasks("grunt-string-replace");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-cssmin");
grunt.loadNpmTasks("grunt-wrap");
grunt.loadNpmTasks("grunt-exec");

Expand All @@ -299,19 +209,4 @@ module.exports = function(grunt) {
"exec:usercss"
]);
});

// build custom minified GitHub-Dark style
grunt.registerTask("themes", "Rebuild minified theme files", () => {
grunt.task.run([
"clean:cssmins",
"cssmin:codemirror",
"cssmin:github",
"cssmin:jupyter",
"jupyter"
]);
});

grunt.registerTask("jupyter", "Replacing :is() in Jupyter files", () => {
processJupyterFiles();
});
};
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -115,7 +115,7 @@ To develop, first install [Node.js](https://nodejs.org) 12 or greater, then inst

- `npx grunt`: The default grunt task builds a custom theme using a provided `build.json` file. See the [wiki](https://github.com/StylishThemes/GitHub-Dark/wiki/Build) for details.
- `npm run usercss`: Build a [Usercss](https://github.com/openstyles/stylus/wiki/Usercss) style.
- `npx grunt themes`: Parse all theme files and combine them into minified styles in the `themes` directory.
- `npm run themes`: Parse all theme files and combine them into minified styles in the `themes` directory.
- `npm run clean`: Reformat `github-dark.css` to conform the style guide.
- `npm run lint`: Run Stylelint on `github-dark.css`.
- `npm run authors`: Regenerate the `AUTHORS` file based on git history.
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -19,17 +19,18 @@
"patch": "npm run lint && npm run usercss && versions -p -d -C patch github-dark.css github-dark.user.css",
"perfectionist": "perfectionist github-dark.css github-dark.css --indentSize 2 --maxAtRuleLength 250",
"test": "npm run lint",
"themes": "node tools/themes.js",
"update": "updates -cu && npm install",
"usercss": "grunt usercss"
},
"devDependencies": {
"clean-css-cli": "4.3.0",
"css": "2.2.4",
"css-mediaquery": "0.1.2",
"eslint": "6.7.2",
"eslint-config-silverwind": "5.0.3",
"fast-glob": "3.1.1",
"grunt": "1.0.4",
"grunt-contrib-clean": "2.0.0",
"grunt-contrib-cssmin": "3.0.0",
"grunt-exec": "3.0.0",
"grunt-string-replace": "1.3.1",
"grunt-wrap": "0.3.1",
Expand Down
2 changes: 1 addition & 1 deletion themes/codemirror/ambiance.min.css

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

2 changes: 1 addition & 1 deletion themes/codemirror/base16-ocean-dark.min.css

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

2 changes: 1 addition & 1 deletion themes/codemirror/cobalt.min.css

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

2 changes: 1 addition & 1 deletion themes/codemirror/dracula.min.css

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

0 comments on commit fd356f8

Please sign in to comment.