From 048cb820ad63f772949457d25bcf873a575d4fa0 Mon Sep 17 00:00:00 2001 From: Thorsten Hans Date: Wed, 15 Jan 2025 21:49:18 +0100 Subject: [PATCH] feat: add support for yarn Signed-off-by: Thorsten Hans --- templates/http-js/content/package.json | 42 ++++++++++--------- templates/http-js/content/spin.toml | 7 +++- .../http-js/metadata/snippets/component.txt | 2 +- templates/http-js/metadata/spin-template.toml | 1 + templates/http-ts/content/package.json | 6 ++- templates/http-ts/content/spin.toml | 5 ++- .../http-ts/metadata/snippets/component.txt | 2 +- templates/http-ts/metadata/spin-template.toml | 1 + templates/redis-js/content/package.json | 4 ++ templates/redis-js/content/spin.toml | 3 +- .../redis-js/metadata/snippets/component.txt | 2 +- .../redis-js/metadata/spin-template.toml | 1 + templates/redis-ts/content/package.json | 4 ++ templates/redis-ts/content/spin.toml | 3 +- .../redis-ts/metadata/snippets/component.txt | 2 +- .../redis-ts/metadata/spin-template.toml | 1 + 16 files changed, 56 insertions(+), 30 deletions(-) diff --git a/templates/http-js/content/package.json b/templates/http-js/content/package.json index 0b3c8f2f..f85f4c96 100644 --- a/templates/http-js/content/package.json +++ b/templates/http-js/content/package.json @@ -1,22 +1,26 @@ { - "name": "{{project-name | kebab_case}}", - "version": "1.0.0", - "description": "{{project-description}}", - "main": "index.js", - "scripts": { + "name": "{{project-name | kebab_case}}", + "version": "1.0.0", + "description": "{{project-description}}", + "main": "index.js", + "scripts": { + {%- if package-manager == "npm" -%} "build": "npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}", + {%- else -%} + "build": "yarn exec webpack -- --mode=production && yarn exec mkdirp -- target && yarn exec j2w -- -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}", + {%- endif -%} "test": "echo \"Error: no test specified\" && exit 1", - "postinstall": "knitwit" - }, - "keywords": [], - "author": "", - "license": "ISC", - "devDependencies": { - "mkdirp": "^3.0.1", - "webpack": "^5.74.0", - "webpack-cli": "^4.10.0" - }, - "dependencies": { - "@fermyon/spin-sdk": "^2.3.0" - } -} \ No newline at end of file + "postinstall": "knitwit" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "mkdirp": "^3.0.1", + "webpack": "^5.74.0", + "webpack-cli": "^4.10.0" + }, + "dependencies": { + "@fermyon/spin-sdk": "^2.3.0" + } +} diff --git a/templates/http-js/content/spin.toml b/templates/http-js/content/spin.toml index e387fe73..7c04b7ee 100644 --- a/templates/http-js/content/spin.toml +++ b/templates/http-js/content/spin.toml @@ -13,6 +13,9 @@ component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] source = "target/{{project-name | kebab_case}}.wasm" exclude_files = ["**/node_modules"] +allowed_outbound_hosts = [] + [component.{{project-name | kebab_case}}.build] -command = "npm run build" -watch = ["src/**/*.ts", "package.json"] \ No newline at end of file +command = "{{ package-manager}} run build" +watch = ["src/**/*.ts", "package.json"] + diff --git a/templates/http-js/metadata/snippets/component.txt b/templates/http-js/metadata/snippets/component.txt index 6130fc89..daf9bcd3 100644 --- a/templates/http-js/metadata/snippets/component.txt +++ b/templates/http-js/metadata/snippets/component.txt @@ -7,5 +7,5 @@ source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm" allowed_outbound_hosts = [] [component.{{project-name | kebab_case}}.build] -command = "npm run build" +command = "{{ package-manager }} run build" workdir = "{{ output-path }}" diff --git a/templates/http-js/metadata/spin-template.toml b/templates/http-js/metadata/spin-template.toml index 228c88eb..0837c932 100644 --- a/templates/http-js/metadata/spin-template.toml +++ b/templates/http-js/metadata/spin-template.toml @@ -11,3 +11,4 @@ component = "component.txt" project-description = { type = "string", prompt = "Description", default = "" } http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" } enable-aot = { type = "string", prompt = "Enable AoT Compilation [y/N]", default = "N", pattern = "^[yYnN]$" } +package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" } diff --git a/templates/http-ts/content/package.json b/templates/http-ts/content/package.json index 05cd0142..a8949781 100644 --- a/templates/http-ts/content/package.json +++ b/templates/http-ts/content/package.json @@ -4,7 +4,11 @@ "description": "{{project-description}}", "main": "index.js", "scripts": { - "build": "npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/{{ project-name | kebab_case }}.wasm {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}", + {%- if package-manager == "npm" -%} + "build": "npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}", + {%- else -%} + "build": "yarn exec webpack -- --mode=production && yarn exec mkdirp -- target && yarn exec j2w -- -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}", + {%- endif -%} "test": "echo \"Error: no test specified\" && exit 1", "postinstall": "knitwit" }, diff --git a/templates/http-ts/content/spin.toml b/templates/http-ts/content/spin.toml index e387fe73..47bd03dc 100644 --- a/templates/http-ts/content/spin.toml +++ b/templates/http-ts/content/spin.toml @@ -13,6 +13,7 @@ component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] source = "target/{{project-name | kebab_case}}.wasm" exclude_files = ["**/node_modules"] + [component.{{project-name | kebab_case}}.build] -command = "npm run build" -watch = ["src/**/*.ts", "package.json"] \ No newline at end of file +command = "{{ package-manager }} run build" +watch = ["src/**/*.ts", "package.json"] diff --git a/templates/http-ts/metadata/snippets/component.txt b/templates/http-ts/metadata/snippets/component.txt index 73f0fda8..dcad5ed0 100644 --- a/templates/http-ts/metadata/snippets/component.txt +++ b/templates/http-ts/metadata/snippets/component.txt @@ -7,5 +7,5 @@ source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm" allowed_outbound_hosts = [] [component.{{project-name | kebab_case}}.build] -command = "npm run build" +command = "{{ package-manager }} run build" workdir = "{{ output-path }}" \ No newline at end of file diff --git a/templates/http-ts/metadata/spin-template.toml b/templates/http-ts/metadata/spin-template.toml index 7eb9d34a..c759dc60 100644 --- a/templates/http-ts/metadata/spin-template.toml +++ b/templates/http-ts/metadata/spin-template.toml @@ -11,3 +11,4 @@ component = "component.txt" project-description = { type = "string", prompt = "Description", default = "" } http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" } enable-aot = { type = "string", prompt = "Enable AoT Compilation [y/N]", default = "N", pattern = "^[yYnN]$" } +package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" } diff --git a/templates/redis-js/content/package.json b/templates/redis-js/content/package.json index 0b3c8f2f..ded957cd 100644 --- a/templates/redis-js/content/package.json +++ b/templates/redis-js/content/package.json @@ -4,7 +4,11 @@ "description": "{{project-description}}", "main": "index.js", "scripts": { + {%- if package-manager == "npm" -%} "build": "npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}", + {%- else -%} + "build": "yarn exec webpack -- --mode=production && yarn exec mkdirp -- target && yarn exec j2w -- -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}", + {%- endif -%} "test": "echo \"Error: no test specified\" && exit 1", "postinstall": "knitwit" }, diff --git a/templates/redis-js/content/spin.toml b/templates/redis-js/content/spin.toml index 723b5507..65102e75 100644 --- a/templates/redis-js/content/spin.toml +++ b/templates/redis-js/content/spin.toml @@ -16,6 +16,7 @@ component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] source = "target/{{project-name | kebab_case}}.wasm" exclude_files = ["**/node_modules"] + [component.{{project-name | kebab_case}}.build] -command = "npm run build" +command = "{{ package-manager }} run build" watch = ["src/**/*.ts", "package.json"] diff --git a/templates/redis-js/metadata/snippets/component.txt b/templates/redis-js/metadata/snippets/component.txt index a70eaa0d..7bc1b3a4 100644 --- a/templates/redis-js/metadata/snippets/component.txt +++ b/templates/redis-js/metadata/snippets/component.txt @@ -6,5 +6,5 @@ component = "{{project-name | kebab_case}}" source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm" allowed_outbound_hosts = [] [component.{{project-name | kebab_case}}.build] -command = "npm run build" +command = "{{ package-manager }} run build" workdir = "{{ output-path }}" \ No newline at end of file diff --git a/templates/redis-js/metadata/spin-template.toml b/templates/redis-js/metadata/spin-template.toml index 6bef03a6..4a5fb4bf 100644 --- a/templates/redis-js/metadata/spin-template.toml +++ b/templates/redis-js/metadata/spin-template.toml @@ -18,3 +18,4 @@ project-description = { type = "string", prompt = "Description", default = "" } redis-address = { type = "string", prompt = "Redis address", default = "redis://localhost:6379" } redis-channel = { type = "string", prompt = "Redis channel" } enable-aot = { type = "string", prompt = "Enable AoT Compilation [y/N]", default = "N", pattern = "^[yYnN]$" } +package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" } diff --git a/templates/redis-ts/content/package.json b/templates/redis-ts/content/package.json index 8f6d3744..a8949781 100644 --- a/templates/redis-ts/content/package.json +++ b/templates/redis-ts/content/package.json @@ -4,7 +4,11 @@ "description": "{{project-description}}", "main": "index.js", "scripts": { + {%- if package-manager == "npm" -%} "build": "npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}", + {%- else -%} + "build": "yarn exec webpack -- --mode=production && yarn exec mkdirp -- target && yarn exec j2w -- -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}", + {%- endif -%} "test": "echo \"Error: no test specified\" && exit 1", "postinstall": "knitwit" }, diff --git a/templates/redis-ts/content/spin.toml b/templates/redis-ts/content/spin.toml index 723b5507..65102e75 100644 --- a/templates/redis-ts/content/spin.toml +++ b/templates/redis-ts/content/spin.toml @@ -16,6 +16,7 @@ component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] source = "target/{{project-name | kebab_case}}.wasm" exclude_files = ["**/node_modules"] + [component.{{project-name | kebab_case}}.build] -command = "npm run build" +command = "{{ package-manager }} run build" watch = ["src/**/*.ts", "package.json"] diff --git a/templates/redis-ts/metadata/snippets/component.txt b/templates/redis-ts/metadata/snippets/component.txt index a70eaa0d..7bc1b3a4 100644 --- a/templates/redis-ts/metadata/snippets/component.txt +++ b/templates/redis-ts/metadata/snippets/component.txt @@ -6,5 +6,5 @@ component = "{{project-name | kebab_case}}" source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm" allowed_outbound_hosts = [] [component.{{project-name | kebab_case}}.build] -command = "npm run build" +command = "{{ package-manager }} run build" workdir = "{{ output-path }}" \ No newline at end of file diff --git a/templates/redis-ts/metadata/spin-template.toml b/templates/redis-ts/metadata/spin-template.toml index ca5cbdc0..86a040e2 100644 --- a/templates/redis-ts/metadata/spin-template.toml +++ b/templates/redis-ts/metadata/spin-template.toml @@ -18,3 +18,4 @@ project-description = { type = "string", prompt = "Description", default = "" } redis-address = { type = "string", prompt = "Redis address", default = "redis://localhost:6379" } redis-channel = { type = "string", prompt = "Redis channel" } enable-aot = { type = "string", prompt = "Enable AoT Compilation [y/N]", default = "N", pattern = "^[yYnN]$" } +package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" }