Skip to content

Commit fa7e334

Browse files
author
Ovidiu Barabula
committed
feat(cli): implement commands
1 parent d19713a commit fa7e334

File tree

1 file changed

+82
-40
lines changed

1 file changed

+82
-40
lines changed

src/cli/cli.ts

Lines changed: 82 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,91 @@
88
import * as program from 'commander';
99
import frontvue from '../core';
1010

11-
program
12-
.version('0.1.0')
13-
.arguments('<command>')
14-
.action(command => {
15-
if (!command) {
16-
console.log('You need to type a command as well');
11+
// Set CLI tool version
12+
program.version('0.1.0', '-v, --version');
13+
14+
15+
/**
16+
* Command: init
17+
* Description: Initialize a new project
18+
*/
19+
program.command('init')
20+
.alias('i')
21+
.description('Initialize a new project')
22+
.action(async () => {
23+
const instance = await frontvue;
24+
const logger = instance.logger('cli');
25+
logger.info(`Configuring new project\u2026`);
26+
await instance.run('init');
27+
});
28+
29+
30+
/**
31+
* Command: config
32+
* Description: Start configuration wizard
33+
*/
34+
program.command('config')
35+
.alias('c')
36+
.description('Start configuration wizard')
37+
.action(async () => {
38+
const instance = await frontvue;
39+
const logger = instance.logger('cli');
40+
logger.info(`Configuring project\u2026`);
41+
await instance.run('config');
42+
});
43+
44+
45+
/**
46+
* Command: dev
47+
* Description: Start development mode
48+
*/
49+
program.command('dev')
50+
.alias('d')
51+
.description('Starts development mode')
52+
.action(async () => {
53+
const instance = await frontvue;
54+
const logger = instance.logger('cli');
55+
const hooks = ['clean', 'process', 'watch'];
56+
logger.info('Starting development mode\u2026');
57+
58+
for (const hook of hooks) {
59+
await instance.run(hook);
1760
}
1861
});
1962

20-
program
21-
.command('init [name]')
22-
.action(async name => {
23-
const instance = await frontvue;
24-
const logger = instance.logger('cli');
25-
logger.info(`Creating a new project ./${name}`);
26-
27-
await Promise.all(
28-
[
29-
instance.run('init'),
30-
instance.run('template'),
31-
instance.run('clean'),
32-
instance.run('process'),
33-
instance.run('watch'),
34-
],
35-
);
36-
})
37-
.description('Initialize a new project');
38-
39-
40-
program
41-
.command('config')
42-
.description('Start configuration wizard')
43-
.action(() => console.log('Starting configuration...'));
44-
45-
46-
program
47-
.command('run [hook]')
48-
.description('Run tasks in a hook')
49-
.action(async hook => {
50-
const instance = await frontvue;
51-
const logger = instance.logger('cli');
52-
logger.info(`Starting ${hook}...`);
63+
64+
/**
65+
* Command: build
66+
* Description: Build production package
67+
*/
68+
program.command('build')
69+
.alias('b')
70+
.description('Build production package')
71+
.action(async () => {
72+
const instance = await frontvue;
73+
const logger = instance.logger('cli');
74+
const hooks = ['clean', 'process'];
75+
logger.info('Building production package\u2026');
76+
77+
for (const hook of hooks) {
5378
await instance.run(hook);
54-
});
79+
}
80+
});
81+
82+
83+
/**
84+
* Command: run <hook>
85+
* Description: Run specific tasks hook
86+
*/
87+
program.command('run <hook>')
88+
.alias('r')
89+
.description('Run all tasks in a specific hook sequence')
90+
.action(async hook => {
91+
const instance = await frontvue;
92+
const logger = instance.logger('cli');
93+
logger.info(`Running <${hook}> tasks\u2026`);
94+
await instance.run(hook);
95+
});
96+
5597

5698
program.parse(process.argv);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy