1
Fork 0

Allow writing versions to individual styles, reset all styles to 1.0.0

Create bump.js to easily bump versions
This commit is contained in:
Bauke 2018-06-19 16:34:38 +02:00
parent 65b00adb36
commit 2755dc4eaf
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
13 changed files with 3466 additions and 3413 deletions

53
bump.js Normal file
View File

@ -0,0 +1,53 @@
// Bumps a specified style's version
const fs = require('fs')
const path = require('path')
/**
* @function bump
* @param {string} jsonPath - Path to the .json file
* @param {string} incrementType - Which semver type to increment: "major", "minor" or "patch"
*/
function bump(jsonPath, incrementType) {
if (!fs.existsSync(jsonPath))
throw Error(`File ${jsonPath} does not exist.`)
if (path.extname(jsonPath) !== '.json')
throw Error(`File ${jsonPath} does not end in "json".`)
if (typeof incrementType === 'undefined')
throw Error('No valid increment type was included. Valid: "major", "minor" or "patch".')
if (incrementType !== 'major' && incrementType !== 'minor' && incrementType !== 'patch')
throw Error(`Increment type ${incrementType} does not equal "major", "minor" or "patch".`)
const jsonFile = require(jsonPath)
if (typeof jsonFile.options.version === 'undefined')
throw Error(`${jsonFile} does not include a "version" property.`)
const incrementTypes = {
'major': 0,
'minor': 1,
'patch': 2
}
const oldVersion = jsonFile.options.version.split('.')
let bumped = parseInt(oldVersion[incrementTypes[incrementType]]) + 1
let newVersion
switch (incrementType) {
case 'major':
newVersion = `${bumped}.${oldVersion[1]}.${oldVersion[2]}`
break
case 'minor':
newVersion = `${oldVersion[0]}.${bumped}.${oldVersion[2]}`
break
case 'patch':
newVersion = `${oldVersion[0]}.${oldVersion[1]}.${bumped}`
break
}
jsonFile.options.version = newVersion
fs.writeFileSync(jsonPath, JSON.stringify(jsonFile, null, 2))
}
exports.bump = bump

View File

@ -1,9 +1,9 @@
/* ==UserStyle==
@name Tildes Compact
@namespace tildes.net
@version 3.0.1
@version 1.0.0
@author Bauke
@description Compact theme for Tildes.net
@description Removes some elements and changes some sizes to make the Tildes.net layout a little more compact.
@homepageURL https://gitlab.com/Bauke/styles
@supportURL https://gitlab.com/Bauke/styles/issues
@license MIT

View File

@ -1,7 +1,7 @@
/* ==UserStyle==
@name Tildes Dracula
@namespace tildes.net
@version 3.0.1
@version 1.0.0
@author Bauke
@description Dracula theme for Tildes.net
@homepageURL https://gitlab.com/Bauke/styles

View File

@ -1,7 +1,7 @@
/* ==UserStyle==
@name Tildes Monokai
@namespace tildes.net
@version 3.0.1
@version 1.0.0
@author Bauke
@description Monokai theme for Tildes.net
@homepageURL https://gitlab.com/Bauke/styles

View File

@ -2,6 +2,7 @@
// 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')
@ -13,13 +14,38 @@ const cssDirectory = path.join(__dirname, 'css')
// Walk recursively through styles directory
let files = klawSync(stylesDirectory, {nodir: true})
// Filter out any files that aren't .js files
files = files.filter(file => path.extname(file.path) === '.js')
// Filter out any files that aren't .json files
files = files.filter(file => path.extname(file.path) === '.json')
// Iterate through all .js files
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 .js files as the descriptor of the style
// 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)

View File

@ -1,15 +1,16 @@
{
"name": "bauke-styles",
"repository": "https://gitlab.com/Bauke/styles",
"version": "3.0.1",
"version": "1.0.0",
"author": {
"name": "Bauke",
"email": "me@bauke.xyz"
},
"license": "MIT",
"scripts": {
"release signature example: yarn release --bump=tildes-monokai minor": "echo \"no.\"",
"release": "yarn lint && yarn build:prod && yarn generate",
"watch": "node-sass -w sass -o temp",
"release": "yarn lint && yarn build:prod && yarn version && yarn generate",
"generate": "node generate.js",
"build:dev": "node-sass sass -o temp --output-style compact",
"build:prod": "node-sass sass -o css -q --output-style compact",

View File

@ -1,23 +0,0 @@
const pjson = require('../../package.json')
// Descriptor for Tildes Compact
const entry = 'tildes-compact.css'
const folder = 'tildes-compact'
const options = {
name: 'Tildes Compact',
namespace: 'tildes.net',
version: pjson.version,
author: 'Bauke',
description: 'Compact theme for Tildes.net',
homepageURL: 'https://gitlab.com/Bauke/styles',
supportURL: 'https://gitlab.com/Bauke/styles/issues',
license: 'MIT'
}
module.exports = {
entry: entry,
folder: folder,
options: options
}

View File

@ -0,0 +1,14 @@
{
"entry": "tildes-compact.css",
"folder": "tildes-compact",
"options": {
"name": "Tildes Compact",
"namespace": "tildes.net",
"version": "1.0.0",
"author": "Bauke",
"description": "Removes some elements and changes some sizes to make the Tildes.net layout a little more compact.",
"homepageURL": "https://gitlab.com/Bauke/styles",
"supportURL": "https://gitlab.com/Bauke/styles/issues",
"license": "MIT"
}
}

View File

@ -1,23 +0,0 @@
const pjson = require('../../package.json')
// Descriptor for Tildes Dracula
const entry = 'tildes-dracula.css'
const folder = 'tildes-dracula'
const options = {
name: 'Tildes Dracula',
namespace: 'tildes.net',
version: pjson.version,
author: 'Bauke',
description: 'Dracula theme for Tildes.net',
homepageURL: 'https://gitlab.com/Bauke/styles',
supportURL: 'https://gitlab.com/Bauke/styles/issues',
license: 'MIT'
}
module.exports = {
entry: entry,
folder: folder,
options: options
}

View File

@ -0,0 +1,14 @@
{
"entry": "tildes-dracula.css",
"folder": "tildes-dracula",
"options": {
"name": "Tildes Dracula",
"namespace": "tildes.net",
"version": "1.0.0",
"author": "Bauke",
"description": "Dracula theme for Tildes.net",
"homepageURL": "https://gitlab.com/Bauke/styles",
"supportURL": "https://gitlab.com/Bauke/styles/issues",
"license": "MIT"
}
}

View File

@ -1,23 +0,0 @@
const pjson = require('../../package.json')
// Descriptor for Tildes Monokai
const entry = 'tildes-monokai.css'
const folder = 'tildes-monokai'
const options = {
name: 'Tildes Monokai',
namespace: 'tildes.net',
version: pjson.version,
author: 'Bauke',
description: 'Monokai theme for Tildes.net',
homepageURL: 'https://gitlab.com/Bauke/styles',
supportURL: 'https://gitlab.com/Bauke/styles/issues',
license: 'MIT'
}
module.exports = {
entry: entry,
folder: folder,
options: options
}

View File

@ -0,0 +1,14 @@
{
"entry": "tildes-monokai.css",
"folder": "tildes-monokai",
"options": {
"name": "Tildes Monokai",
"namespace": "tildes.net",
"version": "1.0.0",
"author": "Bauke",
"description": "Monokai theme for Tildes.net",
"homepageURL": "https://gitlab.com/Bauke/styles",
"supportURL": "https://gitlab.com/Bauke/styles/issues",
"license": "MIT"
}
}

6668
yarn.lock Executable file → Normal file

File diff suppressed because it is too large Load Diff