@@ -3,9 +3,10 @@ import path from 'node:path';
3
3
import { mkdirp , copy , dist } from './utils.ts' ;
4
4
5
5
export type TemplateType = ( typeof templateTypes ) [ number ] ;
6
- export type LanguageType = 'typescript' | 'checkjs' | 'none' ;
6
+ export type LanguageType = ( typeof languageTypes ) [ number ] ;
7
7
8
8
const templateTypes = [ 'minimal' , 'demo' , 'library' ] as const ;
9
+ const languageTypes = [ 'typescript' , 'checkjs' , 'none' ] as const ;
9
10
10
11
export type Options = {
11
12
name : string ;
@@ -18,7 +19,7 @@ export type File = {
18
19
contents : string ;
19
20
} ;
20
21
21
- export type Condition = Exclude < TemplateType | LanguageType , 'none' > ;
22
+ export type Condition = TemplateType | LanguageType ;
22
23
23
24
export type Common = {
24
25
files : Array < {
@@ -42,7 +43,7 @@ export const templates: TemplateMetadata[] = templateTypes.map((dir) => {
42
43
const { title, description } = JSON . parse ( fs . readFileSync ( meta_file , 'utf8' ) ) ;
43
44
44
45
return {
45
- name : dir as TemplateType ,
46
+ name : dir ,
46
47
title,
47
48
description
48
49
} ;
@@ -95,13 +96,13 @@ function write_common_files(cwd: string, options: Options, name: string) {
95
96
}
96
97
97
98
function matches_condition ( condition : Condition , options : Options ) {
98
- if ( condition === 'demo' || condition === 'minimal' || condition === 'library' ) {
99
+ if ( templateTypes . includes ( condition as TemplateType ) ) {
99
100
return options . template === condition ;
100
101
}
101
- if ( condition === 'typescript' || condition === 'checkjs' ) {
102
+ if ( languageTypes . includes ( condition as LanguageType ) ) {
102
103
return options . types === condition ;
103
104
}
104
- return ! ! options [ condition ] ;
105
+ return Boolean ( options [ condition as never ] ) ;
105
106
}
106
107
107
108
function merge ( target : any , source : any ) {
@@ -144,8 +145,6 @@ function sort_keys(obj: Record<string, any>) {
144
145
/**
145
146
* Sort files so that those which apply more generically come first so they
146
147
* can be overwritten by files for more precise cases later.
147
- *
148
- * @param {import('./types/internal.js').Common['files'] } files
149
148
*/
150
149
function sort_files ( files : Common [ 'files' ] ) {
151
150
return files . sort ( ( f1 , f2 ) => {
0 commit comments