-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): 修改脚本声明写法,修改 project.scripts 由数组变成对象声明,好处是可以由 project.scri…
…pts.[脚本名].cfg.xxx 进行类型推断实现类型提示。
- Loading branch information
Showing
4 changed files
with
35 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
import { Script } from './script'; | ||
|
||
export interface Project { | ||
export interface ProjectOptions<T extends Record<string, Script>> { | ||
name: string; | ||
level?: number; | ||
domains: string[]; | ||
scripts: Script[]; | ||
scripts: T; | ||
} | ||
|
||
export class Project<T extends Record<string, Script> = Record<string, Script>> implements ProjectOptions<T> { | ||
name: string; | ||
level?: number; | ||
domains: string[]; | ||
scripts: T; | ||
|
||
constructor({ name, level, domains, scripts }: ProjectOptions<T>) { | ||
this.name = name; | ||
this.level = level; | ||
this.domains = domains; | ||
this.scripts = scripts; | ||
} | ||
|
||
static create<T extends Record<string, Script>>(opts: ProjectOptions<T>): Project<T> { | ||
return new Project(opts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { Project } from '../interfaces/project'; | ||
import { CommonProject } from './common'; | ||
import { CXProject } from './cx'; | ||
import { InitProject } from './init'; | ||
import { RenderProject } from './init'; | ||
import { ZHSProject } from './zhs'; | ||
|
||
export function getDefinedProjects() { | ||
return [InitProject, CommonProject, CXProject, ZHSProject]; | ||
export function getDefinedProjects(): Project[] { | ||
return [RenderProject, CommonProject, CXProject, ZHSProject]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters