Skip to content

Commit 75e2f55

Browse files
committed
feat: Add support for yarn package manager
Signed-off-by: Thorsten Hans <[email protected]>
1 parent 0eaf37c commit 75e2f55

File tree

16 files changed

+50
-27
lines changed

16 files changed

+50
-27
lines changed
+23-19
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
{
2-
"name": "{{project-name | kebab_case}}",
3-
"version": "1.0.0",
4-
"description": "{{project-description}}",
5-
"main": "index.js",
6-
"scripts": {
2+
"name": "{{project-name | kebab_case}}",
3+
"version": "1.0.0",
4+
"description": "{{project-description}}",
5+
"main": "index.js",
6+
"scripts": {
7+
{%- if package-manager == "npm" -%}
78
"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",
9+
{%- else -%}
10+
"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",
11+
{%- endif -%}
812
"test": "echo \"Error: no test specified\" && exit 1"
9-
},
10-
"keywords": [],
11-
"author": "",
12-
"license": "ISC",
13-
"devDependencies": {
14-
"mkdirp": "^3.0.1",
15-
"webpack": "^5.74.0",
16-
"webpack-cli": "^4.10.0",
17-
"@fermyon/knitwit": "0.3.0"
18-
},
19-
"dependencies": {
20-
"@fermyon/spin-sdk": "^3.0.0",
21-
"itty-router": "^5.0.18"
22-
}
13+
},
14+
"keywords": [],
15+
"author": "",
16+
"license": "ISC",
17+
"devDependencies": {
18+
"mkdirp": "^3.0.1",
19+
"webpack": "^5.74.0",
20+
"webpack-cli": "^4.10.0",
21+
"@fermyon/knitwit": "0.3.0"
22+
},
23+
"dependencies": {
24+
"@fermyon/spin-sdk": "^3.0.0",
25+
"itty-router": "^5.0.18"
26+
}
2327
}

templates/http-js/content/spin.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ exclude_files = ["**/node_modules"]
1616
allowed_outbound_hosts = []
1717

1818
[component.{{project-name | kebab_case}}.build]
19-
command = ["npm install", "npm run build"]
19+
command = ["{{package-manager}} install", "{{package-manager}} run build"]
2020
watch = ["src/**/*.js"]

templates/http-js/metadata/snippets/component.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
77
allowed_outbound_hosts = []
88

99
[component.{{project-name | kebab_case}}.build]
10-
command = "npm install && npm run build"
10+
command = ["{{package-manager}} install", "{{package-manager}} run build"]
1111
workdir = "{{ output-path }}"

templates/http-js/metadata/spin-template.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ component = "component.txt"
1010
[parameters]
1111
project-description = { type = "string", prompt = "Description", default = "" }
1212
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }
13+
package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" }

templates/http-ts/content/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"description": "{{project-description}}",
55
"main": "index.js",
66
"scripts": {
7+
{%- if package-manager == "npm" -%}
78
"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",
9+
{%- else -%}
10+
"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",
11+
{%- endif -%}
812
"test": "echo \"Error: no test specified\" && exit 1"
913
},
1014
"keywords": [],

templates/http-ts/content/spin.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ component = "{{project-name | kebab_case}}"
1313
[component.{{project-name | kebab_case}}]
1414
source = "dist/{{project-name | kebab_case}}.wasm"
1515
exclude_files = ["**/node_modules"]
16+
allowed_outbound_hosts = []
1617

1718
[component.{{project-name | kebab_case}}.build]
18-
command = ["npm install", "npm run build"]
19+
command = ["{{package-manager}} install", "{{package-manager}} run build"]
1920
watch = ["src/**/*.ts"]

templates/http-ts/metadata/snippets/component.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
77
allowed_outbound_hosts = []
88

99
[component.{{project-name | kebab_case}}.build]
10-
command = "npm install && npm run build"
10+
command = ["{{package-manager}} install", "{{package-manager}} run build"]
1111
workdir = "{{ output-path }}"

templates/http-ts/metadata/spin-template.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ component = "component.txt"
1010
[parameters]
1111
project-description = { type = "string", prompt = "Description", default = "" }
1212
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }
13+
package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" }

templates/redis-js/content/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"description": "{{project-description}}",
55
"main": "index.js",
66
"scripts": {
7+
{%- if package-manager == "npm" -%}
78
"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",
9+
{%- else -%}
10+
"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",
11+
{%- endif -%}
812
"test": "echo \"Error: no test specified\" && exit 1",
913
"postinstall": "knitwit --out-dir build/wit/knitwit --out-world combined"
1014
},

templates/redis-js/content/spin.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ component = "{{project-name | kebab_case}}"
1616
[component.{{project-name | kebab_case}}]
1717
source = "dist/{{project-name | kebab_case}}.wasm"
1818
exclude_files = ["**/node_modules"]
19+
allowed_outbound_hosts = []
1920

2021
[component.{{project-name | kebab_case}}.build]
21-
command = "npm install && npm run build"
22+
command = ["{{package-manager}} install", "{{package-manager}} run build"]
2223
watch = ["src/**/*.ts", "package.json"]

templates/redis-js/metadata/snippets/component.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ component = "{{project-name | kebab_case}}"
66
source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
77
allowed_outbound_hosts = []
88
[component.{{project-name | kebab_case}}.build]
9-
command = "npm install && npm run build"
9+
command = ["{{package-manager}} install", "{{package-manager}} run build"]
1010
workdir = "{{ output-path }}"

templates/redis-js/metadata/spin-template.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ skip_snippets = ["application_trigger"]
1717
project-description = { type = "string", prompt = "Description", default = "" }
1818
redis-address = { type = "string", prompt = "Redis address", default = "redis://localhost:6379" }
1919
redis-channel = { type = "string", prompt = "Redis channel" }
20+
package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" }

templates/redis-ts/content/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"description": "{{project-description}}",
55
"main": "index.js",
66
"scripts": {
7+
{%- if package-manager == "npm" -%}
78
"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",
9+
{%- else -%}
10+
"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",
11+
{%- endif -%}
812
"test": "echo \"Error: no test specified\" && exit 1",
913
"postinstall": "knitwit --out-dir build/wit/knitwit --out-world combined"
1014
},

templates/redis-ts/content/spin.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ component = "{{project-name | kebab_case}}"
1616
[component.{{project-name | kebab_case}}]
1717
source = "dist/{{project-name | kebab_case}}.wasm"
1818
exclude_files = ["**/node_modules"]
19+
allowed_outbound_hosts = []
1920

2021
[component.{{project-name | kebab_case}}.build]
21-
command = "npm install && npm run build"
22+
command = ["{{package-manager}} install", "{{package-manager}} run build"]
2223
watch = ["src/**/*.ts", "package.json"]

templates/redis-ts/metadata/snippets/component.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ component = "{{project-name | kebab_case}}"
66
source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
77
allowed_outbound_hosts = []
88
[component.{{project-name | kebab_case}}.build]
9-
command = "npm install && npm run build"
9+
command = ["{{package-manager}} install", "{{package-manager}} run build"]
1010
workdir = "{{ output-path }}"

templates/redis-ts/metadata/spin-template.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ skip_snippets = ["application_trigger"]
1717
project-description = { type = "string", prompt = "Description", default = "" }
1818
redis-address = { type = "string", prompt = "Redis address", default = "redis://localhost:6379" }
1919
redis-channel = { type = "string", prompt = "Redis channel" }
20+
package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" }

0 commit comments

Comments
 (0)