@@ -60,6 +60,40 @@ describe('CLI generate command test', () => {
6060 expect ( fs . existsSync ( path . join ( workDir , 'bar/schema.ts' ) ) ) . toBe ( true ) ;
6161 } ) ;
6262
63+ it ( 'should respect plugin lite options' , async ( ) => {
64+ const modelWithPlugin = `
65+ plugin typescript {
66+ provider = "@core/typescript"
67+ lite = true
68+ }
69+
70+ model User {
71+ id String @id @default(cuid())
72+ }
73+ ` ;
74+ const { workDir } = await createProject ( modelWithPlugin ) ;
75+ runCli ( 'generate' , workDir ) ;
76+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
77+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema-lite.ts' ) ) ) . toBe ( true ) ;
78+ } ) ;
79+
80+ it ( 'should respect plugin lite-only options' , async ( ) => {
81+ const modelWithPlugin = `
82+ plugin typescript {
83+ provider = "@core/typescript"
84+ liteOnly = true
85+ }
86+
87+ model User {
88+ id String @id @default(cuid())
89+ }
90+ ` ;
91+ const { workDir } = await createProject ( modelWithPlugin ) ;
92+ runCli ( 'generate' , workDir ) ;
93+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( false ) ;
94+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema-lite.ts' ) ) ) . toBe ( true ) ;
95+ } ) ;
96+
6397 it ( 'should respect lite option' , async ( ) => {
6498 const { workDir } = await createProject ( model ) ;
6599 runCli ( 'generate --lite' , workDir ) ;
@@ -73,4 +107,114 @@ describe('CLI generate command test', () => {
73107 expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( false ) ;
74108 expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema-lite.ts' ) ) ) . toBe ( true ) ;
75109 } ) ;
110+
111+ it ( 'should respect explicit liteOnly true option' , async ( ) => {
112+ const { workDir } = await createProject ( model ) ;
113+ runCli ( 'generate --lite-only=true' , workDir ) ;
114+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( false ) ;
115+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema-lite.ts' ) ) ) . toBe ( true ) ;
116+ } ) ;
117+
118+ it ( 'should respect explicit liteOnly false option' , async ( ) => {
119+ const { workDir } = await createProject ( model ) ;
120+ runCli ( 'generate --lite-only=false' , workDir ) ;
121+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
122+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema-lite.ts' ) ) ) . toBe ( false ) ;
123+ } ) ;
124+
125+ it ( 'should prefer CLI options over @core/typescript plugin settings for lite and liteOnly' , async ( ) => {
126+ const modelWithPlugin = `
127+ plugin typescript {
128+ provider = "@core/typescript"
129+ lite = true
130+ liteOnly = true
131+ }
132+
133+ model User {
134+ id String @id @default(cuid())
135+ }
136+ ` ;
137+ const { workDir } = await createProject ( modelWithPlugin ) ;
138+ runCli ( 'generate --lite=false --lite-only=false' , workDir ) ;
139+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
140+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema-lite.ts' ) ) ) . toBe ( false ) ;
141+ } ) ;
142+
143+ it ( 'should generate models.ts and input.ts by default' , async ( ) => {
144+ const { workDir } = await createProject ( model ) ;
145+ runCli ( 'generate' , workDir ) ;
146+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
147+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/models.ts' ) ) ) . toBe ( true ) ;
148+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/input.ts' ) ) ) . toBe ( true ) ;
149+ } ) ;
150+
151+ it ( 'should respect plugin options for generateModels and generateInput by default' , async ( ) => {
152+ const modelWithPlugin = `
153+ plugin typescript {
154+ provider = "@core/typescript"
155+ generateModels = false
156+ generateInput = false
157+ }
158+
159+ model User {
160+ id String @id @default(cuid())
161+ }
162+ ` ;
163+ const { workDir } = await createProject ( modelWithPlugin ) ;
164+ runCli ( 'generate' , workDir ) ;
165+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
166+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/models.ts' ) ) ) . toBe ( false ) ;
167+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/input.ts' ) ) ) . toBe ( false ) ;
168+ } ) ;
169+
170+ it ( 'should generate models.ts when --generate-models=true is passed' , async ( ) => {
171+ const { workDir } = await createProject ( model ) ;
172+ runCli ( 'generate --generate-models=true' , workDir ) ;
173+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
174+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/models.ts' ) ) ) . toBe ( true ) ;
175+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/input.ts' ) ) ) . toBe ( true ) ;
176+ } ) ;
177+
178+ it ( 'should not generate models.ts when --generate-models=false is passed' , async ( ) => {
179+ const { workDir } = await createProject ( model ) ;
180+ runCli ( 'generate --generate-models=false' , workDir ) ;
181+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
182+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/models.ts' ) ) ) . toBe ( false ) ;
183+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/input.ts' ) ) ) . toBe ( true ) ;
184+ } ) ;
185+
186+ it ( 'should generate input.ts when --generate-input=true is passed' , async ( ) => {
187+ const { workDir } = await createProject ( model ) ;
188+ runCli ( 'generate --generate-input=true' , workDir ) ;
189+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
190+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/models.ts' ) ) ) . toBe ( true ) ;
191+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/input.ts' ) ) ) . toBe ( true ) ;
192+ } ) ;
193+
194+ it ( 'should not generate input.ts when --generate-input=false is passed' , async ( ) => {
195+ const { workDir } = await createProject ( model ) ;
196+ runCli ( 'generate --generate-input=false' , workDir ) ;
197+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
198+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/models.ts' ) ) ) . toBe ( true ) ;
199+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/input.ts' ) ) ) . toBe ( false ) ;
200+ } ) ;
201+
202+ it ( 'should prefer CLI options over @core/typescript plugin settings for generateModels and generateInput' , async ( ) => {
203+ const modelWithPlugin = `
204+ plugin typescript {
205+ provider = "@core/typescript"
206+ generateModels = false
207+ generateInput = false
208+ }
209+
210+ model User {
211+ id String @id @default(cuid())
212+ }
213+ ` ;
214+ const { workDir } = await createProject ( modelWithPlugin ) ;
215+ runCli ( 'generate --generate-models --generate-input' , workDir ) ;
216+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
217+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/models.ts' ) ) ) . toBe ( true ) ;
218+ expect ( fs . existsSync ( path . join ( workDir , 'zenstack/input.ts' ) ) ) . toBe ( true ) ;
219+ } ) ;
76220} ) ;
0 commit comments