chore(cli): easier dev on cli (#6336)

* add ts extensions by default

* remove script

* add script to remove ext

* simpler scripts

* add readme

* add revert mode

* nit

* fix

* fix typos

* typo
This commit is contained in:
centdix
2025-08-07 17:55:14 +02:00
committed by GitHub
parent f19cc2aa4c
commit 5f06a607cb
19 changed files with 168 additions and 178 deletions
-64
View File
@@ -1,64 +0,0 @@
#!/usr/bin/env bash
# Set script to exit on any error
set -e
# Default to regular sed
REVERT_MODE=false
# Function to show usage
show_usage() {
echo "Usage: $0 [-r] [-h]"
echo " -r Revert changes (restore from .orig files)"
echo " -h Show this help message"
exit 1
}
# Parse command line arguments
while getopts "rh" opt; do
case ${opt} in
r )
REVERT_MODE=true
;;
h )
show_usage
;;
\? )
echo "Invalid option: -$OPTARG" >&2
show_usage
;;
esac
done
# Function to add .ts extensions to relative imports
add_ts_extensions() {
echo "Adding .ts extensions to imports..."
find windmill-utils-internal/src -name "*.ts" -type f | while read -r file; do
# Create backup of original
cp "$file" "$file.orig"
# Add .ts to relative imports that don't already have extensions
sed -E \
-e 's/(from[[:space:]]+["'"'"'])(\.[^"'"'"']*[^./][^"'"'"']*)(["'"'"'])/\1\2.ts\3/g' \
-e 's/(import[[:space:]]+["'"'"'])(\.[^"'"'"']*[^./][^"'"'"']*)(["'"'"'])/\1\2.ts\3/g' \
"$file.orig" > "$file"
done
echo "✓ Added .ts extensions"
}
# Function to revert to original files
revert_extensions() {
echo "Removing .ts extensions..."
find windmill-utils-internal/src -name "*.orig" -type f | while read -r backup_file; do
original_file="${backup_file%.orig}"
mv "$backup_file" "$original_file"
done
echo "✓ All files reverted"
}
# Main execution
if [ "$REVERT_MODE" = true ]; then
revert_extensions
else
add_ts_extensions
fi
-22
View File
@@ -1,22 +0,0 @@
#!/usr/bin/env bash
# Set script to exit on any error
set -e
# Generate client files
./gen_wm_client-mac.sh
# Generate utils client files
./windmill-utils-internal/gen_wm_client-mac.sh
# Set up trap to ensure cleanup happens on exit, error, or interruption
trap 'echo "Cleaning up..."; ./add-ts-ext.sh -r' EXIT ERR INT TERM
# Add .ts extensions for Deno
./add-ts-ext.sh
# Run dnt
echo "Running dnt..."
deno run -A dnt.ts
echo "Build complete!"
+2 -5
View File
@@ -9,11 +9,8 @@ set -e
# Generate utils client files
./windmill-utils-internal/gen_wm_client.sh
# Set up trap to ensure cleanup happens on exit, error, or interruption
trap 'echo "Cleaning up..."; ./add-ts-ext.sh -r' EXIT ERR INT TERM
# Add .ts extensions for Deno
./add-ts-ext.sh
# Add .ts extensions to windmill-utils-internal
./windmill-utils-internal/remove-ts-ext.sh -r
# Run dnt
echo "Running dnt..."
-28
View File
@@ -1,28 +0,0 @@
#!/usr/bin/env bash
set -eou pipefail
script_dirpath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# only install gnu-sed if not already installed
if ! command -v gsed &> /dev/null; then
brew install gnu-sed
fi
rm -rf "${script_dirpath}/gen"
npx --yes @hey-api/openapi-ts@0.53.1 --input "${script_dirpath}/../backend/windmill-api/openapi.yaml" --output "${script_dirpath}/gen" --useOptions --client legacy/fetch --schemas false
cat <<EOF - gen/core/OpenAPI.ts > temp_file && mv temp_file gen/core/OpenAPI.ts
const getEnv = (key: string) => {
return Deno.env.get(key)
};
const baseUrl = getEnv("BASE_INTERNAL_URL") ?? getEnv("BASE_URL") ?? "http://localhost:8000";
const baseUrlApi = (baseUrl ?? '') + "/api";
EOF
gsed -i 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: true/g' gen/core/OpenAPI.ts
gsed -i 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' gen/core/OpenAPI.ts
gsed -i "s/BASE: '\/api'/BASE: baseUrlApi/g" gen/core/OpenAPI.ts
find gen/ -name "*.ts" -exec gsed -i -E "s/(import.*from[[:space:]]*['\"][^'\"]+)(['\"])/\1.ts\2/g" {} \;
find gen/ -name "*.ts" -exec gsed -i -E "s/(export.*from[[:space:]]*['\"][^'\"]+)(['\"])/\1.ts\2/g" {} \;
+24 -5
View File
@@ -14,10 +14,29 @@ const baseUrl = getEnv("BASE_INTERNAL_URL") ?? getEnv("BASE_URL") ?? "http://loc
const baseUrlApi = (baseUrl ?? '') + "/api";
EOF
sed -i 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: true/g' gen/core/OpenAPI.ts
sed -i 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' gen/core/OpenAPI.ts
sed -i "s/BASE: '\/api'/BASE: baseUrlApi/g" gen/core/OpenAPI.ts
find gen/ -name "*.ts" -exec sed -i -E "s/(import.*from[[:space:]]*['\"][^'\"]+)(['\"])/\1.ts\2/g" {} \;
echo "Applying sed transformations..."
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Detected macOS - using GNU sed (gsed)"
if ! command -v gsed &> /dev/null; then
echo "Error: gsed not found"
echo "Run: brew install gnu-sed"
exit 1
fi
gsed -i 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: true/g' gen/core/OpenAPI.ts
gsed -i 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' gen/core/OpenAPI.ts
gsed -i "s/BASE: '\\/api'/BASE: baseUrlApi/g" gen/core/OpenAPI.ts
find gen/ -name "*.ts" -exec gsed -i -E "s/(import.*from[[:space:]]*['\"][^'\"]+)(['\"])/\1.ts\2/g" {} \;
find gen/ -name "*.ts" -exec gsed -i -E "s/(export.*from[[:space:]]*['\"][^'\"]+)(['\"])/\1.ts\2/g" {} \;
else
echo "Detected Linux - using GNU sed"
sed -i 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: true/g' gen/core/OpenAPI.ts
sed -i 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' gen/core/OpenAPI.ts
sed -i "s/BASE: '\\/api'/BASE: baseUrlApi/g" gen/core/OpenAPI.ts
find gen/ -name "*.ts" -exec sed -i -E "s/(import.*from[[:space:]]*['\"][^'\"]+)(['\"])/\1.ts\2/g" {} \;
find gen/ -name "*.ts" -exec sed -i -E "s/(export.*from[[:space:]]*['\"][^'\"]+)(['\"])/\1.ts\2/g" {} \;
fi
find gen/ -name "*.ts" -exec sed -i -E "s/(export.*from[[:space:]]*['\"][^'\"]+)(['\"])/\1.ts\2/g" {} \;
echo "✓ Client generation completed"
+39
View File
@@ -0,0 +1,39 @@
# Windmill Utils Internal
Internal TypeScript utility package for Windmill development tools and scripts.
## What this package contains
This package provides internal utilities and tools used by the Windmill CLI, the VS CODE extension, and the frontend.
## Development
To work on this package we need to generate the windmill client, and remove .ts extensions to the imports and exports (added by default for deno compatibility, so that the CLI can use this package).
You just need to run this before working on the package:
```bash
npm run dev
```
After you are done with your modifications, add back the .ts extensions:
```bash
./remove-ts-ext.sh -r
```
### Building
To build the package for production:
```bash
npm run build
```
### Publishing
To publish the package:
```bash
./publish.sh
```
@@ -1,25 +0,0 @@
#!/usr/bin/env bash
# only install gnu-sed if not already installed
if ! command -v gsed &> /dev/null; then
brew install gnu-sed
fi
script_dirpath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
output_dirpath="${script_dirpath}/src/gen"
rm -rf "${output_dirpath}"
npx --yes @hey-api/openapi-ts@0.53.1 --input "${script_dirpath}/../../backend/windmill-api/openapi.yaml" --output "${output_dirpath}" --useOptions --client legacy/fetch --schemas false
cat <<EOF - "${output_dirpath}/core/OpenAPI.ts" > temp_file && mv temp_file "${output_dirpath}/core/OpenAPI.ts"
const getEnv = (key: string) => {
return process.env[key]
};
const baseUrl = getEnv("BASE_INTERNAL_URL") ?? getEnv("BASE_URL") ?? "http://localhost:8000";
const baseUrlApi = (baseUrl ?? '') + "/api";
EOF
gsed -i 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: true/g' "${output_dirpath}/core/OpenAPI.ts"
gsed -i 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' "${output_dirpath}/core/OpenAPI.ts"
gsed -i "s/BASE: '\/api'/BASE: baseUrlApi/g" "${output_dirpath}/core/OpenAPI.ts"
+23 -3
View File
@@ -1,5 +1,8 @@
#!/usr/bin/env bash
# Set script to exit on any error
set -e
script_dirpath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
output_dirpath="${script_dirpath}/src/gen"
@@ -15,6 +18,23 @@ const baseUrl = getEnv("BASE_INTERNAL_URL") ?? getEnv("BASE_URL") ?? "http://loc
const baseUrlApi = (baseUrl ?? '') + "/api";
EOF
sed -i 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: true/g' "${output_dirpath}/core/OpenAPI.ts"
sed -i 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' "${output_dirpath}/core/OpenAPI.ts"
sed -i "s/BASE: '\/api'/BASE: baseUrlApi/g" "${output_dirpath}/core/OpenAPI.ts"
echo "Applying sed transformations..."
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Detected macOS - using GNU sed (gsed)"
if ! command -v gsed &> /dev/null; then
echo "Error: gsed not found"
echo "Run: brew install gnu-sed"
exit 1
fi
gsed -i 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: true/g' "${output_dirpath}/core/OpenAPI.ts"
gsed -i 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' "${output_dirpath}/core/OpenAPI.ts"
gsed -i "s/BASE: '\\/api'/BASE: baseUrlApi/g" "${output_dirpath}/core/OpenAPI.ts"
else
echo "Detected Linux - using GNU sed"
sed -i 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: true/g' "${output_dirpath}/core/OpenAPI.ts"
sed -i 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' "${output_dirpath}/core/OpenAPI.ts"
sed -i "s/BASE: '\\/api'/BASE: baseUrlApi/g" "${output_dirpath}/core/OpenAPI.ts"
fi
echo "✓ Client generation completed"
+8 -8
View File
@@ -9,18 +9,18 @@
"version": "1.0.0",
"license": "Apache 2.0",
"devDependencies": {
"@types/node": "^24.1.0",
"@types/node": "^24.2.0",
"typescript": "^5.0.0"
}
},
"node_modules/@types/node": {
"version": "24.1.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.1.0.tgz",
"integrity": "sha512-ut5FthK5moxFKH2T1CUOC6ctR67rQRvvHdFLCD2Ql6KXmMuCrjsSsRI9UsLCm9M18BMwClv4pn327UvB7eeO1w==",
"version": "24.2.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.2.0.tgz",
"integrity": "sha512-3xyG3pMCq3oYCNg7/ZP+E1ooTaGB4cG8JWRsqqOYQdbWNY4zbaV0Ennrd7stjiJEFZCaybcIgpTjJWHRfBSIDw==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~7.8.0"
"undici-types": "~7.10.0"
}
},
"node_modules/typescript": {
@@ -38,9 +38,9 @@
}
},
"node_modules/undici-types": {
"version": "7.8.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.8.0.tgz",
"integrity": "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==",
"version": "7.10.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.10.0.tgz",
"integrity": "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag==",
"dev": true,
"license": "MIT"
}
+4 -4
View File
@@ -5,8 +5,8 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "./gen_wm_client.sh && tsc",
"build-mac": "./gen_wm_client-mac.sh && tsc",
"dev": "./gen_wm_client.sh && ./remove-ts-ext.sh",
"build": "./gen_wm_client.sh && ./remove-ts-ext.sh && tsc",
"prepublishOnly": "npm run build"
},
"keywords": [
@@ -15,10 +15,10 @@
"author": "Ruben Fiszel",
"license": "Apache 2.0",
"devDependencies": {
"@types/node": "^24.1.0",
"@types/node": "^24.2.0",
"typescript": "^5.0.0"
},
"files": [
"dist/**/*"
]
}
}
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# Set script to exit on any error
set -e
script_dirpath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Parse command line arguments
RESTORE_MODE=false
while [[ $# -gt 0 ]]; do
case $1 in
-r)
RESTORE_MODE=true
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [-r]"
echo " -r Restore .ts extensions to imports/exports"
exit 1
;;
esac
done
if [[ "$RESTORE_MODE" == true ]]; then
echo "Adding .ts extensions to imports..."
# Only add .ts if the path doesn't already end with .ts or /
REGEX='/\.ts["'\'']/! s/(from|import)[[:space:]]+["'\'']([^"'\'']*[^/])(["'\''])/\1 "\2.ts\3/g'
SUCCESS_MSG="✓ All .ts extensions added to import/export statements"
else
echo "Removing .ts extensions from imports..."
REGEX='s/(from|import)[[:space:]]+["'\'']([^"'\'']*?)\.ts(["'\''])/\1 "\2\3/g'
SUCCESS_MSG="✓ All .ts extensions removed from import/export statements"
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Detected macOS - using GNU sed (gsed)"
if ! command -v gsed &> /dev/null; then
echo "Error: gsed not found"
echo "Run: brew install gnu-sed"
exit 1
fi
else
echo "Detected Linux - using GNU sed"
fi
find "$script_dirpath"/src -name "*.ts" -type f | while read -r file; do
if [[ "$OSTYPE" == "darwin"* ]]; then
gsed -E -i "$REGEX" "$file"
else
sed -E -i "$REGEX" "$file"
fi
done
echo "$SUCCESS_MSG"
@@ -1 +1 @@
export * from "./config";
export * from "./config.ts";
+5 -5
View File
@@ -8,8 +8,8 @@
* - Cross-platform path constants
*/
export * from "./inline-scripts";
export * from "./path-utils";
export * from "./parse";
export * from "./config";
export { SEP, DELIMITER } from "./constants";
export * from "./inline-scripts.ts";
export * from "./path-utils.ts";
export * from "./parse.ts";
export * from "./config.ts";
export { SEP, DELIMITER } from "./constants.ts";
@@ -1,5 +1,5 @@
import { newPathAssigner } from "../path-utils/path-assigner";
import { FlowModule } from "../gen/types.gen";
import { newPathAssigner } from "../path-utils/path-assigner.ts";
import { FlowModule } from "../gen/types.gen.ts";
/**
* Represents an inline script extracted from a flow module
@@ -1,2 +1,2 @@
export * from "./replacer";
export * from "./extractor";
export * from "./replacer.ts";
export * from "./extractor.ts";
@@ -1,4 +1,4 @@
import { FlowModule } from "../gen/types.gen";
import { FlowModule } from "../gen/types.gen.ts";
/**
* Replaces inline script references with actual file content from the filesystem.
@@ -1 +1 @@
export * from "./parse-schema";
export * from "./parse-schema.ts";
@@ -1 +1 @@
export * from "./path-assigner";
export * from "./path-assigner.ts";
@@ -1,4 +1,4 @@
import { RawScript } from "../gen/types.gen";
import { RawScript } from "../gen/types.gen.ts";
const INLINE_SCRIPT_PREFIX = "inline_script";