updated cli args and help screen
This commit is contained in:
@@ -116,7 +116,7 @@ function getResult(error: BuildFailure | null, result: BuildResult | null) {
|
||||
}
|
||||
|
||||
function clearFilenameComments(content: string): string {
|
||||
let regexp = new RegExp(`//\\s*${AllPaths.base.script}/.*(?:\\n|$)`, 'g')
|
||||
let regexp = new RegExp(`//\\s*${AllPaths.base.in}/.*(?:\\n|$)`, 'g')
|
||||
return content.replace(regexp, '')
|
||||
}
|
||||
|
||||
|
||||
79
src/main.ts
79
src/main.ts
@@ -1,4 +1,4 @@
|
||||
import { existsSync, lstatSync, readdirSync, unlinkSync } from 'fs'
|
||||
import { existsSync, lstatSync, mkdirSync, readdirSync, unlinkSync } from 'fs'
|
||||
import commandLineArgs from 'command-line-args'
|
||||
import { updateReadmeFile } from './readmefile'
|
||||
import runBuild, { runBuildResult } from './build'
|
||||
@@ -10,11 +10,13 @@ export interface CLIArgsT {
|
||||
minify: boolean
|
||||
prettier: boolean
|
||||
srccomment: boolean
|
||||
readme: boolean
|
||||
|
||||
baseurl?: string
|
||||
url?: string
|
||||
supporturl?: string
|
||||
remotebranch?: string
|
||||
scriptpath?: string
|
||||
distpath?: string
|
||||
in?: string
|
||||
out?: string
|
||||
|
||||
help?: boolean
|
||||
}
|
||||
@@ -24,20 +26,23 @@ export const CLIArgs = commandLineArgs([
|
||||
{ name: 'minify', alias: 'm', type: Boolean, defaultValue: false },
|
||||
{ name: 'prettier', alias: 'p', type: Boolean, defaultValue: false },
|
||||
{ name: 'srccomment', alias: 'c', type: Boolean, defaultValue: false },
|
||||
{ name: 'readme', alias: 'r', type: Boolean, defaultValue: false },
|
||||
|
||||
{ name: 'baseurl', alias: 'u', type: String, defaultValue: '' },
|
||||
{ name: 'remotebranch', alias: 'b', type: String, defaultValue: 'main' },
|
||||
{ name: 'scriptsdir', alias: 's', type: String, defaultValue: 'scripts' },
|
||||
{ name: 'distdir', alias: 'd', type: String, defaultValue: 'dist' },
|
||||
{ name: 'url', alias: 'u', type: String, defaultValue: '' },
|
||||
{ name: 'supporturl', alias: 's', type: String, defaultValue: '' },
|
||||
{ name: 'remotebranch', alias: 'b', type: String, defaultValue: '' },
|
||||
{ name: 'in', alias: 'i', type: String, defaultValue: 'scripts' },
|
||||
{ name: 'out', alias: 'o', 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',
|
||||
baseUrl: CLIArgs.url || '',
|
||||
supportUrl: CLIArgs.supporturl || '',
|
||||
remoteBranch: CLIArgs.remotebranch || '',
|
||||
inBase: CLIArgs.in || 'scripts',
|
||||
outBase: CLIArgs.out || 'dist',
|
||||
})
|
||||
|
||||
if (CLIArgs.help) {
|
||||
@@ -56,16 +61,46 @@ Usage: ${command} [options]
|
||||
options:
|
||||
--watch
|
||||
alias: -w
|
||||
default: false
|
||||
automatically recompile on save
|
||||
--minify
|
||||
alias: -m
|
||||
default: false
|
||||
minify output files
|
||||
--prettier
|
||||
alias: -p
|
||||
default: false
|
||||
prettify output files
|
||||
--srccomment
|
||||
alias: -s
|
||||
alias: -c
|
||||
default: false
|
||||
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||
--readme
|
||||
alias: -r
|
||||
default: false
|
||||
update the readme.md file in your directory to include links to each userscript
|
||||
|
||||
--url <url>
|
||||
alias: -u <url>
|
||||
default: ""
|
||||
the base for urls used in the meta comments
|
||||
--supporturl <url>
|
||||
alias: -s <url>
|
||||
default: ""
|
||||
the support url used in the meta comments
|
||||
--remotebranch <name>
|
||||
alias: -b <name>
|
||||
default: ""
|
||||
if included, the included base url will be treated as a git repo, and the support url is not required
|
||||
--in
|
||||
alias: -i
|
||||
default: "scripts"
|
||||
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||
--out
|
||||
alias: -o
|
||||
default: "dist"
|
||||
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||
|
||||
--help
|
||||
alias: -h
|
||||
show this help message
|
||||
@@ -79,14 +114,18 @@ if (!existsSync('package.json') || !lstatSync('package.json').isFile()) {
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
//delete compiled scripts
|
||||
readdirSync(AllPaths.base.dist).forEach(file =>
|
||||
unlinkSync(`${AllPaths.base.dist}/${file}`)
|
||||
)
|
||||
//delete compiled scripts or create output folder if it doesnt exist
|
||||
if (!existsSync(AllPaths.base.out)) {
|
||||
mkdirSync(AllPaths.base.out)
|
||||
} else {
|
||||
readdirSync(AllPaths.base.out).forEach(file =>
|
||||
unlinkSync(`${AllPaths.base.out}/${file}`)
|
||||
)
|
||||
}
|
||||
|
||||
//compile scripts
|
||||
async function doCompile() {
|
||||
let scripts = readdirSync(AllPaths.base.script)
|
||||
let scripts = readdirSync(AllPaths.base.in)
|
||||
let scriptMeta: runBuildResult[] = []
|
||||
|
||||
for (let name of scripts) {
|
||||
@@ -104,7 +143,7 @@ async function doCompile() {
|
||||
function update(result: runBuildResult) {
|
||||
console.log('WATCH', name, result.meta.version)
|
||||
scriptMeta[id] = result
|
||||
updateReadmeFile(scriptMeta)
|
||||
if (CLIArgs.readme) updateReadmeFile(scriptMeta)
|
||||
}
|
||||
|
||||
let result = await runBuild(name, update)
|
||||
@@ -116,7 +155,7 @@ async function doCompile() {
|
||||
return scriptMeta
|
||||
}
|
||||
doCompile().then(scriptMeta => {
|
||||
updateReadmeFile(scriptMeta)
|
||||
if (CLIArgs.readme) updateReadmeFile(scriptMeta)
|
||||
|
||||
console.log(
|
||||
`\nFinished Compiling\n${
|
||||
|
||||
45
src/paths.ts
45
src/paths.ts
@@ -4,39 +4,48 @@ export interface ScriptPathT {
|
||||
meta: `${string}/${string}/meta.json`
|
||||
error: `${string}/${string}/error.log`
|
||||
dist: `${string}/${string}.user.js`
|
||||
url: `${string}/raw/branch/${string}/${string}/${string}.user.js`
|
||||
url: `${string}/${string}.user.js`
|
||||
}
|
||||
|
||||
export interface getAllPathsOps {
|
||||
baseURL: string
|
||||
baseUrl: string
|
||||
supportUrl: string
|
||||
remoteBranch: string
|
||||
scriptBase: string
|
||||
distBase: string
|
||||
inBase: string
|
||||
outBase: string
|
||||
}
|
||||
|
||||
export default function getAllPaths({
|
||||
baseURL,
|
||||
baseUrl,
|
||||
supportUrl,
|
||||
remoteBranch,
|
||||
scriptBase,
|
||||
distBase,
|
||||
inBase,
|
||||
outBase,
|
||||
}: getAllPathsOps) {
|
||||
// generate links for remote git server
|
||||
if (baseUrl != '' && remoteBranch != '') {
|
||||
if (supportUrl == '') {
|
||||
supportUrl = `${baseUrl}/issues`
|
||||
}
|
||||
baseUrl = `${baseUrl}/raw/branch/${remoteBranch}/${outBase}`
|
||||
}
|
||||
|
||||
return {
|
||||
base: {
|
||||
branch: remoteBranch,
|
||||
script: scriptBase,
|
||||
dist: distBase,
|
||||
in: inBase,
|
||||
out: outBase,
|
||||
},
|
||||
url: {
|
||||
base: baseURL,
|
||||
support: `${baseURL}/issues`,
|
||||
base: baseUrl,
|
||||
support: supportUrl,
|
||||
},
|
||||
script: (name: string): ScriptPathT => ({
|
||||
dir: `${scriptBase}/${name}`,
|
||||
main: `${scriptBase}/${name}/main.ts`,
|
||||
meta: `${scriptBase}/${name}/meta.json`,
|
||||
error: `${scriptBase}/${name}/error.log`,
|
||||
dist: `${distBase}/${name}.user.js`,
|
||||
url: `${baseURL}/raw/branch/${remoteBranch}/${distBase}/${name}.user.js`,
|
||||
dir: `${inBase}/${name}`,
|
||||
main: `${inBase}/${name}/main.ts`,
|
||||
meta: `${inBase}/${name}/meta.json`,
|
||||
error: `${inBase}/${name}/error.log`,
|
||||
dist: `${outBase}/${name}.user.js`,
|
||||
url: `${baseUrl}/${name}.user.js`,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user