-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from mate-academy/vite-service
add ViteService for React tasks
- Loading branch information
Showing
6 changed files
with
82 additions
and
4 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
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,61 @@ | ||
import path from 'path'; | ||
import { | ||
execBashCodeControlled, execBashCodeSync, ExecResult, | ||
} from '../tools'; | ||
|
||
interface StartOptions { | ||
port?: number; | ||
open?: boolean; | ||
showLogs?: boolean; | ||
} | ||
|
||
export class ViteService { | ||
private readonly binDir = path.join(this.rootDir, 'node_modules/.bin/'); | ||
|
||
constructor(private readonly rootDir: string) { | ||
} | ||
|
||
start<Async extends boolean, Result = ExecResult<Async>>( | ||
options: StartOptions = {}, | ||
async: Async = false as Async, | ||
): Result { | ||
const { | ||
port, | ||
open = true, | ||
showLogs = false, | ||
} = options; | ||
|
||
const execFn = async | ||
? execBashCodeControlled | ||
: execBashCodeSync; | ||
|
||
const PORT = port | ||
? ` --port=${port}` | ||
: ''; | ||
|
||
const OPEN = open | ||
? ' --open' | ||
: ''; | ||
|
||
return execFn( | ||
`${this.binDir}vite dev${PORT}${OPEN}`, | ||
showLogs, | ||
) as any; | ||
} | ||
|
||
build( | ||
buildPath?: string, | ||
showLogs = true, | ||
) { | ||
const BUILD_PATH = buildPath | ||
? ` --out-dir ${buildPath}` | ||
: ''; | ||
const command = `cross-env ${this.binDir}vite build${BUILD_PATH}`; | ||
|
||
if (showLogs) { | ||
console.log(`Execute command: ${command}`); | ||
} | ||
|
||
return execBashCodeSync(command); | ||
} | ||
} |
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