1
1
import { cp , rm } from "node:fs/promises" ;
2
2
import { resolve } from "node:path" ;
3
+ import { logRaw } from "helpers/cli" ;
3
4
import { brandColor , dim } from "helpers/colors" ;
4
5
import {
5
6
detectPackageManager ,
@@ -12,7 +13,7 @@ import { spinner } from "helpers/interactive";
12
13
import { getFrameworkVersion } from "../index" ;
13
14
import type { PagesGeneratorContext , FrameworkConfig } from "types" ;
14
15
15
- const { npx } = detectPackageManager ( ) ;
16
+ const { npx, npm } = detectPackageManager ( ) ;
16
17
17
18
const generate = async ( ctx : PagesGeneratorContext ) => {
18
19
const version = getFrameworkVersion ( ctx ) ;
@@ -21,17 +22,19 @@ const generate = async (ctx: PagesGeneratorContext) => {
21
22
ctx ,
22
23
`${ npx } @angular/cli@${ version } new ${ ctx . project . name } --standalone`
23
24
) ;
25
+
26
+ logRaw ( "" ) ;
24
27
} ;
25
28
26
29
const configure = async ( ctx : PagesGeneratorContext ) => {
27
30
process . chdir ( ctx . project . path ) ;
28
31
await runCommand ( `${ npx } @angular/cli@next analytics disable` , {
29
32
silent : true ,
30
33
} ) ;
31
- await addSSRAdaptor ( ) ;
34
+ await addSSRAdapter ( ) ;
32
35
await installCFWorker ( ctx ) ;
33
36
await updateAppCode ( ) ;
34
- await updateAngularJson ( ctx ) ;
37
+ updateAngularJson ( ctx ) ;
35
38
} ;
36
39
37
40
const config : FrameworkConfig = {
@@ -54,14 +57,14 @@ export default config;
54
57
55
58
async function installCFWorker ( ctx : PagesGeneratorContext ) {
56
59
const s = spinner ( ) ;
57
- s . start ( `Adding Cloudflare Pages adaptor code` ) ;
60
+ s . start ( `Adding Cloudflare Pages adapter code` ) ;
58
61
await cp (
59
62
// eslint-disable-next-line no-restricted-globals
60
63
resolve ( __dirname , "./angular/templates" ) ,
61
64
resolve ( ctx . project . path ) ,
62
65
{ recursive : true , force : true }
63
66
) ;
64
- s . stop ( `${ brandColor ( "added " ) } ${ dim ( "Cloudflare Pages adaptor code` " ) } ` ) ;
67
+ s . stop ( `${ brandColor ( "copied " ) } ${ dim ( "adapter code" ) } ` ) ;
65
68
66
69
await installPackages (
67
70
[
@@ -75,38 +78,38 @@ async function installCFWorker(ctx: PagesGeneratorContext) {
75
78
] ,
76
79
{
77
80
dev : true ,
78
- startText : "Installing adaptor dependencies" ,
79
- doneText : "Installed" ,
81
+ startText : "Installing adapter dependencies" ,
82
+ doneText : ` ${ brandColor ( "installed" ) } ${ dim ( `via \` ${ npm } install\`` ) } ` ,
80
83
}
81
84
) ;
82
85
}
83
86
84
- async function addSSRAdaptor ( ) {
85
- await runCommand (
86
- `${ npx } ng add @nguniversal/express-engine --skip-confirmation` ,
87
- {
88
- silent : true ,
89
- startText : "Installing Angular SSR" ,
90
- doneText : `${ brandColor ( "installed" ) } ` ,
91
- }
92
- ) ;
87
+ async function addSSRAdapter ( ) {
88
+ const cmd = `${ npx } ng add @nguniversal/express-engine` ;
89
+
90
+ await runCommand ( `${ cmd } --skip-confirmation` , {
91
+ silent : true ,
92
+ startText : "Installing Angular SSR" ,
93
+ doneText : `${ brandColor ( "installed" ) } ${ dim ( `via \`${ cmd } \`` ) } ` ,
94
+ } ) ;
93
95
}
94
96
95
97
async function updateAppCode ( ) {
96
98
const s = spinner ( ) ;
97
99
s . start ( `Updating application code` ) ;
98
100
99
101
// Add the `provideClientHydration()` provider to the app config.
100
- const appConfig = readFile ( resolve ( "src/app/app.config.ts" ) ) ;
102
+ const appConfigPath = "src/app/app.config.ts" ;
103
+ const appConfig = readFile ( resolve ( appConfigPath ) ) ;
101
104
const newAppConfig =
102
105
"import { provideClientHydration } from '@angular/platform-browser';\n" +
103
106
appConfig . replace ( "providers: [" , "providers: [provideClientHydration(), " ) ;
104
- await writeFile ( resolve ( "src/app/app.config.ts" ) , newAppConfig ) ;
107
+ writeFile ( resolve ( appConfigPath ) , newAppConfig ) ;
105
108
106
109
// Remove the unwanted node.js server entry-point
107
110
await rm ( resolve ( "server.ts" ) ) ;
108
111
109
- s . stop ( `Done updating application code ` ) ;
112
+ s . stop ( `${ brandColor ( `updated` ) } ${ dim ( appConfigPath ) } ` ) ;
110
113
}
111
114
112
115
function updateAngularJson ( ctx : PagesGeneratorContext ) {
@@ -121,5 +124,5 @@ function updateAngularJson(ctx: PagesGeneratorContext) {
121
124
delete architectSection [ "serve-ssr" ] ;
122
125
123
126
writeFile ( resolve ( "angular.json" ) , JSON . stringify ( angularJson , null , 2 ) ) ;
124
- s . stop ( `Updated angular.json config ` ) ;
127
+ s . stop ( `${ brandColor ( `updated` ) } ${ dim ( `\` angular.json\`` ) } ` ) ;
125
128
}
0 commit comments