1
Fork 0
userstyles/generate.js

53 lines
1.5 KiB
JavaScript
Executable File

// Generates all *.user.css styles.
// Require dependencies
// const fs = require('fs')
const { bump } = require('./bump.js')
const klawSync = require('klaw-sync')
const path = require('path')
const userCss = require('usercss-creator')
// Define constants
const stylesDirectory = path.join(__dirname, 'sass')
const cssDirectory = path.join(__dirname, 'css')
// Walk recursively through styles directory
let files = klawSync(stylesDirectory, {nodir: true})
// Filter out any files that aren't .json files
files = files.filter(file => path.extname(file.path) === '.json')
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
for (const file of files) {
// Requiring the .json file as the descriptor of the style
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)
}
// Creating the css path and generating the .user.css file with the options
const cssPath = path.join(cssDirectory, descriptor.folder, descriptor.entry)
userCss.create(cssPath, descriptor.options)
}