1
1
/**
2
- * @import {ElmJson} from './types/content';
2
+ * @import {ApplicationElmJson, PackageName} from './types/content';
3
+ * @import {Path} from './types/path';
4
+ * @import {Options, RuleType} from './types/options';
3
5
*/
4
6
const childProcess = require ( 'node:child_process' ) ;
5
7
const path = require ( 'node:path' ) ;
@@ -14,6 +16,9 @@ const MinVersion = require('./min-version');
14
16
const NewRule = require ( './new-rule' ) ;
15
17
const Spinner = require ( './spinner' ) ;
16
18
19
+ /**
20
+ * @param {Options } options
21
+ */
17
22
async function create ( options ) {
18
23
const onCancelOptions = {
19
24
onCancel : ( ) => {
@@ -25,7 +30,7 @@ async function create(options) {
25
30
let canceled = false ;
26
31
27
32
const authorName =
28
- options . prefilledAnswers . authorName ||
33
+ options . prefilledAnswers . authorName ??
29
34
( await prompts (
30
35
[
31
36
{
@@ -49,7 +54,7 @@ async function create(options) {
49
54
}
50
55
51
56
const license =
52
- options . prefilledAnswers . license ||
57
+ options . prefilledAnswers . license ??
53
58
( await prompts (
54
59
[
55
60
{
@@ -73,7 +78,7 @@ async function create(options) {
73
78
return ;
74
79
}
75
80
76
- const ruleType = options . ruleType || ( await NewRule . askForRuleType ( ) ) ;
81
+ const ruleType = options . ruleType ?? ( await NewRule . askForRuleType ( ) ) ;
77
82
if ( ! ruleType ) {
78
83
return ;
79
84
}
@@ -98,6 +103,9 @@ I hope you'll enjoy working with ${chalk.greenBright('elm-review')}! ❤️
98
103
) ;
99
104
}
100
105
106
+ /**
107
+ * @param {string } packageName
108
+ */
101
109
function validatePackageName ( packageName ) {
102
110
if ( ! packageName . startsWith ( 'elm-review-' ) ) {
103
111
throw new ErrorMessage . CustomError (
@@ -146,10 +154,24 @@ const elmToolingJson = {
146
154
}
147
155
} ;
148
156
157
+ /**
158
+ * @param {Path } dir
159
+ * @param {string } fileName
160
+ * @param {string } content
161
+ * @returns {Promise<void> }
162
+ */
149
163
async function writeFile ( dir , fileName , content ) {
150
164
await FS . writeFile ( path . join ( dir , fileName ) , content ) ;
151
165
}
152
166
167
+ /**
168
+ * @param {Options } options
169
+ * @param {string } authorName
170
+ * @param {PackageName } packageName
171
+ * @param {string } ruleName
172
+ * @param {RuleType } ruleType
173
+ * @param {string } license
174
+ */
153
175
async function createProject (
154
176
options ,
155
177
authorName ,
@@ -196,7 +218,7 @@ async function createProject(
196
218
197
219
// Adding package to the example's elm.json
198
220
const previewElmJsonPath = path . join ( pathToPreview , 'elm.json' ) ;
199
- const previewElmJson = /** @type {ElmJson } */ (
221
+ const previewElmJson = /** @type {ApplicationElmJson } */ (
200
222
await FS . readJsonFile ( previewElmJsonPath )
201
223
) ;
202
224
previewElmJson [ 'source-directories' ] = [
@@ -320,6 +342,12 @@ ElmjutsuDumMyM0DuL3.elm
320
342
Spinner . succeed ( ) ;
321
343
}
322
344
345
+ /**
346
+ * @param {string } authorName
347
+ * @param {PackageName } packageName
348
+ * @param {string } ruleName
349
+ * @param {string } license
350
+ */
323
351
function elmJson ( authorName , packageName , ruleName , license ) {
324
352
return {
325
353
type : 'package' ,
@@ -340,6 +368,11 @@ function elmJson(authorName, packageName, ruleName, license) {
340
368
} ;
341
369
}
342
370
371
+ /**
372
+ * @param {string } authorName
373
+ * @param {PackageName } packageName
374
+ * @param {string } ruleName
375
+ */
343
376
function readme ( authorName , packageName , ruleName ) {
344
377
return `# ${ packageName }
345
378
@@ -373,6 +406,10 @@ elm-review --template ${authorName}/${packageName}/example
373
406
` ;
374
407
}
375
408
409
+ /**
410
+ * @param {Options } options
411
+ * @param {PackageName } packageName
412
+ */
376
413
function packageJson ( options , packageName ) {
377
414
return {
378
415
name : packageName ,
0 commit comments