one-dark/build-theme.js

84 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-05-13 18:38:41 +08:00
#!/usr/bin/env node
2022-05-05 19:53:15 +08:00
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2022/05/05 11:21:01
*/
2023-03-14 21:42:57 +08:00
import scss from '@bytedo/sass'
2022-05-05 19:53:15 +08:00
import fs from 'iofs'
import { parse } from 'path'
import { execSync } from 'child_process'
import chokidar from 'chokidar'
import chalk from 'chalk'
const CINNAMON_SCSS = './cinnamon/sass/cinnamon.scss'
const CINNAMON_STYLE = './cinnamon/cinnamon.css'
const GTK3_SCSS = './gtk-3.0/sass/gtk.scss'
const GTK3_STYLE = './gtk-3.0/gtk.css'
2022-07-18 20:07:18 +08:00
// const GTK3_2_SCSS = './gtk-3.20/gtk.scss'
// const GTK3_2_STYLE = './gtk-3.20/gtk.css'
2022-05-05 19:53:15 +08:00
function render(file) {
2022-05-13 18:38:41 +08:00
try {
return scss.renderSync({
file,
indentType: 'space',
indentWidth: 2
}).css
} catch (err) {
console.log(err)
}
2022-05-05 19:53:15 +08:00
}
/*=======================================================*/
/*===== ===*/
/*=======================================================*/
let ready = false
let timer = null
chokidar
.watch('./')
.on('all', (act, file) => {
if (!ready) {
return
}
if (act === 'add' || act === 'change') {
let { ext } = parse(file)
if (ext === '.scss') {
clearTimeout(timer)
timer = setTimeout(_ => {
console.log('更新 Cinnamon 样式……')
{
let style = render(CINNAMON_SCSS)
fs.echo(style, CINNAMON_STYLE)
}
console.log('更新 Cinnamon 完成!!!')
console.log('更新 Gtk3 样式……')
{
let style = render(GTK3_SCSS)
fs.echo(style, GTK3_STYLE)
}
2022-07-18 20:07:18 +08:00
// {
// let style = render(GTK3_2_SCSS)
// fs.echo(style, GTK3_2_STYLE)
// }
2022-05-05 19:53:15 +08:00
console.log('更新 Gtk3 完成!!!')
console.log()
2023-01-16 15:13:45 +08:00
// execSync('bash ./update-theme.sh', {
// stdio: [process.stdin, process.stdout, process.stdout]
// })
2022-05-05 19:53:15 +08:00
}, 1000)
}
}
})
.on('ready', () => {
ready = true
console.log(chalk.red('预处理完成,监听文件变化中,请勿关闭本窗口...'))
})