@tauri-apps/cli 1.0.0-beta.8 → 1.0.0-rc.2
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/.github-example/workflows/CI.yml +469 -0
- package/CHANGELOG.md +30 -297
- package/Cargo.toml +16 -0
- package/README.md +1 -1
- package/build.rs +7 -0
- package/index.d.ts +12 -0
- package/index.js +241 -0
- package/jest.config.js +14 -0
- package/package.json +45 -85
- package/src/lib.rs +10 -0
- package/tauri.js +50 -0
- package/test/jest/__tests__/template.spec.js +41 -0
- package/test/jest/fixtures/app/dist/index.html +140 -0
- package/test/jest/fixtures/app/index.js +53 -0
- package/test/jest/fixtures/app/package.json +22 -0
- package/test/jest/fixtures/app/src-tauri/Cargo.toml +34 -0
- package/test/jest/fixtures/app/src-tauri/build.rs +7 -0
- package/test/jest/fixtures/app/src-tauri/icons/128x128.png +0 -0
- package/test/jest/fixtures/app/src-tauri/icons/128x128@2x.png +0 -0
- package/test/jest/fixtures/app/src-tauri/icons/32x32.png +0 -0
- package/test/jest/fixtures/app/src-tauri/icons/icon.icns +0 -0
- package/test/jest/fixtures/app/src-tauri/icons/icon.ico +0 -0
- package/test/jest/fixtures/app/src-tauri/icons/icon.png +0 -0
- package/test/jest/fixtures/app/src-tauri/src/main.rs +20 -0
- package/test/jest/fixtures/app/src-tauri/tauri.conf.json +28 -0
- package/test/jest/fixtures/app-test-setup.js +86 -0
- package/test/jest/fixtures/empty/dist/index.html +6 -0
- package/test/jest/fixtures/empty/package.json +1 -0
- package/test/jest/helpers/logger.js +25 -0
- package/test/jest/helpers/spawn.js +73 -0
- package/test/jest/jest.setup.js +6 -0
- package/LICENSE_APACHE-2.0 +0 -177
- package/LICENSE_MIT +0 -21
- package/bin/tauri-deps.js +0 -26
- package/bin/tauri-icon.js +0 -61
- package/bin/tauri.js +0 -102
- package/dist/api/cli.js +0 -2
- package/dist/api/cli.js.map +0 -1
- package/dist/api/dependency-manager.js +0 -2
- package/dist/api/dependency-manager.js.map +0 -1
- package/dist/api/tauricon.js +0 -3
- package/dist/api/tauricon.js.LICENSE.txt +0 -11
- package/dist/api/tauricon.js.map +0 -1
- package/dist/helpers/download-binary.js +0 -2
- package/dist/helpers/download-binary.js.map +0 -1
- package/dist/helpers/rust-cli.js +0 -2
- package/dist/helpers/rust-cli.js.map +0 -1
- package/dist/helpers/spawn.js +0 -2
- package/dist/helpers/spawn.js.map +0 -1
package/index.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
const { existsSync, readFileSync } = require('fs')
|
|
2
|
+
const { join } = require('path')
|
|
3
|
+
|
|
4
|
+
const { platform, arch } = process
|
|
5
|
+
|
|
6
|
+
let nativeBinding = null
|
|
7
|
+
let localFileExisted = false
|
|
8
|
+
let loadError = null
|
|
9
|
+
|
|
10
|
+
function isMusl() {
|
|
11
|
+
// For Node 10
|
|
12
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
13
|
+
try {
|
|
14
|
+
return readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
|
|
15
|
+
} catch (e) {
|
|
16
|
+
return true
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
const { glibcVersionRuntime } = process.report.getReport().header
|
|
20
|
+
return !glibcVersionRuntime
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
switch (platform) {
|
|
25
|
+
case 'android':
|
|
26
|
+
switch (arch) {
|
|
27
|
+
case 'arm64':
|
|
28
|
+
localFileExisted = existsSync(join(__dirname, 'cli.android-arm64.node'))
|
|
29
|
+
try {
|
|
30
|
+
if (localFileExisted) {
|
|
31
|
+
nativeBinding = require('./cli.android-arm64.node')
|
|
32
|
+
} else {
|
|
33
|
+
nativeBinding = require('@tauri-apps/cli-android-arm64')
|
|
34
|
+
}
|
|
35
|
+
} catch (e) {
|
|
36
|
+
loadError = e
|
|
37
|
+
}
|
|
38
|
+
break
|
|
39
|
+
case 'arm':
|
|
40
|
+
localFileExisted = existsSync(join(__dirname, 'cli.android-arm-eabi.node'))
|
|
41
|
+
try {
|
|
42
|
+
if (localFileExisted) {
|
|
43
|
+
nativeBinding = require('./cli.android-arm-eabi.node')
|
|
44
|
+
} else {
|
|
45
|
+
nativeBinding = require('@tauri-apps/cli-android-arm-eabi')
|
|
46
|
+
}
|
|
47
|
+
} catch (e) {
|
|
48
|
+
loadError = e
|
|
49
|
+
}
|
|
50
|
+
break
|
|
51
|
+
default:
|
|
52
|
+
throw new Error(`Unsupported architecture on Android ${arch}`)
|
|
53
|
+
}
|
|
54
|
+
break
|
|
55
|
+
case 'win32':
|
|
56
|
+
switch (arch) {
|
|
57
|
+
case 'x64':
|
|
58
|
+
localFileExisted = existsSync(
|
|
59
|
+
join(__dirname, 'cli.win32-x64-msvc.node')
|
|
60
|
+
)
|
|
61
|
+
try {
|
|
62
|
+
if (localFileExisted) {
|
|
63
|
+
nativeBinding = require('./cli.win32-x64-msvc.node')
|
|
64
|
+
} else {
|
|
65
|
+
nativeBinding = require('@tauri-apps/cli-win32-x64-msvc')
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
loadError = e
|
|
69
|
+
}
|
|
70
|
+
break
|
|
71
|
+
case 'ia32':
|
|
72
|
+
localFileExisted = existsSync(
|
|
73
|
+
join(__dirname, 'cli.win32-ia32-msvc.node')
|
|
74
|
+
)
|
|
75
|
+
try {
|
|
76
|
+
if (localFileExisted) {
|
|
77
|
+
nativeBinding = require('./cli.win32-ia32-msvc.node')
|
|
78
|
+
} else {
|
|
79
|
+
nativeBinding = require('@tauri-apps/cli-win32-ia32-msvc')
|
|
80
|
+
}
|
|
81
|
+
} catch (e) {
|
|
82
|
+
loadError = e
|
|
83
|
+
}
|
|
84
|
+
break
|
|
85
|
+
case 'arm64':
|
|
86
|
+
localFileExisted = existsSync(
|
|
87
|
+
join(__dirname, 'cli.win32-arm64-msvc.node')
|
|
88
|
+
)
|
|
89
|
+
try {
|
|
90
|
+
if (localFileExisted) {
|
|
91
|
+
nativeBinding = require('./cli.win32-arm64-msvc.node')
|
|
92
|
+
} else {
|
|
93
|
+
nativeBinding = require('@tauri-apps/cli-win32-arm64-msvc')
|
|
94
|
+
}
|
|
95
|
+
} catch (e) {
|
|
96
|
+
loadError = e
|
|
97
|
+
}
|
|
98
|
+
break
|
|
99
|
+
default:
|
|
100
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
|
101
|
+
}
|
|
102
|
+
break
|
|
103
|
+
case 'darwin':
|
|
104
|
+
switch (arch) {
|
|
105
|
+
case 'x64':
|
|
106
|
+
localFileExisted = existsSync(join(__dirname, 'cli.darwin-x64.node'))
|
|
107
|
+
try {
|
|
108
|
+
if (localFileExisted) {
|
|
109
|
+
nativeBinding = require('./cli.darwin-x64.node')
|
|
110
|
+
} else {
|
|
111
|
+
nativeBinding = require('@tauri-apps/cli-darwin-x64')
|
|
112
|
+
}
|
|
113
|
+
} catch (e) {
|
|
114
|
+
loadError = e
|
|
115
|
+
}
|
|
116
|
+
break
|
|
117
|
+
case 'arm64':
|
|
118
|
+
localFileExisted = existsSync(
|
|
119
|
+
join(__dirname, 'cli.darwin-arm64.node')
|
|
120
|
+
)
|
|
121
|
+
try {
|
|
122
|
+
if (localFileExisted) {
|
|
123
|
+
nativeBinding = require('./cli.darwin-arm64.node')
|
|
124
|
+
} else {
|
|
125
|
+
nativeBinding = require('@tauri-apps/cli-darwin-arm64')
|
|
126
|
+
}
|
|
127
|
+
} catch (e) {
|
|
128
|
+
loadError = e
|
|
129
|
+
}
|
|
130
|
+
break
|
|
131
|
+
default:
|
|
132
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
|
133
|
+
}
|
|
134
|
+
break
|
|
135
|
+
case 'freebsd':
|
|
136
|
+
if (arch !== 'x64') {
|
|
137
|
+
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
|
138
|
+
}
|
|
139
|
+
localFileExisted = existsSync(join(__dirname, 'cli.freebsd-x64.node'))
|
|
140
|
+
try {
|
|
141
|
+
if (localFileExisted) {
|
|
142
|
+
nativeBinding = require('./cli.freebsd-x64.node')
|
|
143
|
+
} else {
|
|
144
|
+
nativeBinding = require('@tauri-apps/cli-freebsd-x64')
|
|
145
|
+
}
|
|
146
|
+
} catch (e) {
|
|
147
|
+
loadError = e
|
|
148
|
+
}
|
|
149
|
+
break
|
|
150
|
+
case 'linux':
|
|
151
|
+
switch (arch) {
|
|
152
|
+
case 'x64':
|
|
153
|
+
if (isMusl()) {
|
|
154
|
+
localFileExisted = existsSync(
|
|
155
|
+
join(__dirname, 'cli.linux-x64-musl.node')
|
|
156
|
+
)
|
|
157
|
+
try {
|
|
158
|
+
if (localFileExisted) {
|
|
159
|
+
nativeBinding = require('./cli.linux-x64-musl.node')
|
|
160
|
+
} else {
|
|
161
|
+
nativeBinding = require('@tauri-apps/cli-linux-x64-musl')
|
|
162
|
+
}
|
|
163
|
+
} catch (e) {
|
|
164
|
+
loadError = e
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
localFileExisted = existsSync(
|
|
168
|
+
join(__dirname, 'cli.linux-x64-gnu.node')
|
|
169
|
+
)
|
|
170
|
+
try {
|
|
171
|
+
if (localFileExisted) {
|
|
172
|
+
nativeBinding = require('./cli.linux-x64-gnu.node')
|
|
173
|
+
} else {
|
|
174
|
+
nativeBinding = require('@tauri-apps/cli-linux-x64-gnu')
|
|
175
|
+
}
|
|
176
|
+
} catch (e) {
|
|
177
|
+
loadError = e
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
break
|
|
181
|
+
case 'arm64':
|
|
182
|
+
if (isMusl()) {
|
|
183
|
+
localFileExisted = existsSync(
|
|
184
|
+
join(__dirname, 'cli.linux-arm64-musl.node')
|
|
185
|
+
)
|
|
186
|
+
try {
|
|
187
|
+
if (localFileExisted) {
|
|
188
|
+
nativeBinding = require('./cli.linux-arm64-musl.node')
|
|
189
|
+
} else {
|
|
190
|
+
nativeBinding = require('@tauri-apps/cli-linux-arm64-musl')
|
|
191
|
+
}
|
|
192
|
+
} catch (e) {
|
|
193
|
+
loadError = e
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
localFileExisted = existsSync(
|
|
197
|
+
join(__dirname, 'cli.linux-arm64-gnu.node')
|
|
198
|
+
)
|
|
199
|
+
try {
|
|
200
|
+
if (localFileExisted) {
|
|
201
|
+
nativeBinding = require('./cli.linux-arm64-gnu.node')
|
|
202
|
+
} else {
|
|
203
|
+
nativeBinding = require('@tauri-apps/cli-linux-arm64-gnu')
|
|
204
|
+
}
|
|
205
|
+
} catch (e) {
|
|
206
|
+
loadError = e
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
break
|
|
210
|
+
case 'arm':
|
|
211
|
+
localFileExisted = existsSync(
|
|
212
|
+
join(__dirname, 'cli.linux-arm-gnueabihf.node')
|
|
213
|
+
)
|
|
214
|
+
try {
|
|
215
|
+
if (localFileExisted) {
|
|
216
|
+
nativeBinding = require('./cli.linux-arm-gnueabihf.node')
|
|
217
|
+
} else {
|
|
218
|
+
nativeBinding = require('@tauri-apps/cli-linux-arm-gnueabihf')
|
|
219
|
+
}
|
|
220
|
+
} catch (e) {
|
|
221
|
+
loadError = e
|
|
222
|
+
}
|
|
223
|
+
break
|
|
224
|
+
default:
|
|
225
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
|
226
|
+
}
|
|
227
|
+
break
|
|
228
|
+
default:
|
|
229
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!nativeBinding) {
|
|
233
|
+
if (loadError) {
|
|
234
|
+
throw loadError
|
|
235
|
+
}
|
|
236
|
+
throw new Error(`Failed to load native binding`)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const { run } = nativeBinding
|
|
240
|
+
|
|
241
|
+
module.exports.run = run
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
setupFilesAfterEnv: ['<rootDir>/test/jest/jest.setup.js'],
|
|
3
|
+
testMatch: [
|
|
4
|
+
'<rootDir>/test/jest/__tests__/**/*.spec.js',
|
|
5
|
+
'<rootDir>/test/jest/__tests__/**/*.test.js'
|
|
6
|
+
],
|
|
7
|
+
moduleFileExtensions: ['ts', 'js', 'json'],
|
|
8
|
+
moduleNameMapper: {
|
|
9
|
+
'^~/(.*)$': '<rootDir>/$1'
|
|
10
|
+
},
|
|
11
|
+
transform: {
|
|
12
|
+
'\\.toml$': 'jest-transform-toml'
|
|
13
|
+
}
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,32 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-apps/cli",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
4
|
"description": "Command line interface for building Tauri apps",
|
|
5
|
-
"bin": {
|
|
6
|
-
"tauri": "./bin/tauri.js"
|
|
7
|
-
},
|
|
8
|
-
"files": [
|
|
9
|
-
"bin",
|
|
10
|
-
"dist",
|
|
11
|
-
"scripts"
|
|
12
|
-
],
|
|
13
5
|
"funding": {
|
|
14
6
|
"type": "opencollective",
|
|
15
7
|
"url": "https://opencollective.com/tauri"
|
|
16
8
|
},
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "rimraf ./dist && webpack --progress",
|
|
19
|
-
"build-release": "rimraf ./dist && cross-env NODE_ENV=production webpack",
|
|
20
|
-
"test": "jest --runInBand --no-cache --testPathIgnorePatterns=\"(build|dev)\"",
|
|
21
|
-
"pretest": "yarn build",
|
|
22
|
-
"prepublishOnly": "yarn build-release",
|
|
23
|
-
"test:local": "jest --runInBand",
|
|
24
|
-
"lint": "eslint --ext ts \"./src/**/*.ts\"",
|
|
25
|
-
"lint-fix": "eslint --fix --ext ts \"./src/**/*.ts\"",
|
|
26
|
-
"lint:lockfile": "lockfile-lint --path yarn.lock --type yarn --validate-https --allowed-hosts npm yarn",
|
|
27
|
-
"format": "prettier --write --end-of-line=auto \"./**/*.{cjs,js,jsx,ts,tsx,html,css,json}\" --ignore-path .gitignore",
|
|
28
|
-
"format:check": "prettier --check --end-of-line=auto \"./**/*.{cjs,js,jsx,ts,tsx,html,css,json}\" --ignore-path .gitignore"
|
|
29
|
-
},
|
|
30
9
|
"repository": {
|
|
31
10
|
"type": "git",
|
|
32
11
|
"url": "git+https://github.com/tauri-apps/tauri.git"
|
|
@@ -42,72 +21,53 @@
|
|
|
42
21
|
"publishConfig": {
|
|
43
22
|
"access": "public"
|
|
44
23
|
},
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
24
|
+
"main": "index.js",
|
|
25
|
+
"types": "index.d.ts",
|
|
26
|
+
"napi": {
|
|
27
|
+
"name": "cli",
|
|
28
|
+
"triples": {
|
|
29
|
+
"additional": [
|
|
30
|
+
"aarch64-apple-darwin",
|
|
31
|
+
"aarch64-unknown-linux-gnu",
|
|
32
|
+
"aarch64-unknown-linux-musl",
|
|
33
|
+
"armv7-unknown-linux-gnueabihf",
|
|
34
|
+
"x86_64-unknown-linux-musl"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
49
37
|
},
|
|
50
|
-
"
|
|
51
|
-
"@
|
|
52
|
-
"chalk": "4.1.2",
|
|
53
|
-
"cross-env": "7.0.3",
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@napi-rs/cli": "2.4.2",
|
|
54
40
|
"cross-spawn": "7.0.3",
|
|
55
41
|
"fs-extra": "10.0.0",
|
|
56
|
-
"
|
|
57
|
-
"got": "11.8.2",
|
|
58
|
-
"imagemin": "8.0.1",
|
|
59
|
-
"imagemin-optipng": "8.0.0",
|
|
60
|
-
"imagemin-zopfli": "7.0.0",
|
|
61
|
-
"inquirer": "8.1.2",
|
|
62
|
-
"is-png": "3.0.0",
|
|
63
|
-
"minimist": "1.2.5",
|
|
64
|
-
"ms": "2.1.3",
|
|
65
|
-
"png2icons": "2.0.1",
|
|
66
|
-
"read-chunk": "3.2.0",
|
|
67
|
-
"semver": "7.3.5",
|
|
68
|
-
"sharp": "0.28.3",
|
|
69
|
-
"update-notifier": "5.1.0"
|
|
70
|
-
},
|
|
71
|
-
"devDependencies": {
|
|
72
|
-
"@babel/core": "7.15.0",
|
|
73
|
-
"@babel/preset-env": "7.15.0",
|
|
74
|
-
"@babel/preset-typescript": "7.15.0",
|
|
75
|
-
"@types/cross-spawn": "6.0.2",
|
|
76
|
-
"@types/fs-extra": "9.0.12",
|
|
77
|
-
"@types/global-agent": "2.1.1",
|
|
78
|
-
"@types/imagemin": "7.0.1",
|
|
79
|
-
"@types/imagemin-optipng": "5.2.1",
|
|
80
|
-
"@types/inquirer": "7.3.3",
|
|
81
|
-
"@types/ms": "0.7.31",
|
|
82
|
-
"@types/semver": "7.3.8",
|
|
83
|
-
"@types/sharp": "0.28.5",
|
|
84
|
-
"@typescript-eslint/eslint-plugin": "4.29.1",
|
|
85
|
-
"@typescript-eslint/parser": "4.29.1",
|
|
86
|
-
"babel-jest": "27.0.6",
|
|
87
|
-
"eslint": "7.32.0",
|
|
88
|
-
"eslint-config-prettier": "8.3.0",
|
|
89
|
-
"eslint-config-standard-with-typescript": "20.0.0",
|
|
90
|
-
"eslint-plugin-import": "2.24.0",
|
|
91
|
-
"eslint-plugin-lodash-template": "0.19.0",
|
|
92
|
-
"eslint-plugin-node": "11.1.0",
|
|
93
|
-
"eslint-plugin-promise": "5.1.0",
|
|
94
|
-
"eslint-plugin-security": "1.4.0",
|
|
95
|
-
"is-running": "2.1.0",
|
|
96
|
-
"jest": "27.0.6",
|
|
42
|
+
"jest": "27.5.1",
|
|
97
43
|
"jest-transform-toml": "1.0.0",
|
|
98
|
-
"
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
"
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
"
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
"
|
|
108
|
-
"
|
|
44
|
+
"prettier": "2.5.1"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">= 10"
|
|
48
|
+
},
|
|
49
|
+
"bin": {
|
|
50
|
+
"tauri": "./tauri.js"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"artifacts": "napi artifacts",
|
|
54
|
+
"build": "napi build --platform --release",
|
|
55
|
+
"build:debug": "napi build --platform",
|
|
56
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
57
|
+
"test": "jest --runInBand --forceExit --no-cache",
|
|
58
|
+
"version": "napi version",
|
|
59
|
+
"tauri": "node ./tauri.js",
|
|
60
|
+
"format": "prettier --write ./package.json ./tauri.js",
|
|
61
|
+
"format:check": "prettier --check ./package.json ./tauri.js"
|
|
109
62
|
},
|
|
110
|
-
"
|
|
111
|
-
"
|
|
63
|
+
"optionalDependencies": {
|
|
64
|
+
"@tauri-apps/cli-win32-x64-msvc": "1.0.0-rc.2",
|
|
65
|
+
"@tauri-apps/cli-darwin-x64": "1.0.0-rc.2",
|
|
66
|
+
"@tauri-apps/cli-linux-x64-gnu": "1.0.0-rc.2",
|
|
67
|
+
"@tauri-apps/cli-darwin-arm64": "1.0.0-rc.2",
|
|
68
|
+
"@tauri-apps/cli-linux-arm64-gnu": "1.0.0-rc.2",
|
|
69
|
+
"@tauri-apps/cli-linux-arm64-musl": "1.0.0-rc.2",
|
|
70
|
+
"@tauri-apps/cli-linux-arm-gnueabihf": "1.0.0-rc.2",
|
|
71
|
+
"@tauri-apps/cli-linux-x64-musl": "1.0.0-rc.2"
|
|
112
72
|
}
|
|
113
|
-
}
|
|
73
|
+
}
|
package/src/lib.rs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
use napi::{Error, Result, Status};
|
|
6
|
+
|
|
7
|
+
#[napi_derive::napi]
|
|
8
|
+
pub fn run(args: Vec<String>, bin_name: Option<String>) -> Result<()> {
|
|
9
|
+
tauri_cli::run(args, bin_name).map_err(|e| Error::new(Status::GenericFailure, e.to_string()))
|
|
10
|
+
}
|
package/tauri.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const cli = require('./index')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
|
|
6
|
+
const [bin, script, ...arguments] = process.argv
|
|
7
|
+
const binStem = path.parse(bin).name.toLowerCase()
|
|
8
|
+
|
|
9
|
+
// We want to make a helpful binary name for the underlying CLI helper, if we
|
|
10
|
+
// can successfully detect what command likely started the execution.
|
|
11
|
+
let binName
|
|
12
|
+
|
|
13
|
+
// Even if started by a package manager, the binary will be NodeJS.
|
|
14
|
+
// Some distribution still use "nodejs" as the binary name.
|
|
15
|
+
if (binStem === 'node' || binStem === 'nodejs') {
|
|
16
|
+
const managerStem = process.env.npm_execpath
|
|
17
|
+
? path.parse(process.env.npm_execpath).name.toLowerCase()
|
|
18
|
+
: null
|
|
19
|
+
if (managerStem) {
|
|
20
|
+
let manager
|
|
21
|
+
switch (managerStem) {
|
|
22
|
+
// Only supported package manager that has a different filename is npm.
|
|
23
|
+
case 'npm-cli':
|
|
24
|
+
manager = 'npm'
|
|
25
|
+
break
|
|
26
|
+
|
|
27
|
+
// Yarn and pnpm have the same stem name as their bin.
|
|
28
|
+
// We assume all unknown package managers do as well.
|
|
29
|
+
default:
|
|
30
|
+
manager = managerStem
|
|
31
|
+
break
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
binName = `${manager} run ${process.env.npm_lifecycle_event}`
|
|
35
|
+
} else {
|
|
36
|
+
// Assume running NodeJS if we didn't detect a manager from the env.
|
|
37
|
+
// We normalize the path to prevent the script's absolute path being used.
|
|
38
|
+
const scriptNormal = path.normalize(path.relative(process.cwd(), script))
|
|
39
|
+
binName = `${binStem} ${scriptNormal}`
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
// We don't know what started it, assume it's already stripped.
|
|
43
|
+
arguments.unshift(bin)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
cli.run(arguments, binName)
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.log(`Error running CLI: ${e.message}`)
|
|
50
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const fixtureSetup = require('../fixtures/app-test-setup.js')
|
|
2
|
+
const { resolve } = require('path')
|
|
3
|
+
const { existsSync, readFileSync, writeFileSync } = require('fs')
|
|
4
|
+
const { move } = require('fs-extra')
|
|
5
|
+
const cli = require('~/index.js')
|
|
6
|
+
|
|
7
|
+
const currentDirName = __dirname
|
|
8
|
+
|
|
9
|
+
describe('[CLI] cli.js template', () => {
|
|
10
|
+
it('init a project and builds it', async () => {
|
|
11
|
+
const cwd = process.cwd()
|
|
12
|
+
const fixturePath = resolve(currentDirName, '../fixtures/empty')
|
|
13
|
+
const tauriFixturePath = resolve(fixturePath, 'src-tauri')
|
|
14
|
+
const outPath = resolve(tauriFixturePath, 'target')
|
|
15
|
+
const cacheOutPath = resolve(fixturePath, 'target')
|
|
16
|
+
|
|
17
|
+
fixtureSetup.initJest('empty')
|
|
18
|
+
|
|
19
|
+
process.chdir(fixturePath)
|
|
20
|
+
|
|
21
|
+
const outExists = existsSync(outPath)
|
|
22
|
+
if (outExists) {
|
|
23
|
+
await move(outPath, cacheOutPath)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
cli.run(['init', '--directory', process.cwd(), '--force', '--tauri-path', resolve(currentDirName, '../../../../../..'), '--ci'])
|
|
27
|
+
|
|
28
|
+
if (outExists) {
|
|
29
|
+
await move(cacheOutPath, outPath)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
process.chdir(tauriFixturePath)
|
|
33
|
+
|
|
34
|
+
const manifestPath = resolve(tauriFixturePath, 'Cargo.toml')
|
|
35
|
+
const manifestFile = readFileSync(manifestPath).toString()
|
|
36
|
+
writeFileSync(manifestPath, `workspace = { }\n${manifestFile}`)
|
|
37
|
+
|
|
38
|
+
cli.run(['build', '--verbose'])
|
|
39
|
+
process.chdir(cwd)
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<body>
|
|
4
|
+
<script>
|
|
5
|
+
function callBackEnd(route, args) {
|
|
6
|
+
console.log(route)
|
|
7
|
+
console.log(args)
|
|
8
|
+
window.__TAURI__.http
|
|
9
|
+
.fetch('http://localhost:7000/' + route, {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
body: window.__TAURI__.http.Body.json(args),
|
|
12
|
+
responseType: window.__TAURI__.http.ResponseType.Binary
|
|
13
|
+
})
|
|
14
|
+
.catch(console.error)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function reply(args) {
|
|
18
|
+
return callBackEnd('reply', args)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function sendError(error) {
|
|
22
|
+
return callBackEnd('error', error)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function testFs(dir) {
|
|
26
|
+
var contents = 'TAURI E2E TEST FILE'
|
|
27
|
+
var commandSuffix = dir ? 'WithDir' : ''
|
|
28
|
+
|
|
29
|
+
var options = {
|
|
30
|
+
dir: dir || null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return window.__TAURI__.fs
|
|
34
|
+
.writeFile(
|
|
35
|
+
{
|
|
36
|
+
path: 'tauri-test.txt',
|
|
37
|
+
contents: contents
|
|
38
|
+
},
|
|
39
|
+
options
|
|
40
|
+
)
|
|
41
|
+
.then(function (res) {
|
|
42
|
+
reply({
|
|
43
|
+
cmd: 'writeFile' + commandSuffix
|
|
44
|
+
})
|
|
45
|
+
return window.__TAURI__.fs
|
|
46
|
+
.readTextFile('tauri-test.txt', options)
|
|
47
|
+
.then(function (res) {
|
|
48
|
+
if (res === contents) {
|
|
49
|
+
reply({
|
|
50
|
+
cmd: 'readFile' + commandSuffix
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return window.__TAURI__.fs
|
|
54
|
+
.readDir('.', options)
|
|
55
|
+
.then((res) => {
|
|
56
|
+
reply({
|
|
57
|
+
cmd: 'readDir' + commandSuffix
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
return window.__TAURI__.fs
|
|
61
|
+
.copyFile(
|
|
62
|
+
'tauri-test.txt',
|
|
63
|
+
'tauri-test-copy.txt',
|
|
64
|
+
options
|
|
65
|
+
)
|
|
66
|
+
.then(function (res) {
|
|
67
|
+
reply({
|
|
68
|
+
cmd: 'copyFile' + commandSuffix
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
return window.__TAURI__.fs
|
|
72
|
+
.createDir('tauri-test-dir', options)
|
|
73
|
+
.then(function (res) {
|
|
74
|
+
reply({
|
|
75
|
+
cmd: 'createDir' + commandSuffix
|
|
76
|
+
})
|
|
77
|
+
return window.__TAURI__.fs
|
|
78
|
+
.removeDir('tauri-test-dir', options)
|
|
79
|
+
.then(function (res) {
|
|
80
|
+
reply({
|
|
81
|
+
cmd: 'removeDir' + commandSuffix
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
.then(function (res) {
|
|
86
|
+
return window.__TAURI__.fs
|
|
87
|
+
.renameFile(
|
|
88
|
+
'tauri-test.txt',
|
|
89
|
+
'tauri.testt.txt',
|
|
90
|
+
options
|
|
91
|
+
)
|
|
92
|
+
.then(function (res) {
|
|
93
|
+
reply({
|
|
94
|
+
cmd: 'renameFile' + commandSuffix
|
|
95
|
+
})
|
|
96
|
+
return Promise.all([
|
|
97
|
+
window.__TAURI__.fs.removeFile(
|
|
98
|
+
'tauri.testt.txt',
|
|
99
|
+
options
|
|
100
|
+
),
|
|
101
|
+
window.__TAURI__.fs.removeFile(
|
|
102
|
+
'tauri-test-copy.txt',
|
|
103
|
+
options
|
|
104
|
+
)
|
|
105
|
+
]).then(function (res) {
|
|
106
|
+
reply({
|
|
107
|
+
cmd: 'removeFile' + commandSuffix
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
} else {
|
|
115
|
+
sendError('expected "' + contents + '" found "' + res + '"')
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
.catch(sendError)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
window.__TAURI__.event.listen('reply', function (res) {
|
|
123
|
+
reply({
|
|
124
|
+
cmd: 'listen'
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
window.onTauriInit = function () {
|
|
128
|
+
window.__TAURI__.event.emit('hello')
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
testFs(null).then(function () {
|
|
132
|
+
testFs(window.__TAURI__.fs.Dir.Config)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
setTimeout(function () {
|
|
136
|
+
window.__TAURI__.invoke('exit')
|
|
137
|
+
}, 15000)
|
|
138
|
+
</script>
|
|
139
|
+
</body>
|
|
140
|
+
</html>
|