@fredlackey/devutils 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/package.json +1 -1
- package/src/commands/install.js +374 -36
- package/src/installs/adobe-creative-cloud.js +527 -25
- package/src/installs/adobe-creative-cloud.md +605 -0
- package/src/installs/appcleaner.js +303 -26
- package/src/installs/appcleaner.md +699 -0
- package/src/installs/apt-transport-https.js +390 -0
- package/src/installs/apt-transport-https.md +678 -0
- package/src/installs/atomicparsley.js +624 -26
- package/src/installs/atomicparsley.md +795 -0
- package/src/installs/aws-cli.js +779 -26
- package/src/installs/aws-cli.md +727 -0
- package/src/installs/balena-etcher.js +688 -26
- package/src/installs/balena-etcher.md +761 -0
- package/src/installs/bambu-studio.js +912 -26
- package/src/installs/bambu-studio.md +780 -0
- package/src/installs/bash-completion.js +554 -23
- package/src/installs/bash-completion.md +833 -0
- package/src/installs/bash.js +399 -26
- package/src/installs/bash.md +993 -0
- package/src/installs/beyond-compare.js +585 -26
- package/src/installs/beyond-compare.md +813 -0
- package/src/installs/build-essential.js +511 -26
- package/src/installs/build-essential.md +977 -0
- package/src/installs/ca-certificates.js +618 -0
- package/src/installs/ca-certificates.md +937 -0
- package/src/installs/caffeine.js +490 -26
- package/src/installs/caffeine.md +839 -0
- package/src/installs/camtasia.js +577 -25
- package/src/installs/camtasia.md +762 -0
- package/src/installs/chatgpt.js +458 -26
- package/src/installs/chatgpt.md +814 -0
- package/src/installs/chocolatey.js +447 -0
- package/src/installs/chocolatey.md +661 -0
- package/src/installs/chrome-canary.js +472 -26
- package/src/installs/chrome-canary.md +641 -0
- package/src/installs/chromium.js +645 -26
- package/src/installs/chromium.md +838 -0
- package/src/installs/claude-code.js +558 -26
- package/src/installs/claude-code.md +1173 -0
- package/src/installs/curl.js +361 -26
- package/src/installs/curl.md +714 -0
- package/src/installs/cursor.js +561 -26
- package/src/installs/cursor.md +970 -0
- package/src/installs/dbschema.js +674 -26
- package/src/installs/dbschema.md +925 -0
- package/src/installs/dependencies.md +435 -0
- package/src/installs/development-tools.js +600 -0
- package/src/installs/development-tools.md +977 -0
- package/src/installs/docker.js +1010 -25
- package/src/installs/docker.md +1109 -0
- package/src/installs/drawio.js +1001 -26
- package/src/installs/drawio.md +795 -0
- package/src/installs/elmedia-player.js +328 -25
- package/src/installs/elmedia-player.md +556 -0
- package/src/installs/ffmpeg.js +870 -25
- package/src/installs/ffmpeg.md +852 -0
- package/src/installs/file.js +464 -0
- package/src/installs/file.md +987 -0
- package/src/installs/gemini-cli.js +793 -26
- package/src/installs/gemini-cli.md +1153 -0
- package/src/installs/git.js +382 -26
- package/src/installs/git.md +907 -0
- package/src/installs/gitego.js +931 -26
- package/src/installs/gitego.md +1172 -0
- package/src/installs/go.js +913 -26
- package/src/installs/go.md +958 -0
- package/src/installs/google-chrome.js +801 -25
- package/src/installs/google-chrome.md +862 -0
- package/src/installs/gpg.js +412 -73
- package/src/installs/gpg.md +1056 -0
- package/src/installs/homebrew.js +1015 -26
- package/src/installs/homebrew.md +988 -0
- package/src/installs/imageoptim.js +950 -26
- package/src/installs/imageoptim.md +1119 -0
- package/src/installs/installers.json +2297 -0
- package/src/installs/jq.js +382 -26
- package/src/installs/jq.md +809 -0
- package/src/installs/keyboard-maestro.js +701 -26
- package/src/installs/keyboard-maestro.md +825 -0
- package/src/installs/latex.js +771 -26
- package/src/installs/latex.md +1095 -0
- package/src/installs/lftp.js +338 -26
- package/src/installs/lftp.md +907 -0
- package/src/installs/lsb-release.js +346 -0
- package/src/installs/lsb-release.md +814 -0
- package/src/installs/messenger.js +829 -26
- package/src/installs/messenger.md +900 -0
- package/src/installs/microsoft-office.js +550 -26
- package/src/installs/microsoft-office.md +760 -0
- package/src/installs/microsoft-teams.js +782 -25
- package/src/installs/microsoft-teams.md +886 -0
- package/src/installs/node.js +886 -26
- package/src/installs/node.md +1153 -0
- package/src/installs/nordpass.js +698 -26
- package/src/installs/nordpass.md +921 -0
- package/src/installs/nvm.js +977 -26
- package/src/installs/nvm.md +1057 -0
- package/src/installs/openssh.js +734 -64
- package/src/installs/openssh.md +1056 -0
- package/src/installs/pandoc.js +644 -26
- package/src/installs/pandoc.md +1036 -0
- package/src/installs/pinentry.js +492 -26
- package/src/installs/pinentry.md +1142 -0
- package/src/installs/pngyu.js +851 -26
- package/src/installs/pngyu.md +896 -0
- package/src/installs/postman.js +781 -26
- package/src/installs/postman.md +940 -0
- package/src/installs/procps.js +425 -0
- package/src/installs/procps.md +851 -0
- package/src/installs/safari-tech-preview.js +355 -25
- package/src/installs/safari-tech-preview.md +533 -0
- package/src/installs/sfnt2woff.js +640 -26
- package/src/installs/sfnt2woff.md +795 -0
- package/src/installs/shellcheck.js +463 -26
- package/src/installs/shellcheck.md +1005 -0
- package/src/installs/slack.js +722 -25
- package/src/installs/slack.md +865 -0
- package/src/installs/snagit.js +566 -25
- package/src/installs/snagit.md +844 -0
- package/src/installs/software-properties-common.js +372 -0
- package/src/installs/software-properties-common.md +805 -0
- package/src/installs/spotify.js +858 -25
- package/src/installs/spotify.md +901 -0
- package/src/installs/studio-3t.js +803 -26
- package/src/installs/studio-3t.md +918 -0
- package/src/installs/sublime-text.js +780 -25
- package/src/installs/sublime-text.md +914 -0
- package/src/installs/superwhisper.js +687 -25
- package/src/installs/superwhisper.md +630 -0
- package/src/installs/tailscale.js +727 -26
- package/src/installs/tailscale.md +1100 -0
- package/src/installs/tar.js +389 -0
- package/src/installs/tar.md +946 -0
- package/src/installs/termius.js +780 -26
- package/src/installs/termius.md +844 -0
- package/src/installs/terraform.js +761 -26
- package/src/installs/terraform.md +899 -0
- package/src/installs/tidal.js +752 -25
- package/src/installs/tidal.md +864 -0
- package/src/installs/tmux.js +328 -26
- package/src/installs/tmux.md +1030 -0
- package/src/installs/tree.js +393 -26
- package/src/installs/tree.md +833 -0
- package/src/installs/unzip.js +460 -0
- package/src/installs/unzip.md +879 -0
- package/src/installs/vim.js +403 -26
- package/src/installs/vim.md +1040 -0
- package/src/installs/vlc.js +803 -26
- package/src/installs/vlc.md +927 -0
- package/src/installs/vscode.js +825 -26
- package/src/installs/vscode.md +1002 -0
- package/src/installs/wget.js +415 -0
- package/src/installs/wget.md +791 -0
- package/src/installs/whatsapp.js +710 -25
- package/src/installs/whatsapp.md +854 -0
- package/src/installs/winpty.js +352 -0
- package/src/installs/winpty.md +620 -0
- package/src/installs/woff2.js +535 -26
- package/src/installs/woff2.md +977 -0
- package/src/installs/wsl.js +572 -0
- package/src/installs/wsl.md +699 -0
- package/src/installs/xcode-clt.js +520 -0
- package/src/installs/xcode-clt.md +351 -0
- package/src/installs/xcode.js +542 -26
- package/src/installs/xcode.md +573 -0
- package/src/installs/yarn.js +806 -26
- package/src/installs/yarn.md +1074 -0
- package/src/installs/yq.js +636 -26
- package/src/installs/yq.md +944 -0
- package/src/installs/yt-dlp.js +683 -26
- package/src/installs/yt-dlp.md +946 -0
- package/src/installs/yum-utils.js +297 -0
- package/src/installs/yum-utils.md +648 -0
- package/src/installs/zoom.js +740 -25
- package/src/installs/zoom.md +884 -0
- package/src/scripts/README.md +567 -45
- package/src/scripts/STATUS.md +208 -0
- package/src/scripts/afk.js +395 -7
- package/src/scripts/backup-all.js +731 -9
- package/src/scripts/backup-source.js +711 -8
- package/src/scripts/brewd.js +373 -7
- package/src/scripts/brewi.js +505 -9
- package/src/scripts/brewr.js +512 -9
- package/src/scripts/brews.js +462 -9
- package/src/scripts/brewu.js +488 -7
- package/src/scripts/c.js +185 -7
- package/src/scripts/ccurl.js +325 -8
- package/src/scripts/certbot-crontab-init.js +488 -8
- package/src/scripts/certbot-init.js +641 -9
- package/src/scripts/ch.js +339 -7
- package/src/scripts/claude-danger.js +253 -8
- package/src/scripts/clean-dev.js +419 -8
- package/src/scripts/clear-dns-cache.js +525 -7
- package/src/scripts/clone.js +417 -7
- package/src/scripts/code-all.js +420 -7
- package/src/scripts/count-files.js +195 -8
- package/src/scripts/count-folders.js +195 -8
- package/src/scripts/count.js +248 -8
- package/src/scripts/d.js +203 -7
- package/src/scripts/datauri.js +373 -8
- package/src/scripts/delete-files.js +363 -7
- package/src/scripts/docker-clean.js +410 -8
- package/src/scripts/dp.js +426 -7
- package/src/scripts/e.js +375 -9
- package/src/scripts/empty-trash.js +497 -7
- package/src/scripts/evm.js +428 -9
- package/src/scripts/fetch-github-repos.js +441 -10
- package/src/scripts/get-channel.js +329 -8
- package/src/scripts/get-course.js +384 -11
- package/src/scripts/get-dependencies.js +290 -9
- package/src/scripts/get-folder.js +783 -10
- package/src/scripts/get-tunes.js +411 -10
- package/src/scripts/get-video.js +352 -9
- package/src/scripts/git-backup.js +561 -9
- package/src/scripts/git-clone.js +477 -9
- package/src/scripts/git-pup.js +303 -7
- package/src/scripts/git-push.js +380 -8
- package/src/scripts/h.js +607 -9
- package/src/scripts/hide-desktop-icons.js +483 -7
- package/src/scripts/hide-hidden-files.js +522 -7
- package/src/scripts/install-dependencies-from.js +440 -9
- package/src/scripts/ips.js +647 -10
- package/src/scripts/iso.js +354 -8
- package/src/scripts/killni.js +561 -7
- package/src/scripts/ll.js +451 -8
- package/src/scripts/local-ip.js +310 -8
- package/src/scripts/m.js +508 -8
- package/src/scripts/map.js +293 -8
- package/src/scripts/mkd.js +287 -7
- package/src/scripts/ncu-update-all.js +441 -8
- package/src/scripts/nginx-init.js +702 -12
- package/src/scripts/npmi.js +366 -7
- package/src/scripts/o.js +495 -8
- package/src/scripts/org-by-date.js +321 -7
- package/src/scripts/p.js +208 -7
- package/src/scripts/packages.js +313 -8
- package/src/scripts/path.js +209 -7
- package/src/scripts/ports.js +582 -8
- package/src/scripts/q.js +290 -8
- package/src/scripts/refresh-files.js +378 -10
- package/src/scripts/remove-smaller-files.js +500 -8
- package/src/scripts/rename-files-with-date.js +517 -9
- package/src/scripts/resize-image.js +523 -9
- package/src/scripts/rm-safe.js +653 -8
- package/src/scripts/s.js +525 -9
- package/src/scripts/set-git-public.js +349 -7
- package/src/scripts/show-desktop-icons.js +459 -7
- package/src/scripts/show-hidden-files.js +456 -7
- package/src/scripts/tpa.js +265 -8
- package/src/scripts/tpo.js +264 -7
- package/src/scripts/u.js +489 -7
- package/src/scripts/vpush.js +422 -8
- package/src/scripts/y.js +267 -7
- package/src/utils/common/os.js +94 -2
- package/src/utils/ubuntu/apt.js +13 -7
- package/src/utils/windows/choco.js +82 -26
- package/src/utils/windows/winget.js +89 -27
|
@@ -1,25 +1,456 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* install-dependencies-from - Install dependencies from another package.json
|
|
5
|
+
*
|
|
6
|
+
* Migrated from legacy dotfiles function.
|
|
7
|
+
* Original:
|
|
8
|
+
* install-dependencies-from() {
|
|
9
|
+
* local package_json_path="$1"
|
|
10
|
+
* local dependency_type_prefix="${2:-dependencies}"
|
|
11
|
+
* local dependencies
|
|
12
|
+
* local npm_flag=""
|
|
13
|
+
* # ... maps prefix to npm flag
|
|
14
|
+
* dependencies=$(get-dependencies "$package_json_path" "$dependency_type_prefix")
|
|
15
|
+
* for dependency in $dependencies; do
|
|
16
|
+
* npm install "$dependency@latest" $npm_flag
|
|
17
|
+
* done
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* This script reads dependencies from a source package.json file and installs
|
|
21
|
+
* them into the current project at their latest versions. This is useful when
|
|
22
|
+
* you want to synchronize dependencies between projects or migrate dependencies
|
|
23
|
+
* from one project to another.
|
|
24
|
+
*
|
|
25
|
+
* Why Node.js is used instead of shell commands:
|
|
26
|
+
* - JSON parsing is native to Node.js (no need for jq)
|
|
27
|
+
* - npm is always available where this script runs (Node.js is required)
|
|
28
|
+
* - Cross-platform path handling using the path module
|
|
29
|
+
* - Better error messages and validation
|
|
30
|
+
*
|
|
5
31
|
* @module scripts/install-dependencies-from
|
|
6
32
|
*/
|
|
7
33
|
|
|
34
|
+
const fs = require('fs');
|
|
35
|
+
const path = require('path');
|
|
36
|
+
const { execSync, spawn } = require('child_process');
|
|
37
|
+
const os = require('../utils/common/os');
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Maps dependency type prefixes to their full names in package.json.
|
|
41
|
+
* This matches the original bash implementation's case statement.
|
|
42
|
+
*/
|
|
43
|
+
const DEPENDENCY_TYPE_MAP = {
|
|
44
|
+
'dependencies': 'dependencies',
|
|
45
|
+
'dev': 'devDependencies',
|
|
46
|
+
'peer': 'peerDependencies',
|
|
47
|
+
'opt': 'optionalDependencies',
|
|
48
|
+
'bundle': 'bundledDependencies'
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Maps dependency type prefixes to npm install flags.
|
|
53
|
+
* These flags tell npm where to save the dependency in package.json.
|
|
54
|
+
*/
|
|
55
|
+
const NPM_FLAG_MAP = {
|
|
56
|
+
'dependencies': '--save',
|
|
57
|
+
'dev': '--save-dev',
|
|
58
|
+
'peer': '--save-peer',
|
|
59
|
+
'opt': '--save-optional',
|
|
60
|
+
'bundle': '--save-bundled'
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Checks if npm is available on the system.
|
|
65
|
+
* Since this script is run with Node.js, npm should typically be available,
|
|
66
|
+
* but we check anyway to provide a helpful error message if it's not.
|
|
67
|
+
*
|
|
68
|
+
* @returns {boolean} True if npm is available, false otherwise
|
|
69
|
+
*/
|
|
70
|
+
function isNpmAvailable() {
|
|
71
|
+
try {
|
|
72
|
+
execSync('npm --version', { stdio: 'ignore' });
|
|
73
|
+
return true;
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Extracts dependency names from a package.json file.
|
|
81
|
+
* This is the same logic as get-dependencies.js but inlined here
|
|
82
|
+
* to avoid inter-script dependencies.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} packageJsonPath - Path to the package.json file
|
|
85
|
+
* @param {string} dependencyType - The full dependency type name (e.g., 'devDependencies')
|
|
86
|
+
* @returns {string[]} Array of dependency package names
|
|
87
|
+
*/
|
|
88
|
+
function extractDependencies(packageJsonPath, dependencyType) {
|
|
89
|
+
// Resolve the path (handle relative and absolute paths)
|
|
90
|
+
const resolvedPath = path.isAbsolute(packageJsonPath)
|
|
91
|
+
? packageJsonPath
|
|
92
|
+
: path.resolve(process.cwd(), packageJsonPath);
|
|
93
|
+
|
|
94
|
+
// Check if the file exists
|
|
95
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
96
|
+
throw new Error(`File not found: ${resolvedPath}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Read and parse the package.json file
|
|
100
|
+
let packageJson;
|
|
101
|
+
try {
|
|
102
|
+
const fileContents = fs.readFileSync(resolvedPath, 'utf8');
|
|
103
|
+
packageJson = JSON.parse(fileContents);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (error.code === 'ENOENT') {
|
|
106
|
+
throw new Error(`File not found: ${resolvedPath}`);
|
|
107
|
+
} else if (error.code === 'EACCES') {
|
|
108
|
+
throw new Error(`Permission denied reading: ${resolvedPath}`);
|
|
109
|
+
} else if (error instanceof SyntaxError) {
|
|
110
|
+
throw new Error(`Invalid JSON in ${resolvedPath}: ${error.message}`);
|
|
111
|
+
} else {
|
|
112
|
+
throw new Error(`Error reading file: ${error.message}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Check if the dependency type exists in the package.json
|
|
117
|
+
const dependencies = packageJson[dependencyType];
|
|
118
|
+
if (!dependencies || typeof dependencies !== 'object') {
|
|
119
|
+
// No dependencies of this type - return empty array
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Return the dependency names (keys of the dependencies object)
|
|
124
|
+
return Object.keys(dependencies);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Installs a single dependency using npm.
|
|
129
|
+
* This function spawns npm as a child process to provide real-time output
|
|
130
|
+
* to the user, matching the original bash behavior.
|
|
131
|
+
*
|
|
132
|
+
* @param {string} packageName - The npm package name to install
|
|
133
|
+
* @param {string} npmFlag - The npm flag (e.g., '--save-dev')
|
|
134
|
+
* @returns {Promise<boolean>} Resolves to true if successful, false if failed
|
|
135
|
+
*/
|
|
136
|
+
function installDependency(packageName, npmFlag) {
|
|
137
|
+
return new Promise((resolve) => {
|
|
138
|
+
console.log(`Installing ${packageName}...`);
|
|
139
|
+
|
|
140
|
+
// Build the npm install command arguments
|
|
141
|
+
// We install @latest to get the latest version, matching the original behavior
|
|
142
|
+
const args = ['install', `${packageName}@latest`, npmFlag];
|
|
143
|
+
|
|
144
|
+
// Spawn npm as a child process
|
|
145
|
+
// Using spawn instead of execSync allows real-time output streaming
|
|
146
|
+
const npmProcess = spawn('npm', args, {
|
|
147
|
+
stdio: 'inherit', // Pipe output directly to parent process
|
|
148
|
+
shell: true // Use shell to handle cross-platform differences
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
npmProcess.on('close', (code) => {
|
|
152
|
+
if (code === 0) {
|
|
153
|
+
resolve(true);
|
|
154
|
+
} else {
|
|
155
|
+
console.error(`Failed to install ${packageName} (exit code: ${code})`);
|
|
156
|
+
resolve(false);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
npmProcess.on('error', (error) => {
|
|
161
|
+
console.error(`Error installing ${packageName}: ${error.message}`);
|
|
162
|
+
resolve(false);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Displays usage information for the script.
|
|
169
|
+
*/
|
|
170
|
+
function showUsage() {
|
|
171
|
+
console.error('Usage: install-dependencies-from /path/to/package.json [dependency_type]');
|
|
172
|
+
console.error('');
|
|
173
|
+
console.error('Reads dependencies from a source package.json and installs them');
|
|
174
|
+
console.error('into the current project at their latest versions.');
|
|
175
|
+
console.error('');
|
|
176
|
+
console.error('Dependency types:');
|
|
177
|
+
console.error(' dependencies - Production dependencies (default)');
|
|
178
|
+
console.error(' dev - Development dependencies');
|
|
179
|
+
console.error(' peer - Peer dependencies');
|
|
180
|
+
console.error(' opt - Optional dependencies');
|
|
181
|
+
console.error(' bundle - Bundled dependencies');
|
|
182
|
+
console.error('');
|
|
183
|
+
console.error('Examples:');
|
|
184
|
+
console.error(' install-dependencies-from ../source/package.json');
|
|
185
|
+
console.error(' install-dependencies-from ../source/package.json dev');
|
|
186
|
+
console.error(' install-dependencies-from /path/to/project/package.json peer');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Pure Node.js implementation that installs dependencies from another package.json.
|
|
191
|
+
*
|
|
192
|
+
* This function:
|
|
193
|
+
* 1. Validates the input arguments
|
|
194
|
+
* 2. Reads the source package.json to extract dependency names
|
|
195
|
+
* 3. Installs each dependency into the current project at its latest version
|
|
196
|
+
*
|
|
197
|
+
* The implementation uses Node.js for JSON parsing and npm for package installation.
|
|
198
|
+
* This works identically on all platforms because:
|
|
199
|
+
* - fs and path modules handle platform differences in file paths
|
|
200
|
+
* - npm is available wherever Node.js is installed
|
|
201
|
+
* - Child process spawning works the same across platforms
|
|
202
|
+
*
|
|
203
|
+
* @param {string[]} args - Command line arguments
|
|
204
|
+
* @param {string} args[0] - Path to source package.json file (required)
|
|
205
|
+
* @param {string} [args[1]] - Dependency type prefix: "dev", "peer", "opt", "bundle", or "dependencies" (default: "dependencies")
|
|
206
|
+
* @returns {Promise<void>}
|
|
207
|
+
*/
|
|
208
|
+
async function do_install_dependencies_from_nodejs(args) {
|
|
209
|
+
const packageJsonPath = args[0];
|
|
210
|
+
const dependencyTypePrefix = args[1] || 'dependencies';
|
|
211
|
+
|
|
212
|
+
// Validate that a path was provided
|
|
213
|
+
if (!packageJsonPath) {
|
|
214
|
+
showUsage();
|
|
215
|
+
process.exit(1);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Validate the dependency type prefix
|
|
219
|
+
const dependencyType = DEPENDENCY_TYPE_MAP[dependencyTypePrefix];
|
|
220
|
+
if (!dependencyType) {
|
|
221
|
+
console.error(`Error: Invalid dependency type prefix: ${dependencyTypePrefix}`);
|
|
222
|
+
console.error('');
|
|
223
|
+
console.error('Valid prefixes are:');
|
|
224
|
+
console.error(' dependencies - Production dependencies');
|
|
225
|
+
console.error(' dev - Development dependencies');
|
|
226
|
+
console.error(' peer - Peer dependencies');
|
|
227
|
+
console.error(' opt - Optional dependencies');
|
|
228
|
+
console.error(' bundle - Bundled dependencies');
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Get the npm flag for this dependency type
|
|
233
|
+
const npmFlag = NPM_FLAG_MAP[dependencyTypePrefix];
|
|
234
|
+
|
|
235
|
+
// Check if npm is available
|
|
236
|
+
if (!isNpmAvailable()) {
|
|
237
|
+
console.error('Error: npm is not installed or not in PATH.');
|
|
238
|
+
console.error('Please install Node.js and npm to use this command.');
|
|
239
|
+
process.exit(1);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Check if we're in a directory with a package.json (npm project)
|
|
243
|
+
const currentPackageJson = path.join(process.cwd(), 'package.json');
|
|
244
|
+
if (!fs.existsSync(currentPackageJson)) {
|
|
245
|
+
console.error('Error: No package.json found in current directory.');
|
|
246
|
+
console.error('Please run this command from an npm project directory.');
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Extract dependencies from the source package.json
|
|
251
|
+
let dependencies;
|
|
252
|
+
try {
|
|
253
|
+
dependencies = extractDependencies(packageJsonPath, dependencyType);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
console.error(`Error: ${error.message}`);
|
|
256
|
+
process.exit(1);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Check if there are any dependencies to install
|
|
260
|
+
if (dependencies.length === 0) {
|
|
261
|
+
console.log('No dependencies to install.');
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Display what we're about to do
|
|
266
|
+
const resolvedPath = path.isAbsolute(packageJsonPath)
|
|
267
|
+
? packageJsonPath
|
|
268
|
+
: path.resolve(process.cwd(), packageJsonPath);
|
|
269
|
+
console.log(`Installing ${dependencyType} from: ${resolvedPath}`);
|
|
270
|
+
console.log(`Found ${dependencies.length} package(s) to install.`);
|
|
271
|
+
console.log('');
|
|
272
|
+
|
|
273
|
+
// Install each dependency
|
|
274
|
+
let successCount = 0;
|
|
275
|
+
let failCount = 0;
|
|
276
|
+
|
|
277
|
+
for (const dependency of dependencies) {
|
|
278
|
+
const success = await installDependency(dependency, npmFlag);
|
|
279
|
+
if (success) {
|
|
280
|
+
successCount++;
|
|
281
|
+
} else {
|
|
282
|
+
failCount++;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Print summary
|
|
287
|
+
console.log('');
|
|
288
|
+
console.log('Installation complete.');
|
|
289
|
+
console.log(` Succeeded: ${successCount}`);
|
|
290
|
+
if (failCount > 0) {
|
|
291
|
+
console.log(` Failed: ${failCount}`);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Exit with error code if any installations failed
|
|
295
|
+
if (failCount > 0) {
|
|
296
|
+
process.exit(1);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Install dependencies from another package.json on macOS.
|
|
302
|
+
*
|
|
303
|
+
* Delegates to the pure Node.js implementation since npm installation
|
|
304
|
+
* works identically on all platforms.
|
|
305
|
+
*
|
|
306
|
+
* @param {string[]} args - Command line arguments
|
|
307
|
+
* @returns {Promise<void>}
|
|
308
|
+
*/
|
|
309
|
+
async function do_install_dependencies_from_macos(args) {
|
|
310
|
+
return do_install_dependencies_from_nodejs(args);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Install dependencies from another package.json on Ubuntu.
|
|
315
|
+
*
|
|
316
|
+
* Delegates to the pure Node.js implementation since npm installation
|
|
317
|
+
* works identically on all platforms.
|
|
318
|
+
*
|
|
319
|
+
* @param {string[]} args - Command line arguments
|
|
320
|
+
* @returns {Promise<void>}
|
|
321
|
+
*/
|
|
322
|
+
async function do_install_dependencies_from_ubuntu(args) {
|
|
323
|
+
return do_install_dependencies_from_nodejs(args);
|
|
324
|
+
}
|
|
325
|
+
|
|
8
326
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
327
|
+
* Install dependencies from another package.json on Raspberry Pi OS.
|
|
328
|
+
*
|
|
329
|
+
* Delegates to the pure Node.js implementation since npm installation
|
|
330
|
+
* works identically on all platforms.
|
|
331
|
+
*
|
|
332
|
+
* @param {string[]} args - Command line arguments
|
|
333
|
+
* @returns {Promise<void>}
|
|
334
|
+
*/
|
|
335
|
+
async function do_install_dependencies_from_raspbian(args) {
|
|
336
|
+
return do_install_dependencies_from_nodejs(args);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Install dependencies from another package.json on Amazon Linux.
|
|
341
|
+
*
|
|
342
|
+
* Delegates to the pure Node.js implementation since npm installation
|
|
343
|
+
* works identically on all platforms.
|
|
344
|
+
*
|
|
345
|
+
* @param {string[]} args - Command line arguments
|
|
346
|
+
* @returns {Promise<void>}
|
|
347
|
+
*/
|
|
348
|
+
async function do_install_dependencies_from_amazon_linux(args) {
|
|
349
|
+
return do_install_dependencies_from_nodejs(args);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Install dependencies from another package.json on Windows Command Prompt.
|
|
354
|
+
*
|
|
355
|
+
* Delegates to the pure Node.js implementation since npm installation
|
|
356
|
+
* works identically on all platforms.
|
|
11
357
|
*
|
|
12
358
|
* @param {string[]} args - Command line arguments
|
|
13
|
-
* @param {string} args.0 - Path to source package.json
|
|
14
|
-
* @param {string} [args.1] - Dependency type: "dev", "peer", "opt", or "dependencies"
|
|
15
359
|
* @returns {Promise<void>}
|
|
16
360
|
*/
|
|
17
|
-
async function
|
|
18
|
-
|
|
361
|
+
async function do_install_dependencies_from_cmd(args) {
|
|
362
|
+
return do_install_dependencies_from_nodejs(args);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Install dependencies from another package.json on Windows PowerShell.
|
|
367
|
+
*
|
|
368
|
+
* Delegates to the pure Node.js implementation since npm installation
|
|
369
|
+
* works identically on all platforms.
|
|
370
|
+
*
|
|
371
|
+
* @param {string[]} args - Command line arguments
|
|
372
|
+
* @returns {Promise<void>}
|
|
373
|
+
*/
|
|
374
|
+
async function do_install_dependencies_from_powershell(args) {
|
|
375
|
+
return do_install_dependencies_from_nodejs(args);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Install dependencies from another package.json in Git Bash on Windows.
|
|
380
|
+
*
|
|
381
|
+
* Delegates to the pure Node.js implementation since npm installation
|
|
382
|
+
* works identically on all platforms.
|
|
383
|
+
*
|
|
384
|
+
* @param {string[]} args - Command line arguments
|
|
385
|
+
* @returns {Promise<void>}
|
|
386
|
+
*/
|
|
387
|
+
async function do_install_dependencies_from_gitbash(args) {
|
|
388
|
+
return do_install_dependencies_from_nodejs(args);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Main entry point - detects environment and executes appropriate implementation.
|
|
393
|
+
*
|
|
394
|
+
* Reads dependencies from a specified package.json file and installs them
|
|
395
|
+
* into the current project at their latest versions. This is useful for:
|
|
396
|
+
*
|
|
397
|
+
* - Migrating dependencies from an old project to a new one
|
|
398
|
+
* - Synchronizing dependencies across multiple projects
|
|
399
|
+
* - Starting a new project with dependencies from a template
|
|
400
|
+
* - Copying only specific dependency types (dev, peer, etc.)
|
|
401
|
+
*
|
|
402
|
+
* The script installs packages with @latest to ensure you get the most recent
|
|
403
|
+
* version, even if the source package.json specifies an older version.
|
|
404
|
+
*
|
|
405
|
+
* Examples:
|
|
406
|
+
* install-dependencies-from ../source/package.json
|
|
407
|
+
* install-dependencies-from ../source/package.json dev
|
|
408
|
+
* install-dependencies-from /path/to/project/package.json peer
|
|
409
|
+
*
|
|
410
|
+
* @param {string[]} args - Command line arguments
|
|
411
|
+
* @returns {Promise<void>}
|
|
412
|
+
*/
|
|
413
|
+
async function do_install_dependencies_from(args) {
|
|
414
|
+
const platform = os.detect();
|
|
415
|
+
|
|
416
|
+
const handlers = {
|
|
417
|
+
'macos': do_install_dependencies_from_macos,
|
|
418
|
+
'ubuntu': do_install_dependencies_from_ubuntu,
|
|
419
|
+
'debian': do_install_dependencies_from_ubuntu,
|
|
420
|
+
'raspbian': do_install_dependencies_from_raspbian,
|
|
421
|
+
'amazon_linux': do_install_dependencies_from_amazon_linux,
|
|
422
|
+
'rhel': do_install_dependencies_from_amazon_linux,
|
|
423
|
+
'fedora': do_install_dependencies_from_ubuntu,
|
|
424
|
+
'linux': do_install_dependencies_from_ubuntu,
|
|
425
|
+
'wsl': do_install_dependencies_from_ubuntu,
|
|
426
|
+
'cmd': do_install_dependencies_from_cmd,
|
|
427
|
+
'windows': do_install_dependencies_from_cmd,
|
|
428
|
+
'powershell': do_install_dependencies_from_powershell,
|
|
429
|
+
'gitbash': do_install_dependencies_from_gitbash
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
const handler = handlers[platform.type];
|
|
433
|
+
if (!handler) {
|
|
434
|
+
console.error(`Platform '${platform.type}' is not supported for this command.`);
|
|
435
|
+
process.exit(1);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
await handler(args);
|
|
19
439
|
}
|
|
20
440
|
|
|
21
|
-
module.exports = {
|
|
441
|
+
module.exports = {
|
|
442
|
+
main: do_install_dependencies_from,
|
|
443
|
+
do_install_dependencies_from,
|
|
444
|
+
do_install_dependencies_from_nodejs,
|
|
445
|
+
do_install_dependencies_from_macos,
|
|
446
|
+
do_install_dependencies_from_ubuntu,
|
|
447
|
+
do_install_dependencies_from_raspbian,
|
|
448
|
+
do_install_dependencies_from_amazon_linux,
|
|
449
|
+
do_install_dependencies_from_cmd,
|
|
450
|
+
do_install_dependencies_from_powershell,
|
|
451
|
+
do_install_dependencies_from_gitbash
|
|
452
|
+
};
|
|
22
453
|
|
|
23
454
|
if (require.main === module) {
|
|
24
|
-
|
|
455
|
+
do_install_dependencies_from(process.argv.slice(2));
|
|
25
456
|
}
|