Skip to content

Commit

Permalink
feat: Add support for yarn package manager
Browse files Browse the repository at this point in the history
Signed-off-by: Thorsten Hans <[email protected]>
  • Loading branch information
ThorstenHans committed Feb 11, 2025
1 parent 0eaf37c commit 75e2f55
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 27 deletions.
42 changes: 23 additions & 19 deletions templates/http-js/content/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
{
"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": "knitwit --out-dir build/wit/knitwit --out-world combined && npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{project-name | kebab_case}}.wasm",
{%- else -%}
"build": "knitwit --out-dir build/wit/knitwit --out-world combined && yarn exec webpack -- --mode=production && yarn exec mkdirp -- dist && yarn exec j2w -- -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{project-name | kebab_case}}.wasm",
{%- endif -%}
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mkdirp": "^3.0.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"@fermyon/knitwit": "0.3.0"
},
"dependencies": {
"@fermyon/spin-sdk": "^3.0.0",
"itty-router": "^5.0.18"
}
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mkdirp": "^3.0.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"@fermyon/knitwit": "0.3.0"
},
"dependencies": {
"@fermyon/spin-sdk": "^3.0.0",
"itty-router": "^5.0.18"
}
}
2 changes: 1 addition & 1 deletion templates/http-js/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ exclude_files = ["**/node_modules"]
allowed_outbound_hosts = []

[component.{{project-name | kebab_case}}.build]
command = ["npm install", "npm run build"]
command = ["{{package-manager}} install", "{{package-manager}} run build"]
watch = ["src/**/*.js"]
2 changes: 1 addition & 1 deletion templates/http-js/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
allowed_outbound_hosts = []

[component.{{project-name | kebab_case}}.build]
command = "npm install && npm run build"
command = ["{{package-manager}} install", "{{package-manager}} run build"]
workdir = "{{ output-path }}"
1 change: 1 addition & 0 deletions templates/http-js/metadata/spin-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ component = "component.txt"
[parameters]
project-description = { type = "string", prompt = "Description", default = "" }
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }
package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" }
4 changes: 4 additions & 0 deletions templates/http-ts/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"description": "{{project-description}}",
"main": "index.js",
"scripts": {
{%- if package-manager == "npm" -%}
"build": "knitwit --out-dir build/wit/knitwit --out-world combined && npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{ project-name | kebab_case }}.wasm",
{%- else -%}
"build": "knitwit --out-dir build/wit/knitwit --out-world combined && yarn exec webpack -- --mode=production && yarn exec mkdirp -- dist && yarn exec j2w -- -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{ project-name | kebab_case }}.wasm",
{%- endif -%}
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
Expand Down
3 changes: 2 additions & 1 deletion templates/http-ts/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ component = "{{project-name | kebab_case}}"
[component.{{project-name | kebab_case}}]
source = "dist/{{project-name | kebab_case}}.wasm"
exclude_files = ["**/node_modules"]
allowed_outbound_hosts = []

[component.{{project-name | kebab_case}}.build]
command = ["npm install", "npm run build"]
command = ["{{package-manager}} install", "{{package-manager}} run build"]
watch = ["src/**/*.ts"]
2 changes: 1 addition & 1 deletion templates/http-ts/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
allowed_outbound_hosts = []

[component.{{project-name | kebab_case}}.build]
command = "npm install && npm run build"
command = ["{{package-manager}} install", "{{package-manager}} run build"]
workdir = "{{ output-path }}"
1 change: 1 addition & 0 deletions templates/http-ts/metadata/spin-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ component = "component.txt"
[parameters]
project-description = { type = "string", prompt = "Description", default = "" }
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }
package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" }
4 changes: 4 additions & 0 deletions templates/redis-js/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"description": "{{project-description}}",
"main": "index.js",
"scripts": {
{%- if package-manager == "npm" -%}
"build": "npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{project-name | kebab_case}}.wasm",
{%- else -%}
"build": "yarn exec webpack -- --mode=production && yarn exec mkdirp -- dist && yarn exec j2w -- -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{project-name | kebab_case}}.wasm",
{%- endif -%}
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "knitwit --out-dir build/wit/knitwit --out-world combined"
},
Expand Down
3 changes: 2 additions & 1 deletion templates/redis-js/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ component = "{{project-name | kebab_case}}"
[component.{{project-name | kebab_case}}]
source = "dist/{{project-name | kebab_case}}.wasm"
exclude_files = ["**/node_modules"]
allowed_outbound_hosts = []

[component.{{project-name | kebab_case}}.build]
command = "npm install && npm run build"
command = ["{{package-manager}} install", "{{package-manager}} run build"]
watch = ["src/**/*.ts", "package.json"]
2 changes: 1 addition & 1 deletion templates/redis-js/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ component = "{{project-name | kebab_case}}"
source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
allowed_outbound_hosts = []
[component.{{project-name | kebab_case}}.build]
command = "npm install && npm run build"
command = ["{{package-manager}} install", "{{package-manager}} run build"]
workdir = "{{ output-path }}"
1 change: 1 addition & 0 deletions templates/redis-js/metadata/spin-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ skip_snippets = ["application_trigger"]
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" }
package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" }
4 changes: 4 additions & 0 deletions templates/redis-ts/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"description": "{{project-description}}",
"main": "index.js",
"scripts": {
{%- if package-manager == "npm" -%}
"build": "npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{project-name | kebab_case}}.wasm",
{%- else -%}
"build": "yarn exec webpack -- --mode=production && yarn exec mkdirp -- dist && yarn exec j2w -- -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{project-name | kebab_case}}.wasm",
{%- endif -%}
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "knitwit --out-dir build/wit/knitwit --out-world combined"
},
Expand Down
3 changes: 2 additions & 1 deletion templates/redis-ts/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ component = "{{project-name | kebab_case}}"
[component.{{project-name | kebab_case}}]
source = "dist/{{project-name | kebab_case}}.wasm"
exclude_files = ["**/node_modules"]
allowed_outbound_hosts = []

[component.{{project-name | kebab_case}}.build]
command = "npm install && npm run build"
command = ["{{package-manager}} install", "{{package-manager}} run build"]
watch = ["src/**/*.ts", "package.json"]
2 changes: 1 addition & 1 deletion templates/redis-ts/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ component = "{{project-name | kebab_case}}"
source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
allowed_outbound_hosts = []
[component.{{project-name | kebab_case}}.build]
command = "npm install && npm run build"
command = ["{{package-manager}} install", "{{package-manager}} run build"]
workdir = "{{ output-path }}"
1 change: 1 addition & 0 deletions templates/redis-ts/metadata/spin-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ skip_snippets = ["application_trigger"]
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" }
package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" }

0 comments on commit 75e2f55

Please sign in to comment.