-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(command): add dev and build commands
- Loading branch information
Showing
13 changed files
with
141 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface CommandDevArgs { | ||
experimental: boolean; | ||
} | ||
|
||
export interface CommandBuildArgs { | ||
experimental: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./config"; | ||
export * from "./template"; | ||
export * from "./command-args"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { CommandModule } from "yargs"; | ||
import { projectForm } from "./form"; | ||
import { CommandDevArgs } from "../@types"; | ||
|
||
const buildProject = (): CommandModule<Record<string, never>, CommandDevArgs> => { | ||
return { | ||
command: "build", | ||
describe: "Build project", | ||
handler: projectForm, | ||
}; | ||
}; | ||
|
||
export { buildProject }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
import path from "node:path"; | ||
import { existsSync } from "node:fs"; | ||
import { spawnSync } from "node:child_process"; | ||
import { CommandBuildArgs } from "../@types"; | ||
import { printError } from "../utils/cli-ui"; | ||
import { getPlatformCommand } from "../utils/get-platform-command-bin"; | ||
|
||
const PATH = `${process.env.PATH}${path.delimiter}${path.resolve(__dirname, "../../node_modules/.bin")}`; | ||
const env = { ...process.env, PATH }; | ||
|
||
const projectForm = async ({ experimental }: CommandBuildArgs): Promise<void> => { | ||
console.time("Build succeed"); | ||
|
||
spawnSync("rimraf", ["dist"], { env, stdio: "inherit" }); | ||
|
||
if (experimental) { | ||
if (!existsSync(".swcrc")) { | ||
printError("Experimental features needs .swcrc file", ".swcrc"); | ||
process.exit(1); | ||
} | ||
|
||
const { result } = require("concurrently")([ | ||
{ name: "types", command: "tsc --noEmit" }, | ||
{ name: "lint", command: "eslint src/**/*.ts" }, | ||
{ name: "build", command: "swc src -d dist" }, | ||
], { raw: true }); | ||
|
||
result | ||
.then(() => { | ||
console.timeEnd("Build succeed"); | ||
}) | ||
.catch(() => { | ||
printError("Build failed", "expressots build"); | ||
process.exit(1); | ||
}); | ||
|
||
return; | ||
} | ||
|
||
spawnSync(getPlatformCommand("tsc"), ["-p", "tsconfig.build.json"], { env, stdio: "inherit" }); | ||
console.timeEnd("Build succeed"); | ||
}; | ||
|
||
export { projectForm }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./cli"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { CommandModule } from "yargs"; | ||
import { projectForm } from "./form"; | ||
import { CommandDevArgs } from "../@types"; | ||
|
||
const devProject = (): CommandModule<Record<string, never>, CommandDevArgs> => { | ||
return { | ||
command: "dev", | ||
describe: "Run project in development mode", | ||
handler: projectForm, | ||
}; | ||
}; | ||
|
||
export { devProject }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
import path from "node:path"; | ||
import { existsSync } from "node:fs"; | ||
import { spawn, spawnSync } from "node:child_process"; | ||
import nodemon from "nodemon"; | ||
import { CommandDevArgs } from "../@types"; | ||
import { printError } from "../utils/cli-ui"; | ||
import { getPlatformCommand } from "../utils/get-platform-command-bin"; | ||
|
||
const projectForm = async ({ experimental }: CommandDevArgs): Promise<void> => { | ||
if (experimental) { | ||
if (!existsSync(".swcrc")) { | ||
printError("Experimental features needs .swcrc file", ".swcrc"); | ||
process.exit(1); | ||
} | ||
|
||
require('@swc/register'); | ||
|
||
function nodemonRestart() { | ||
spawn(getPlatformCommand("eslint"), ["src/**/*.ts"], { stdio: "inherit" }); | ||
spawn(getPlatformCommand("tsc"), ["--noEmit"], { stdio: "inherit" }); | ||
} | ||
|
||
nodemon({ | ||
ext: "ts", | ||
exec: `node -r ${require.resolve("@swc/register")} src/main.ts`, | ||
}) | ||
.on("start", nodemonRestart) | ||
.on("restart", nodemonRestart); | ||
|
||
|
||
return; | ||
} | ||
|
||
spawnSync(getPlatformCommand("ts-node-dev"), ["src/main.ts"], { stdio: "inherit" }); | ||
}; | ||
|
||
export { projectForm }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./cli"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function getPlatformCommand(binName: string) { | ||
const isWindows = process.platform === "win32"; | ||
return isWindows ? `${binName}.cmd` : binName; | ||
} | ||
|
||
export { getPlatformCommand }; |