@@ -2,61 +2,6 @@ import { NextConfig } from "next"
22import { ValidCNSInputs } from "./create-next-stack-types"
33import { DeeplyReadonly } from "./helpers/deeply-readonly"
44
5- export const createPlugin = < TPluginConfig extends PluginConfig > (
6- pluginConfig : TPluginConfig
7- ) : Plugin < TPluginConfig > => {
8- const plugin = {
9- ...pluginConfig ,
10- }
11- const enhancements = {
12- steps :
13- pluginConfig . steps != null
14- ? Object . entries ( pluginConfig . steps ) . reduce (
15- ( acc , [ key , value ] ) => ( {
16- ...acc ,
17- [ key ] : createStep ( value , plugin as Plugin < TPluginConfig > ) ,
18- } ) ,
19- { } as Record < string , Step >
20- )
21- : undefined ,
22- }
23- for ( const [ key , value ] of Object . entries ( enhancements ) ) {
24- Object . defineProperty ( plugin , key , {
25- value,
26- enumerable : true ,
27- } )
28- }
29- return plugin as Plugin < TPluginConfig >
30- }
31-
32- export const createStep = < TRawStep extends RawStep = RawStep > (
33- step : TRawStep ,
34- plugin : Plugin
35- ) : Step < TRawStep > => {
36- return {
37- // defaults
38- shouldRun : true ,
39-
40- // step
41- ...step ,
42-
43- // enhancements
44- plugin,
45- }
46- }
47-
48- export type Plugin < TPluginConfig extends PluginConfig = PluginConfig > =
49- TPluginConfig & {
50- steps ?: {
51- [ key in keyof TPluginConfig [ "steps" ] ] : Step < RawStep > // TODO: Fix type. This should be Step<TPluginConfig["steps"][key]>, but that doesn't work.
52- }
53- }
54-
55- export type Step < TStep extends RawStep = RawStep > = TStep & {
56- shouldRun : NonNullable < RawStep [ "shouldRun" ] >
57- plugin : Plugin
58- }
59-
605type PluginConfig = DeeplyReadonly < {
616 /** Name of the plugin */
627 name : string
@@ -70,7 +15,7 @@ type PluginConfig = DeeplyReadonly<{
7015 devDependencies ?: Record < string , Package >
7116 /** Temporary dependencies uninstalled when Create Next Stack is done. */
7217 tmpDependencies ?: Record < string , Package >
73- /** Technology descriptions */
18+ /** Descriptions of the technologies supported by the plugin. */
7419 technologies ?: Technology [ ]
7520 /** Scripts that are added to the package.json file. */
7621 scripts ?: Script [ ]
@@ -153,7 +98,6 @@ type RawStep = {
15398 */
15499 description : string
155100
156- // TODO: Consider memoizing shouldRun, as it is sometimes called multiple times. See the lint-staged setup step.
157101 /**
158102 * A boolean or function that determines whether the custom run function should run.
159103 *
@@ -165,6 +109,63 @@ type RawStep = {
165109 run : ( inputs : ValidCNSInputs ) => Promise < void >
166110}
167111
112+ export const createPlugin = < TPluginConfig extends PluginConfig > (
113+ pluginConfig : TPluginConfig
114+ ) : Plugin < TPluginConfig > => {
115+ const plugin = {
116+ ...pluginConfig ,
117+ }
118+ const enhancements = {
119+ steps :
120+ pluginConfig . steps != null
121+ ? Object . entries ( pluginConfig . steps ) . reduce (
122+ ( acc , [ key , value ] ) => ( {
123+ ...acc ,
124+ [ key ] : createStep ( value , plugin as Plugin < TPluginConfig > ) ,
125+ } ) ,
126+ { } as Record < string , Step >
127+ )
128+ : undefined ,
129+ }
130+ for ( const [ key , value ] of Object . entries ( enhancements ) ) {
131+ Object . defineProperty ( plugin , key , {
132+ value,
133+ enumerable : true ,
134+ } )
135+ }
136+ return plugin as Plugin < TPluginConfig >
137+ }
138+
139+ export const createStep = < TRawStep extends RawStep = RawStep > (
140+ step : TRawStep ,
141+ plugin : Plugin
142+ ) : Step < TRawStep > => {
143+ return {
144+ // defaults
145+ shouldRun : true ,
146+
147+ // TODO: Consider memoizing shouldRun, as it is sometimes called multiple times. See the lint-staged setup step.
148+
149+ // step
150+ ...step ,
151+
152+ // enhancements
153+ plugin,
154+ }
155+ }
156+
157+ export type Plugin < TPluginConfig extends PluginConfig = PluginConfig > =
158+ TPluginConfig & {
159+ steps ?: {
160+ [ key in keyof TPluginConfig [ "steps" ] ] : Step < RawStep > // TODO: Fix type. This should be Step<TPluginConfig["steps"][key]>, but that doesn't work.
161+ }
162+ }
163+
164+ export type Step < TStep extends RawStep = RawStep > = TStep & {
165+ shouldRun : NonNullable < RawStep [ "shouldRun" ] >
166+ plugin : Plugin
167+ }
168+
168169export const evalActive = (
169170 active : PluginConfig [ "active" ] ,
170171 inputs : ValidCNSInputs
0 commit comments