refactord paths.ts

This commit is contained in:
2022-06-11 00:05:32 -05:00
parent 29b40b4e43
commit 83570d9535
14 changed files with 148 additions and 97 deletions

View File

@@ -1,16 +1,22 @@
import { existsSync, lstatSync, readdirSync, unlinkSync } from 'fs'
import commandLineArgs from 'command-line-args'
import { DistBase, ScriptBase, ScriptPath } from './paths'
import { updateReadmeFile } from './readmefile'
import runBuild from './build'
import * as Path from 'path'
import getAllPaths from './paths'
export interface CLIArgsT {
watch: boolean
minify: boolean
prettier: boolean
srccomment: boolean
help: boolean
baseurl?: string
remotebranch?: string
scriptpath?: string
distpath?: string
help?: boolean
}
export const CLIArgs = commandLineArgs([
@@ -18,9 +24,22 @@ export const CLIArgs = commandLineArgs([
{ name: 'minify', alias: 'm', type: Boolean, defaultValue: false },
{ name: 'prettier', alias: 'p', type: Boolean, defaultValue: false },
{ name: 'srccomment', alias: 's', type: Boolean, defaultValue: false },
{ name: 'help', alias: 'h', type: Boolean, defaultValue: false },
{ name: 'baseurl', alias: 'bu', type: String, defaultValue: '' },
{ name: 'remotebranch', alias: 'rb', type: String, defaultValue: 'main' },
{ name: 'scriptsdir', alias: 'sd', type: String, defaultValue: 'scripts' },
{ name: 'distdir', alias: 'dd', type: String, defaultValue: 'dist' },
{ name: 'help', alias: 'h', type: Boolean },
]) as CLIArgsT
export const AllPaths = getAllPaths({
baseURL: CLIArgs.baseurl || '',
remoteBranch: CLIArgs.remotebranch || 'main',
scriptBase: CLIArgs.scriptpath || 'scripts',
distBase: CLIArgs.distpath || 'dist',
})
if (CLIArgs.help) {
let command = '<command>'
if (process.argv.length > 0) {
@@ -61,14 +80,16 @@ if (!existsSync('package.json') || !lstatSync('package.json').isFile()) {
}
//delete compiled scripts
readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
readdirSync(AllPaths.base.dist).forEach(file =>
unlinkSync(`${AllPaths.base.dist}/${file}`)
)
//compile scripts
let scripts = readdirSync(ScriptBase)
let scripts = readdirSync(AllPaths.base.script)
let scriptMeta: runBuild[] = []
for (let name of scripts) {
let path = ScriptPath(name)
let path = AllPaths.script(name)
if (
!name.endsWith('_') &&