1- import { spawn } from 'node:child_process' ;
21import fs from 'node:fs' ;
32import path from 'node:path' ;
43import logSymbols from 'log-symbols' ;
4+ import { installDependencies , type PackageManagerName , runScript } from 'nypm' ;
55import ora from 'ora' ;
66import {
77 type EmailsDirectory ,
@@ -12,65 +12,9 @@ import { registerSpinnerAutostopping } from '../utils/register-spinner-autostopp
1212
1313interface Args {
1414 dir : string ;
15- packageManager : string ;
15+ packageManager : PackageManagerName ;
1616}
1717
18- const buildPreviewApp = ( absoluteDirectory : string ) => {
19- return new Promise < void > ( ( resolve , reject ) => {
20- const nextBuild = spawn ( 'npm' , [ 'run' , 'build' ] , {
21- cwd : absoluteDirectory ,
22- shell : true ,
23- } ) ;
24- nextBuild . stdout . pipe ( process . stdout ) ;
25- nextBuild . stderr . pipe ( process . stderr ) ;
26-
27- nextBuild . on ( 'close' , ( code ) => {
28- if ( code === 0 ) {
29- resolve ( ) ;
30- } else {
31- reject (
32- new Error (
33- `Unable to build the Next app and it exited with code: ${ code } ` ,
34- ) ,
35- ) ;
36- }
37- } ) ;
38- } ) ;
39- } ;
40-
41- const npmInstall = async (
42- builtPreviewAppPath : string ,
43- packageManager : string ,
44- ) => {
45- return new Promise < void > ( ( resolve , reject ) => {
46- const childProc = spawn (
47- packageManager ,
48- [
49- 'install' ,
50- packageManager === 'deno' ? '' : '--include=dev' ,
51- packageManager === 'deno' ? '--quiet' : '--silent' ,
52- ] ,
53- {
54- cwd : builtPreviewAppPath ,
55- shell : true ,
56- } ,
57- ) ;
58- childProc . stdout . pipe ( process . stdout ) ;
59- childProc . stderr . pipe ( process . stderr ) ;
60- childProc . on ( 'close' , ( code ) => {
61- if ( code === 0 ) {
62- resolve ( ) ;
63- } else {
64- reject (
65- new Error (
66- `Unable to install the dependencies and it exited with code: ${ code } ` ,
67- ) ,
68- ) ;
69- }
70- } ) ;
71- } ) ;
72- } ;
73-
7418const setNextEnvironmentVariablesForBuild = async (
7519 emailsDirRelativePath : string ,
7620 builtPreviewAppPath : string ,
@@ -283,14 +227,21 @@ export const build = async ({
283227 await updatePackageJson ( builtPreviewAppPath ) ;
284228
285229 spinner . text = 'Installing dependencies on `.react-email`' ;
286- await npmInstall ( builtPreviewAppPath , packageManager ) ;
230+ await installDependencies ( {
231+ cwd : builtPreviewAppPath ,
232+ silent : true ,
233+ packageManager,
234+ } ) ;
287235
288236 spinner . stopAndPersist ( {
289237 text : 'Successfully prepared `.react-email` for `next build`' ,
290238 symbol : logSymbols . success ,
291239 } ) ;
292240
293- await buildPreviewApp ( builtPreviewAppPath ) ;
241+ await runScript ( 'build' , {
242+ packageManager,
243+ cwd : builtPreviewAppPath ,
244+ } ) ;
294245 } catch ( error ) {
295246 console . log ( error ) ;
296247 process . exit ( 1 ) ;
0 commit comments