Skip to content

Commit 72df17c

Browse files
fix: add vs-code ide option
1 parent 39d6d45 commit 72df17c

File tree

3 files changed

+82
-7
lines changed

3 files changed

+82
-7
lines changed

src/commands/create.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { load, commands } from 'npm'
3737
import generateTsConfig from '../generators/tsconfig.gen'
3838
import generateTsDeclartionFile from '../generators/declarations.gen'
3939
import generateDotEnv from '../generators/env.gen'
40+
import generateIdeStubs from '../generators/ide.gen'
4041

4142
command(
4243
'create [overwrite]',
@@ -51,6 +52,11 @@ command(
5152
description: 'Overwrite existing application folder'
5253
})
5354

55+
export enum IDE {
56+
VISUAL_STUDIO_CODE = 'Visual Studio Code',
57+
OTHER = 'Other'
58+
}
59+
5460
interface QustionResponse {
5561
readonly name: string
5662
readonly answer: string | boolean
@@ -59,6 +65,7 @@ interface QustionResponse {
5965
interface AnswersDictionary {
6066
readonly fullname: string
6167
readonly isUniversalApp: boolean
68+
readonly ide: IDE
6269
}
6370

6471
interface WorkingAnswersDictionary {
@@ -105,15 +112,17 @@ const Q_SHORT_NAME = {
105112
current: WorkingAnswersDictionary,
106113
stream: Subject<any>
107114
) => {
108-
stream.next(Q_APP_TYPE.question)
115+
stream.next(Q_IDE.question)
109116
}
110117
}
111118

112-
const Q_APP_TYPE = {
119+
const Q_IDE = {
113120
question: {
114-
type: 'confirm',
115-
name: 'isUniversalApp',
116-
message: 'Server rendered (Angular Universal)?'
121+
type: 'list',
122+
name: 'ide',
123+
message: 'Which IDE are you using?',
124+
default: 'Visual Studio Code',
125+
choices: ['Visual Studio Code', 'Other']
117126
},
118127
answerHandler: (
119128
response: QustionResponse,
@@ -124,6 +133,21 @@ const Q_APP_TYPE = {
124133
}
125134
}
126135

136+
// const Q_APP_TYPE = {
137+
// question: {
138+
// type: 'confirm',
139+
// name: 'isUniversalApp',
140+
// message: 'Server rendered (Angular Universal)?'
141+
// },
142+
// answerHandler: (
143+
// response: QustionResponse,
144+
// current: WorkingAnswersDictionary,
145+
// stream: Subject<any>
146+
// ) => {
147+
// stream.complete()
148+
// }
149+
// }
150+
127151
const Q_TEST_RUNNERS = {
128152
question: {
129153
type: 'list',
@@ -144,7 +168,8 @@ const QUESTION_DICT = [
144168
Q_FULL_NAME,
145169
Q_SHORT_NAME,
146170
Q_TEST_RUNNERS,
147-
Q_APP_TYPE
171+
Q_IDE
172+
// Q_APP_TYPE
148173
].reduce(
149174
(acc, curr) => {
150175
return { ...acc, [curr.question.name]: curr }
@@ -313,7 +338,8 @@ function create(overwriteExisting = false) {
313338
generateDotEnv(path, overwriteExisting),
314339
generateFngConfig(path, overwriteExisting),
315340
generateTsConfig(path, overwriteExisting),
316-
generateTsDeclartionFile(path, overwriteExisting)
341+
generateTsDeclartionFile(path, overwriteExisting),
342+
generateIdeStubs(im.config.ide, path, overwriteExisting)
317343
])
318344
}, im => im),
319345
take(1)

src/generators/ide.gen.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { IDE } from '../commands/create'
2+
import { empty } from 'rxjs'
3+
import { resolve } from 'path'
4+
import {
5+
writeFileSafely_,
6+
writeFile_,
7+
mkDirAndContinueIfExists_
8+
} from '../utilities/rx-fs'
9+
import { flatMap } from 'rxjs/operators'
10+
import * as vsCodeSettings from '../templates/vscode/settings.json.txt'
11+
12+
const configPath = '.vscode/settings.json'
13+
const dirRoot = '.vscode'
14+
15+
function handleOther() {
16+
return empty()
17+
}
18+
19+
function handleVSCode(dir: string, overwrite = false) {
20+
return overwrite
21+
? mkDirAndContinueIfExists_(resolve(dir, dirRoot)).pipe(
22+
flatMap(() => writeFile_(resolve(dir, configPath), vsCodeSettings))
23+
)
24+
: mkDirAndContinueIfExists_(resolve(dir, dirRoot)).pipe(
25+
flatMap(() =>
26+
writeFileSafely_(resolve(dir, configPath), vsCodeSettings)
27+
)
28+
)
29+
}
30+
31+
export default function generateIdeStubs(
32+
ide: IDE,
33+
dir: string,
34+
overwrite = false
35+
) {
36+
switch (ide) {
37+
case IDE.OTHER:
38+
return handleOther()
39+
case IDE.VISUAL_STUDIO_CODE:
40+
return handleVSCode(dir, overwrite)
41+
default:
42+
return empty()
43+
}
44+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editor.tabSize": 2,
3+
"npm.enableScriptExplorer": true,
4+
"typescript.tsdk": "node_modules/typescript/lib"
5+
}

0 commit comments

Comments
 (0)