Skip to content

Commit e0d7334

Browse files
author
Dainer Mesa
committed
refactor: Rename download function to install_angular_cli
1 parent 0dfd200 commit e0d7334

1 file changed

Lines changed: 48 additions & 48 deletions

File tree

bin/install

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
download() {
5-
local install_type="$1" version="$2" install_path="$3"
4+
install_angular_cli() {
5+
local install_type="$1" version="$2" install_path="$3"
66

77
# Validate inputs early and provide a helpful error if missing.
88
if [[ -z "${version}" || -z "${install_path}" ]]; then
@@ -119,51 +119,51 @@ download() {
119119
mkdir -p "${install_path}/bin"
120120

121121
# Create a wrapper script that reliably resolves the JS entrypoint
122-
cat > "${install_path}/bin/ng" << "
123-
#!/usr/bin/env node
124-
// This wrapper attempts to resolve the real JS entrypoint for @angular/cli
125-
// using Node's module resolution anchored at the install path. This avoids
126-
// accidentally requiring a shell shim (which causes a syntax error in Node).
127-
const fs = require('fs');
128-
129-
function tryResolve() {
130-
const candidates = [
131-
'${install_path}/lib/node_modules',
132-
'${install_path}/node_modules',
133-
'${install_path}/.pnpm/node_modules',
134-
'${install_path}/.pnpm/@angular+cli@${version}/node_modules'
135-
];
136-
137-
for (const base of candidates) {
138-
try {
139-
const resolved = require.resolve('@angular/cli/bin/ng', { paths: [base] });
140-
if (fs.existsSync(resolved)) return resolved;
141-
} catch (e) {
142-
// ignore and continue
143-
}
144-
}
145-
146-
// Fallback to several common JS file locations
147-
const fallback = [
148-
'${install_path}/lib/node_modules/@angular/cli/bin/ng.js',
149-
'${install_path}/node_modules/@angular/cli/bin/ng.js',
150-
'${install_path}/.pnpm/node_modules/@angular/cli/bin/ng.js',
151-
'${install_path}/.pnpm/@angular+cli@${version}/node_modules/@angular/cli/bin/ng.js'
152-
];
153-
for (const f of fallback) {
154-
if (fs.existsSync(f)) return f;
155-
}
156-
return null;
157-
}
158-
159-
const ngPath = tryResolve();
160-
if (!ngPath) {
161-
console.error('Could not resolve @angular/cli binary (ng) from install path.');
162-
process.exit(1);
163-
}
164-
165-
require(ngPath);
166-
"
122+
cat > "${install_path}/bin/ng" << EOF
123+
#!/usr/bin/env node
124+
// This wrapper attempts to resolve the real JS entrypoint for @angular/cli
125+
// using Node's module resolution anchored at the install path. This avoids
126+
// accidentally requiring a shell shim (which causes a syntax error in Node).
127+
const fs = require('fs');
128+
129+
function tryResolve() {
130+
const candidates = [
131+
'${install_path}/lib/node_modules',
132+
'${install_path}/node_modules',
133+
'${install_path}/.pnpm/node_modules',
134+
'${install_path}/.pnpm/@angular+cli@${version}/node_modules'
135+
];
136+
137+
for (const base of candidates) {
138+
try {
139+
const resolved = require.resolve('@angular/cli/bin/ng', { paths: [base] });
140+
if (fs.existsSync(resolved)) return resolved;
141+
} catch (e) {
142+
// ignore and continue
143+
}
144+
}
145+
146+
// Fallback to several common JS file locations
147+
const fallback = [
148+
'${install_path}/lib/node_modules/@angular/cli/bin/ng.js',
149+
'${install_path}/node_modules/@angular/cli/bin/ng.js',
150+
'${install_path}/.pnpm/node_modules/@angular/cli/bin/ng.js',
151+
'${install_path}/.pnpm/@angular+cli@${version}/node_modules/@angular/cli/bin/ng.js'
152+
];
153+
for (const f of fallback) {
154+
if (fs.existsSync(f)) return f;
155+
}
156+
return null;
157+
}
158+
159+
const ngPath = tryResolve();
160+
if (!ngPath) {
161+
console.error('Could not resolve @angular/cli binary (ng) from install path.');
162+
process.exit(1);
163+
}
164+
165+
require(ngPath);
166+
EOF
167167

168168
chmod +x "${install_path}/bin/ng"
169169
else
@@ -174,4 +174,4 @@ download() {
174174
echo "✅ Angular CLI ${version} installed at ${install_path} (using ${installer})"
175175
}
176176
echo "Installing Angular CLI..."
177-
download $ASDF_INSTALL_TYPE "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
177+
install_angular_cli "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"

0 commit comments

Comments
 (0)