FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
angular-cli/scripts/create.mts at main · angular/angular-cli · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
angular
/
angular-cli
Public
Notifications
You must be signed in to change notification settings
Fork
11.8k
Star
27k
Code
Issues
254
Pull requests
17
Actions
Security and quality
5
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
angular-cli
/
scripts
/
create.mts
Copy path
More file actions
More file actions
Latest commit
History
History
History
112 lines (89 loc) · 3.34 KB
Breadcrumbs
angular-cli
/
scripts
/
create.mts
Copy path
File metadata and controls
112 lines (89 loc) · 3.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
*
@license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import
assert
from
'node:assert'
;
import
*
as
child_process
from
'node:child_process'
;
import
{
copyFile
,
readFile
,
rm
,
writeFile
}
from
'node:fs/promises'
;
import
*
as
path
from
'node:path'
;
import
{
pathToFileURL
}
from
'node:url'
;
import
build
from
'./build.mts'
;
import
{
packages
}
from
'./packages.mts'
;
export
interface
CreateOptions
extends
Record
<
string
,
unknown
>
{
_
:
string
[
]
;
}
const
__dirname
=
import
.
meta
.
dirname
;
async
function
_exec
(
command
:
string
,
args
:
string
[
]
,
opts
:
{
cwd
?:
string
}
)
{
const
{
status
,
error
,
stderr
,
stdout
}
=
child_process
.
spawnSync
(
command
,
args
,
{
...
opts
}
)
;
if
(
status
!=
0
)
{
console
.
error
(
`Command failed:
${
command
}
${
args
.
map
(
(
x
)
=>
JSON
.
stringify
(
x
)
)
.
join
(
', '
)
}
`
)
;
if
(
error
)
{
console
.
error
(
'Error: '
+
(
error
?
error
.
message
:
'undefined'
)
)
;
}
else
{
console
.
error
(
`STDERR:\n
${
stderr
}
`
)
;
}
throw
error
;
}
return
{
stdout
}
;
}
export
default
async
function
(
args
:
CreateOptions
,
cwd
:
string
)
:
Promise
<
number
>
{
const
{
_
,
...
otherArgOptions
}
=
args
;
const
projectName
=
_
[
0
]
;
assert
(
projectName
,
'Project name must be provided.'
)
;
const
ngNewAdditionalOptions
=
Object
.
entries
(
otherArgOptions
)
.
map
(
(
[
key
,
value
]
)
=>
`--
${
key
}
=
${
value
}
`
,
)
;
const
oldCwd
=
process
.
cwd
(
)
;
console
.
info
(
'Building...'
)
;
const
buildResult
=
await
build
(
{
local
:
true
}
)
;
const
cliBuild
=
buildResult
.
find
(
(
{
name
}
)
=>
name
===
'angular/cli'
)
;
assert
(
cliBuild
)
;
process
.
chdir
(
cwd
)
;
// The below is needed as NPX does not guarantee that the updated version is used unless the file name changes.
const
newTarballName
=
cliBuild
.
tarPath
.
replace
(
'.tgz'
,
'-'
+
Date
.
now
(
)
+
'.tgz'
)
;
await
copyFile
(
cliBuild
.
tarPath
,
newTarballName
)
;
console
.
info
(
'Creating project...'
)
;
try
{
await
_exec
(
'npx'
,
[
'--yes'
,
pathToFileURL
(
newTarballName
)
.
toString
(
)
,
'new'
,
projectName
,
'--skip-install'
,
'--skip-git'
,
'--no-interactive'
,
...
ngNewAdditionalOptions
,
]
,
{
cwd
}
,
)
;
}
finally
{
await
rm
(
newTarballName
,
{
maxRetries
:
3
}
)
;
}
console
.
info
(
'Updating package.json...'
)
;
const
packageJsonPath
=
path
.
join
(
projectName
,
'package.json'
)
;
const
packageJson
=
JSON
.
parse
(
await
readFile
(
packageJsonPath
,
'utf-8'
)
)
;
packageJson
[
'dependencies'
]
??=
{
}
;
packageJson
[
'devDependencies'
]
??=
{
}
;
packageJson
[
'overrides'
]
??=
{
}
;
// Set the dependencies to the new build we just used.
for
(
const
packageName
of
packages
.
map
(
(
{
name
}
)
=>
name
)
)
{
const
tar
=
path
.
join
(
__dirname
,
'../dist'
,
packageName
.
replace
(
/
\/
|
@
/
g
,
'_'
)
+
'.tgz'
)
;
if
(
packageName
in
packageJson
[
'dependencies'
]
)
{
packageJson
[
'dependencies'
]
[
packageName
]
=
tar
;
}
else
if
(
packageName
in
packageJson
[
'devDependencies'
]
)
{
packageJson
[
'devDependencies'
]
[
packageName
]
=
tar
;
}
else
{
packageJson
[
'overrides'
]
[
packageName
]
=
tar
;
}
}
await
writeFile
(
packageJsonPath
,
JSON
.
stringify
(
packageJson
,
null
,
2
)
,
'utf-8'
)
;
console
.
info
(
'Installing npm packages...'
)
;
await
_exec
(
'npm'
,
[
'install'
]
,
{
cwd
:
path
.
join
(
cwd
,
projectName
)
}
)
;
process
.
chdir
(
oldCwd
)
;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL