#!/usr/bin/env node const fs = require('fs') const path = require('path') const postcss = require('postcss') const algacss = require('../src/') const argv = require('minimist')(process.argv.slice(2), { string: ['_'] }) const cwd = process.cwd() const sourceFile = argv._[0] const targetFile = argv._[1] const processStyle = (value = '') => { let option = {} if(value !== '') { option = { important: false, src: value } } const argvKeys = Object.keys(argv).filter(i => i !== '_') let renderCss = `@use ${path.basename(value).split('.')[0]};` if(argvKeys.length >= 1) { let newCssProp = '{' for(let argvKey of argvKeys) { newCssProp += `${argvKey}: ${argv[argvKey]};` } newCssProp += '}' renderCss = `@use ${path.basename(value).split('.')[0]} ${newCssProp}` } let result = postcss([ algacss(option) ]).process(renderCss, { from: value }) return result.css } if(sourceFile) { if(sourceFile?.endsWith('.alga')) { let content = processStyle(sourceFile) let targetPath = targetFile || sourceFile.replace('.alga', '.css') if(targetFile) { targetPath = path.join(cwd, targetPath) } if(!targetPath.endsWith('.css')) { targetPath = targetPath + new Date().toJSON().replace(/T|Z|-|\:|\./g, '') +'.css' } fs.writeFileSync(targetPath, content) console.log('Source: '+ sourceFile) console.log('Target: '+ targetPath) console.log('Status: created') } else { let content = processStyle(sourceFile) let targetPath = targetFile || sourceFile.replace('.alga', '.css') if(targetFile) { targetPath = path.join(cwd, targetPath) } if(!targetPath.endsWith('.css')) { targetPath = targetPath + new Date().toJSON().replace(/T|Z|-|\:|\./g, '') +'.css' } fs.writeFileSync(targetPath, content) console.log('Source: '+ sourceFile) console.log('Target: '+ targetPath) console.log('Status: created') } } process.exit()