@dotcms/dotcli 24.2.26-rc1 → 24.2.26-rc3

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 CHANGED
@@ -1,7 +1,19 @@
1
1
  # dotCMS CLI
2
- The dotCMS CLI is a command-line tool that you can use to populate and modify your dotCMS instances from a command shell.
2
+ The **dotCMS CLI**, sometimes shortened to **dotCLI**, is a standalone tool for interacting with a dotCMS instance through a command shell, allowing a wide array of automated operations and behaviors.
3
+
4
+ ## Getting Started
5
+
6
+ ### Installation
7
+
8
+ ### NPM
9
+
10
+ The simplest and most recommended way to get the dotCMS CLI is from its npm package:
11
+
12
+ ```shell script
13
+ npm install -g @dotcms/cli
14
+ ```
15
+ ### Manual JAR Download
3
16
 
4
- ## Quick start
5
17
  1. Download the CLI: The dotCMS CLI is delivered as an uber jar that can be downloaded from [here](https://repo.dotcms.com/artifactory/libs-snapshot-local/com/dotcms/dotcms-cli/).
6
18
  Once downloaded, you just need to run it with:
7
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/dotcli",
3
- "version": "24.02.26-rc1",
3
+ "version": "24.02.26-rc3",
4
4
  "scripts": {
5
5
  "postinstall": "node src/postinstall.js install",
6
6
  "postuninstall": "node src/postinstall.js uninstall && npm prune"
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ // Dependencies
3
4
  const path = require('path');
4
5
  const fs = require('fs').promises;
5
6
  const os = require('os');
6
7
 
8
+ // Architecture and platform mappings
7
9
  const ARCHITECTURE_MAPPING = {
8
10
  "x64": "x86_64",
9
11
  "arm64": "aarch_64"
@@ -14,26 +16,35 @@ const PLATFORM_MAPPING = {
14
16
  "linux": "linux"
15
17
  };
16
18
 
19
+ const EXTENSION_MAP = {
20
+ "win32": ".exe",
21
+ "default": ""
22
+ };
23
+
24
+ // Utility functions
17
25
  function getGlobalBinPath() {
18
26
  const npmGlobalPrefix = process.env.PREFIX || process.env.npm_config_prefix || process.env.HOME;
19
27
  return path.join(npmGlobalPrefix, 'bin');
20
28
  }
21
29
 
22
30
  function validatePackageConfig(packageJson) {
31
+ // Validation of package.json configuration
23
32
  if (!packageJson.version || !packageJson.packageName || !packageJson.alias || !packageJson.binaries || typeof packageJson.binaries !== "object") {
24
33
  throw new Error("Invalid package.json. 'version', 'packageName', 'alias' and 'binaries' must be specified.");
25
34
  }
26
35
  }
27
36
 
37
+ // Read and parse package.json
28
38
  async function parsePackageJson() {
29
-
30
39
  console.log("Installing CLI");
40
+
31
41
  const platform = os.platform();
32
42
  const architecture = os.arch();
33
43
 
34
44
  console.log("Platform: " + platform);
35
45
  console.log("Architecture: " + architecture);
36
46
 
47
+ // Check installation support for platform and architecture
37
48
  if (!(os.arch() in ARCHITECTURE_MAPPING) || !(os.platform() in PLATFORM_MAPPING)) {
38
49
  throw new Error(`Installation is not supported for this ${platform}/${architecture} combination.`);
39
50
  }
@@ -48,7 +59,7 @@ async function parsePackageJson() {
48
59
  const packageName = packageJson.packageName;
49
60
  const alias = packageJson.alias;
50
61
  const binaries = packageJson.binaries;
51
- const extension = platform === "win32" ? ".exe" : "";
62
+ const extension = EXTENSION_MAP[platform] || EXTENSION_MAP.default;
52
63
  const binaryKey = `${packageName}-${platform}-${architecture}`;
53
64
  const binaryPath = binaries[binaryKey];
54
65
 
@@ -69,76 +80,86 @@ async function parsePackageJson() {
69
80
  }
70
81
  }
71
82
 
83
+ // Create symlink for the binary
84
+ async function createSymlink(globalBinPath, config) {
85
+ try {
86
+ console.info(`Creating symlink for the relevant binary for your platform ${os.platform()}-${os.arch()}`);
72
87
 
73
- async function createSymlink(binarySource, binaryDestination) {
74
- const globalBinPath = getGlobalBinPath();
75
- const symlinkPath = path.join(globalBinPath, binaryDestination);
88
+ const currentDir = __dirname;
89
+ const targetDir = path.join(currentDir, '..');
90
+ const binarySource = path.join(targetDir, config.binaryPath);
91
+ const binaryDestination = config.alias;
92
+ const fullSymlinkPath = path.join(globalBinPath, binaryDestination);
76
93
 
77
- try {
78
- try {
79
- await fs.access(symlinkPath, fs.constants.F_OK);
80
- // If the symlink exists, remove it.
81
- await fs.unlink(symlinkPath);
82
- console.log(`Existing symlink ${symlinkPath} found and removed.`);
83
- } catch (error) {
84
- // The symlink does not exist, continue.
85
- }
94
+ await fs.symlink(binarySource, fullSymlinkPath);
86
95
 
87
- if (os.platform() === "win32") {
88
- // Create a junction for the binary for Windows.
89
- // await fs.symlink(binarySource, symlinkPath, "junction");
90
- } else {
91
- // Create a symlink for the binary for macOS and Linux.
92
- await fs.symlink(binarySource, symlinkPath);
93
- }
94
- console.info(`Created symlink ${symlinkPath} pointing to ${binarySource}`);
96
+ console.info(`Created symlink ${fullSymlinkPath} pointing to ${binarySource}`);
95
97
  } catch (error) {
96
98
  console.error("Error while creating symlink:", error);
97
99
  throw new Error("Failed to create symlink.");
98
100
  }
99
101
  }
100
102
 
101
- async function installCli() {
102
- const config = await parsePackageJson();
103
+ // Remove symlink if exists
104
+ async function removeSymlinkIfExists(globalBinPath, config) {
105
+ try {
106
+ console.info("Global bin path location:", globalBinPath);
103
107
 
104
- console.log({
105
- config
106
- });
108
+ const files = await fs.readdir(globalBinPath);
109
+ const symlinkFileName = config.alias + config.extension;
110
+ const symlinkPath = files.find(file => file === symlinkFileName);
107
111
 
108
- console.info(`Creating symlink for the relevant binary for your platform ${os.platform()}-${os.arch()}`);
112
+ if (!symlinkPath) {
113
+ console.warn(`Symlink '${symlinkFileName}' not found in the global bin directory.`);
114
+ return;
115
+ }
109
116
 
110
- const currentDir = __dirname;
111
- const targetDir = path.join(currentDir, '..');
112
- const binarySource = path.join(targetDir, config.binaryPath);
113
- const binaryDestination = config.alias;
117
+ const fullSymlinkPath = path.join(globalBinPath, symlinkPath);
118
+ await fs.unlink(fullSymlinkPath);
119
+ console.info(`Removed symlink: ${fullSymlinkPath}`);
120
+ } catch (error) {
121
+ console.warn("Error while removing symlink:", error);
122
+ }
123
+ }
114
124
 
115
- console.info("Installing cli:", binarySource, binaryDestination);
125
+ // Install CLI
126
+ async function installCli() {
127
+ const config = await parsePackageJson();
128
+ const globalBinPath = getGlobalBinPath();
116
129
 
117
- await createSymlink(binarySource, binaryDestination + config.extension);
130
+ try{
131
+ await removeSymlinkIfExists(globalBinPath, config);
132
+ await createSymlink(globalBinPath, config);
133
+ } catch (ex) {
134
+ console.error("Error while installing:", ex);
135
+ throw new Error(`Failed to install ${config.alias}.`);
136
+ }
137
+
138
+ console.info(`${config.alias} installed successfully.`);
118
139
  }
119
140
 
141
+ // Uninstall CLI
120
142
  async function uninstallCli() {
121
143
  const config = await parsePackageJson();
144
+ const globalBinPath = getGlobalBinPath();
122
145
 
123
146
  try {
124
- const globalBinPath = getGlobalBinPath();
125
- const symlinkPath = path.join(globalBinPath, config.alias + config.extension);
126
-
127
- console.info("Removing symlink:", symlinkPath);
128
-
129
- await fs.unlink(symlinkPath);
147
+ await removeSymlinkIfExists(globalBinPath, config);
130
148
  } catch (ex) {
131
149
  console.error("Error while uninstalling:", ex);
150
+ throw new Error(`Failed to uninstall ${config.alias}.`);
132
151
  }
133
152
 
134
- console.info("Uninstalled cli successfully");
153
+ console.info(`${config.alias} uninstalled successfully.`);
135
154
  }
136
155
 
156
+ // Available actions
137
157
  const actions = {
138
158
  "install": installCli,
139
159
  "uninstall": uninstallCli
140
160
  };
141
161
 
162
+ // Execute action based on provided command
142
163
  const [cmd] = process.argv.slice(2);
143
164
  if (cmd && actions[cmd]) {
144
165
  actions[cmd]().then(
@@ -151,4 +172,4 @@ if (cmd && actions[cmd]) {
151
172
  } else {
152
173
  console.log("Invalid command. `install` and `uninstall` are the only supported commands");
153
174
  process.exit(1);
154
- }
175
+ }