Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed May 8, 2021
1 parent 554a122 commit 320b448
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
target
dist
node_modules
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@sinclair/hammer",
"version": "0.8.9",
"version": "0.8.10",
"description": "Build Tool for HTML Applications.",
"author": "sinclairzx81",
"keywords": ["esbuild", "bundler", "html"],
Expand Down
21 changes: 9 additions & 12 deletions src/cli.ts
Expand Up @@ -59,24 +59,21 @@ function help() {
}

async function cli(argv: string[]) {
const green = `\x1b[32m`
const yellow = '\x1b[33m'
const esc = `\x1b[0m`
const hammer = String.fromCodePoint(0x1F528)
const result = options(process.argv)
if(result === undefined) return help()
console.log(`${hammer} Plaform '${result.platform}'`)
for(const sourcePath of result.sourcePaths) {
console.log(`${hammer} Build ${sourcePath}`)
}
if(result.watch) {
console.log(`${hammer} Watch for file changes`)
}
if(result.serve) {
console.log(`${hammer} Serve on http://localhost:${result.serve}`)
}
if(result.start) {
console.log(`${hammer} Start ${result.start}`)
console.log(`${green}Building${esc} ${sourcePath}`)
}
if(result.serve) console.log(`${yellow}Serving${esc} on http://localhost:${result.serve}`)
if(result.start) console.log(`${yellow}Starting${esc} ${result.start}`)
if(result.watch) console.log(`${yellow}Watching${esc} for file changes`)
await start(result)
if(!result.watch) console.log(hammer, 'Done')

if(!result.watch) console.log(`${green}Done${esc}`)
}

cli(process.argv)
9 changes: 5 additions & 4 deletions src/options/options.ts
Expand Up @@ -44,7 +44,7 @@ export class OptionsReader {
private readonly parameters: string[]

constructor(private readonly args: string[]) {
this.parameters = this.args.slice(2).join(' ').split(' ').filter(x => x.length !== 0)
this.parameters = this.args.slice(2)
}

private help() {
Expand Down Expand Up @@ -85,10 +85,11 @@ export class OptionsReader {

private start() {
const dist = this.dist()
const index = this.parameters.indexOf('--start');
const index = this.parameters.indexOf('--start')
if(!(index === -1 || (index + 1) > this.parameters.length)) {
const entry = path.join(dist, this.parameters[index + 1])
return fs.existsSync(entry) ? entry : undefined
const parameter = path.join(dist, this.parameters[index + 1])
const split = parameter.split(' ')
return fs.existsSync(split[0]) ? parameter : undefined
} else if(!(index === -1)) {
const entry = path.join(dist, 'index.js')
return fs.existsSync(entry) ? entry : undefined
Expand Down
1 change: 1 addition & 0 deletions tasks.js
@@ -1,5 +1,6 @@
export async function clean() {
await folder('target').delete().exec()
await folder('dist').delete().exec()
}

export async function start(target = 'target/watch') {
Expand Down

0 comments on commit 320b448

Please sign in to comment.