1
Fork 0
userstyles/generate.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-06-14 21:42:44 +00:00
// Generates all *.user.css styles.
// Require dependencies
// const fs = require('fs')
const { bump } = require('./bump.js')
2018-06-14 21:42:44 +00:00
const klawSync = require('klaw-sync')
const path = require('path')
const userCss = require('usercss-creator')
// Define constants
2018-06-15 12:41:58 +00:00
const stylesDirectory = path.join(__dirname, 'sass')
2018-06-14 21:42:44 +00:00
const cssDirectory = path.join(__dirname, 'css')
2018-06-14 22:25:31 +00:00
// Walk recursively through styles directory
2018-06-14 21:42:44 +00:00
let files = klawSync(stylesDirectory, {nodir: true})
// Filter out any files that aren't .json files
files = files.filter(file => path.extname(file.path) === '.json')
2018-06-14 21:42:44 +00:00
let style
let incrementType
for (const arg of process.argv) {
if (arg.includes('--bump')) {
style = arg.substring('--bump='.length, arg.length)
}
switch (arg) {
case 'major':
incrementType = 'major'
break
case 'minor':
incrementType = 'minor'
break
case 'patch':
incrementType = 'patch'
break
}
}
// Iterate through all .json files
2018-06-14 21:42:44 +00:00
for (const file of files) {
// Requiring the .json file as the descriptor of the style
2018-06-14 21:42:44 +00:00
const descriptor = require(file.path)
// Test if the style we want to bump is the one currently generating
if (style === descriptor.folder) {
// Bump the style's .json with the increment type
bump(file.path, incrementType)
}
2018-06-14 22:25:31 +00:00
// Creating the css path and generating the .user.css file with the options
2018-06-14 21:42:44 +00:00
const cssPath = path.join(cssDirectory, descriptor.folder, descriptor.entry)
userCss.create(cssPath, descriptor.options)
}