Commit 588e956 1 parent 67d5a10 commit 588e956 Copy full SHA for 588e956
File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { URL } from 'url';
6
6
7
7
import newCmd from '#commands/new' ;
8
8
import generateCmd from '#commands/generate' ;
9
+ import initCmd from '#commands/init' ;
9
10
10
11
const sapphire = new Command ( ) ;
11
12
@@ -30,4 +31,6 @@ sapphire
30
31
. argument ( '<name>' , 'file name' )
31
32
. action ( generateCmd ) ;
32
33
34
+ sapphire . command ( 'init' ) . description ( 'creates a config file on an existing Sapphire project' ) . alias ( 'i' ) . action ( initCmd ) ;
35
+
33
36
sapphire . parse ( process . argv ) ;
Original file line number Diff line number Diff line change
1
+ import { PromptInit } from '#prompts' ;
2
+ import prompts from 'prompts' ;
3
+ import YAML from 'yaml' ;
4
+ import { writeFile } from 'fs/promises' ;
5
+ import FindUp from 'find-up' ;
6
+ import chalk from 'chalk' ;
7
+
8
+ const { red } = chalk ;
9
+
10
+ export default async ( ) => {
11
+ const packageJson = await FindUp ( 'package.json' ) ;
12
+ if ( ! packageJson ) {
13
+ console . log ( red ( "Can't find package.json" ) ) ;
14
+ process . exit ( 1 ) ;
15
+ }
16
+
17
+ const response = await prompts ( PromptInit ) ;
18
+ if ( ! response . preconditions ) return process . exit ( 1 ) ;
19
+
20
+ const config = {
21
+ projectLanguage : response . projectLanguage ,
22
+ locations : {
23
+ base : response . base ,
24
+ arguments : response . arguments ,
25
+ commands : response . commands ,
26
+ listeners : response . listeners ,
27
+ preconditions : response . preconditions
28
+ } ,
29
+ customFileTemplates : {
30
+ enabled : response . cftEnabled ,
31
+ location : response . cftLocation ?? ''
32
+ }
33
+ } ;
34
+
35
+ const file = response . configFormat === 'json' ? JSON . stringify ( config , null , 2 ) : YAML . stringify ( config ) ;
36
+ return writeFile ( `.sapphirerc.${ response . configFormat } ` , file ) ;
37
+ } ;
You can’t perform that action at this time.
0 commit comments