@trendify/cli 0.1.33 → 0.1.35
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/dist/launcher.entry.d.ts +3 -0
- package/dist/launcher.entry.d.ts.map +1 -0
- package/dist/launcher.entry.js +85 -0
- package/package.json +3 -3
- package/scripts/update-runner.ps1 +109 -0
- package/scripts/update-runner.sh +5 -3
- package/bin/trendify.sh +0 -46
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launcher.entry.d.ts","sourceRoot":"","sources":["../src/launcher.entry.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
import { CLI_UPDATE_REQUEST_EXIT_CODE } from './shared/constants/process-exit-code.constant.js';
|
|
7
|
+
import { getCliUpdateStateFilePath } from './shared/services/update-request.service.js';
|
|
8
|
+
const APP_ENTRY_FILE_PATH = fileURLToPath(new URL('./cli.entry.js', import.meta.url));
|
|
9
|
+
const PACKAGE_ROOT_PATH = fileURLToPath(new URL('..', import.meta.url));
|
|
10
|
+
const UNIX_UPDATE_RUNNER_PATH = fileURLToPath(new URL('../scripts/update-runner.sh', import.meta.url));
|
|
11
|
+
const WINDOWS_UPDATE_RUNNER_PATH = fileURLToPath(new URL('../scripts/update-runner.ps1', import.meta.url));
|
|
12
|
+
function runNodeScript(scriptFilePath, args) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const child = spawn(process.execPath, [scriptFilePath, ...args], {
|
|
15
|
+
env: process.env,
|
|
16
|
+
stdio: 'inherit',
|
|
17
|
+
});
|
|
18
|
+
child.once('error', (error) => {
|
|
19
|
+
reject(error);
|
|
20
|
+
});
|
|
21
|
+
child.once('exit', (code, signal) => {
|
|
22
|
+
if (signal) {
|
|
23
|
+
resolve(1);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
resolve(code ?? 0);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function runUpdateRunner(args) {
|
|
31
|
+
const stateFilePath = getCliUpdateStateFilePath();
|
|
32
|
+
const runnerArgs = [stateFilePath, PACKAGE_ROOT_PATH, process.execPath, ...args];
|
|
33
|
+
if (process.platform === 'win32') {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const child = spawn('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', WINDOWS_UPDATE_RUNNER_PATH, ...runnerArgs], {
|
|
36
|
+
env: process.env,
|
|
37
|
+
stdio: 'inherit',
|
|
38
|
+
windowsHide: false,
|
|
39
|
+
});
|
|
40
|
+
child.once('error', (error) => {
|
|
41
|
+
reject(error);
|
|
42
|
+
});
|
|
43
|
+
child.once('exit', (code, signal) => {
|
|
44
|
+
if (signal) {
|
|
45
|
+
resolve(1);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
resolve(code ?? 0);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const child = spawn('/bin/sh', [UNIX_UPDATE_RUNNER_PATH, ...runnerArgs], {
|
|
54
|
+
env: process.env,
|
|
55
|
+
stdio: 'inherit',
|
|
56
|
+
});
|
|
57
|
+
child.once('error', (error) => {
|
|
58
|
+
reject(error);
|
|
59
|
+
});
|
|
60
|
+
child.once('exit', (code, signal) => {
|
|
61
|
+
if (signal) {
|
|
62
|
+
resolve(1);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
resolve(code ?? 0);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function main() {
|
|
70
|
+
const args = process.argv.slice(2);
|
|
71
|
+
const appExitCode = await runNodeScript(APP_ENTRY_FILE_PATH, args);
|
|
72
|
+
if (appExitCode !== CLI_UPDATE_REQUEST_EXIT_CODE || !existsSync(getCliUpdateStateFilePath())) {
|
|
73
|
+
process.exit(appExitCode);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const updaterExitCode = await runUpdateRunner(args);
|
|
77
|
+
process.exit(updaterExitCode);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
const message = error instanceof Error && error.message ? error.message : 'Falha ao iniciar o atualizador externo.';
|
|
81
|
+
process.stderr.write(`${message}\n`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
void main();
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trendify/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"description": "CLI do Trendify para descoberta de temas e fluxos de conta.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cli.entry.js",
|
|
7
7
|
"types": "dist/cli.entry.d.ts",
|
|
8
8
|
"bin": {
|
|
9
|
-
"trendify": "
|
|
9
|
+
"trendify": "dist/launcher.entry.js"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
|
-
"bin/trendify.sh",
|
|
14
13
|
"scripts/update-runner.sh",
|
|
14
|
+
"scripts/update-runner.ps1",
|
|
15
15
|
".env",
|
|
16
16
|
"README.md",
|
|
17
17
|
".env.example"
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
$ErrorActionPreference = 'Stop'
|
|
2
|
+
|
|
3
|
+
$stateFilePath = $args[0]
|
|
4
|
+
$packageRootPath = $args[1]
|
|
5
|
+
$nodeCommand = $args[2]
|
|
6
|
+
$cliArgs = @()
|
|
7
|
+
|
|
8
|
+
if ($args.Length -gt 3) {
|
|
9
|
+
$cliArgs = $args[3..($args.Length - 1)]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function Reset-Terminal {
|
|
13
|
+
if ($Host.Name -like '*ConsoleHost*') {
|
|
14
|
+
try {
|
|
15
|
+
Clear-Host
|
|
16
|
+
} catch {
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function Read-StateFile {
|
|
22
|
+
param([string]$Path)
|
|
23
|
+
|
|
24
|
+
$values = @{}
|
|
25
|
+
|
|
26
|
+
foreach ($line in Get-Content -Path $Path) {
|
|
27
|
+
if ([string]::IsNullOrWhiteSpace($line)) {
|
|
28
|
+
continue
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
$separatorIndex = $line.IndexOf('=')
|
|
32
|
+
|
|
33
|
+
if ($separatorIndex -lt 1) {
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
$key = $line.Substring(0, $separatorIndex)
|
|
38
|
+
$value = $line.Substring($separatorIndex + 1)
|
|
39
|
+
$values[$key] = $value
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return $values
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function Write-StateFile {
|
|
46
|
+
param(
|
|
47
|
+
[string]$Path,
|
|
48
|
+
[hashtable]$Values,
|
|
49
|
+
[string]$Status
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
$tempFilePath = "$Path.tmp.$PID"
|
|
53
|
+
@(
|
|
54
|
+
"STATUS=$Status"
|
|
55
|
+
"PACKAGE_NAME=$($Values['PACKAGE_NAME'])"
|
|
56
|
+
"CURRENT_VERSION=$($Values['CURRENT_VERSION'])"
|
|
57
|
+
"TARGET_VERSION=$($Values['TARGET_VERSION'])"
|
|
58
|
+
"REQUESTED_AT=$($Values['REQUESTED_AT'])"
|
|
59
|
+
) | Set-Content -Path $tempFilePath -Encoding utf8
|
|
60
|
+
|
|
61
|
+
Move-Item -Path $tempFilePath -Destination $Path -Force
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (-not (Test-Path -LiteralPath $stateFilePath)) {
|
|
65
|
+
exit 0
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
$state = Read-StateFile -Path $stateFilePath
|
|
69
|
+
|
|
70
|
+
if ($state['STATUS'] -ne 'pending') {
|
|
71
|
+
exit 0
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
$packageName = if ($state['PACKAGE_NAME']) { $state['PACKAGE_NAME'] } else { '@trendify/cli' }
|
|
75
|
+
$currentVersion = if ($state['CURRENT_VERSION']) { $state['CURRENT_VERSION'] } else { 'desconhecida' }
|
|
76
|
+
$targetVersion = if ($state['TARGET_VERSION']) { $state['TARGET_VERSION'] } else { 'latest' }
|
|
77
|
+
$npmCommand = if (Get-Command 'npm.cmd' -ErrorAction SilentlyContinue) { 'npm.cmd' } else { 'npm' }
|
|
78
|
+
|
|
79
|
+
Reset-Terminal
|
|
80
|
+
Write-Host 'Trendify CLI'
|
|
81
|
+
Write-Host '[1/4] Atualizador externo iniciado.'
|
|
82
|
+
Write-Host "[2/4] Atualizando $packageName de v$currentVersion para v$targetVersion..."
|
|
83
|
+
Write-Host ''
|
|
84
|
+
|
|
85
|
+
Write-StateFile -Path $stateFilePath -Values $state -Status 'updating'
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
& $npmCommand install --global "$packageName@$targetVersion"
|
|
89
|
+
if ($LASTEXITCODE -ne 0) {
|
|
90
|
+
throw "npm install finalizou com codigo $LASTEXITCODE."
|
|
91
|
+
}
|
|
92
|
+
} catch {
|
|
93
|
+
Write-StateFile -Path $stateFilePath -Values $state -Status 'failed'
|
|
94
|
+
Write-Error 'Falha ao atualizar automaticamente o CLI.'
|
|
95
|
+
Write-Host "Execute manualmente: npm install -g $packageName@$targetVersion"
|
|
96
|
+
exit 1
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
Remove-Item -LiteralPath $stateFilePath -Force -ErrorAction SilentlyContinue
|
|
100
|
+
|
|
101
|
+
Write-Host ''
|
|
102
|
+
Write-Host '[3/4] Atualizacao concluida.'
|
|
103
|
+
Write-Host '[4/4] Reiniciando o CLI em um processo limpo...'
|
|
104
|
+
Write-Host ''
|
|
105
|
+
Start-Sleep -Milliseconds 750
|
|
106
|
+
Reset-Terminal
|
|
107
|
+
|
|
108
|
+
& $nodeCommand (Join-Path $packageRootPath 'dist/launcher.entry.js') @cliArgs
|
|
109
|
+
exit $LASTEXITCODE
|
package/scripts/update-runner.sh
CHANGED
|
@@ -3,7 +3,9 @@ set -eu
|
|
|
3
3
|
|
|
4
4
|
SELF_PATH=$0
|
|
5
5
|
STATE_FILE=${1:?state file path is required}
|
|
6
|
-
|
|
6
|
+
PACKAGE_ROOT_PATH=${2:?package root path is required}
|
|
7
|
+
NODE_COMMAND=${3:?node command path is required}
|
|
8
|
+
shift 3
|
|
7
9
|
|
|
8
10
|
cleanup() {
|
|
9
11
|
if [ -n "${TRENDIFY_TEMP_UPDATER_PATH:-}" ]; then
|
|
@@ -39,7 +41,7 @@ if [ "${TRENDIFY_UPDATER_STAGE:-launcher}" != "temp" ]; then
|
|
|
39
41
|
TEMP_UPDATER_PATH=$(mktemp "${TMPDIR:-/tmp}/trendify-cli-updater.XXXXXX.sh")
|
|
40
42
|
cp "$SELF_PATH" "$TEMP_UPDATER_PATH"
|
|
41
43
|
chmod 700 "$TEMP_UPDATER_PATH"
|
|
42
|
-
exec env TRENDIFY_UPDATER_STAGE=temp TRENDIFY_TEMP_UPDATER_PATH="$TEMP_UPDATER_PATH"
|
|
44
|
+
exec env TRENDIFY_UPDATER_STAGE=temp TRENDIFY_TEMP_UPDATER_PATH="$TEMP_UPDATER_PATH" /bin/sh "$TEMP_UPDATER_PATH" "$STATE_FILE" "$PACKAGE_ROOT_PATH" "$NODE_COMMAND" "$@"
|
|
43
45
|
fi
|
|
44
46
|
|
|
45
47
|
trap cleanup EXIT INT TERM
|
|
@@ -81,4 +83,4 @@ printf '[4/4] Reiniciando o CLI em um processo limpo...\n\n'
|
|
|
81
83
|
sleep 0.75
|
|
82
84
|
reset_terminal
|
|
83
85
|
|
|
84
|
-
exec "$
|
|
86
|
+
exec "$NODE_COMMAND" "$PACKAGE_ROOT_PATH/dist/launcher.entry.js" "$@"
|
package/bin/trendify.sh
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
set -eu
|
|
3
|
-
|
|
4
|
-
resolve_script_path() {
|
|
5
|
-
TARGET_PATH=$1
|
|
6
|
-
|
|
7
|
-
while [ -L "$TARGET_PATH" ]; do
|
|
8
|
-
LINK_TARGET=$(readlink "$TARGET_PATH")
|
|
9
|
-
|
|
10
|
-
case "$LINK_TARGET" in
|
|
11
|
-
/*)
|
|
12
|
-
TARGET_PATH=$LINK_TARGET
|
|
13
|
-
;;
|
|
14
|
-
*)
|
|
15
|
-
TARGET_DIR=$(CDPATH= cd -- "$(dirname -- "$TARGET_PATH")" && pwd)
|
|
16
|
-
TARGET_PATH="$TARGET_DIR/$LINK_TARGET"
|
|
17
|
-
;;
|
|
18
|
-
esac
|
|
19
|
-
done
|
|
20
|
-
|
|
21
|
-
TARGET_DIR=$(CDPATH= cd -- "$(dirname -- "$TARGET_PATH")" && pwd -P)
|
|
22
|
-
printf '%s/%s\n' "$TARGET_DIR" "$(basename -- "$TARGET_PATH")"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
SCRIPT_PATH=$(resolve_script_path "$0")
|
|
26
|
-
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPT_PATH")" && pwd -P)
|
|
27
|
-
PACKAGE_ROOT=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)
|
|
28
|
-
UPDATE_EXIT_CODE=42
|
|
29
|
-
STATE_FILE_DEFAULT="${HOME}/.trendify/runtime/update-state.env"
|
|
30
|
-
|
|
31
|
-
mkdir -p "$(dirname -- "$STATE_FILE_DEFAULT")"
|
|
32
|
-
|
|
33
|
-
export TRENDIFY_UPDATE_STATE_FILE="${TRENDIFY_UPDATE_STATE_FILE:-$STATE_FILE_DEFAULT}"
|
|
34
|
-
export TRENDIFY_CLI_COMMAND="${TRENDIFY_CLI_COMMAND:-$(command -v trendify 2>/dev/null || printf 'trendify')}"
|
|
35
|
-
|
|
36
|
-
if node "$PACKAGE_ROOT/dist/cli.entry.js" "$@"; then
|
|
37
|
-
APP_EXIT_CODE=0
|
|
38
|
-
else
|
|
39
|
-
APP_EXIT_CODE=$?
|
|
40
|
-
fi
|
|
41
|
-
|
|
42
|
-
if [ "$APP_EXIT_CODE" -eq "$UPDATE_EXIT_CODE" ] && [ -f "$TRENDIFY_UPDATE_STATE_FILE" ]; then
|
|
43
|
-
exec /bin/sh "$PACKAGE_ROOT/scripts/update-runner.sh" "$TRENDIFY_UPDATE_STATE_FILE" "$@"
|
|
44
|
-
fi
|
|
45
|
-
|
|
46
|
-
exit "$APP_EXIT_CODE"
|