Skip to content

Commit

Permalink
feat: add support for building with vue cli (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
nklayman authored Jan 30, 2021
1 parent 2dd3c00 commit f043343
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changes/vue-cli-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"action": minor
---

If vue-cli-plugin-tauri is detected, the tauri:build command will be used.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ jobs:
sudo apt-get update
sudo apt-get install -y webkit2gtk-4.0
- name: install app dependencies and build it
# If using the Vue CLI plugin, tauri:build will be run automatically by tauri-action
# and you can remove `&& yarn build` from this command
run: yarn && yarn build
- uses: tauri-apps/tauri-action@v0
env:
Expand Down Expand Up @@ -149,6 +151,8 @@ jobs:
sudo apt-get update
sudo apt-get install -y webkit2gtk-4.0
- name: install app dependencies and build it
# If using the Vue CLI plugin, tauri:build will be run automatically by tauri-action
# and you can remove `&& yarn build` from this command
run: yarn && yarn build
- uses: tauri-apps/tauri-action@v0
env:
Expand Down
16 changes: 10 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10664,11 +10664,12 @@ function getPackageJson(root) {
}
return null;
}
function hasTauriDependency(root) {
function hasDependency(dependencyName, root) {
const packageJson = getPackageJson(root);
return (packageJson &&
((packageJson.dependencies && packageJson.dependencies.tauri) ||
(packageJson.devDependencies && packageJson.devDependencies.tauri)));
((packageJson.dependencies && packageJson.dependencies[dependencyName]) ||
(packageJson.devDependencies &&
packageJson.devDependencies[dependencyName])));
}
function usesYarn(root) {
return fs_1.existsSync(path_1.join(root, 'yarn.lock'));
Expand All @@ -10687,10 +10688,10 @@ function execCommand(command, { cwd }) {
function buildProject(root, debug, { configPath, distPath, iconPath, npmScript }) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise(resolve => {
if (core.getInput('preferGlobal') === "true") {
if (core.getInput('preferGlobal') === 'true') {
resolve('tauri');
}
else if (hasTauriDependency(root)) {
else if (hasDependency('tauri', root) || hasDependency('vue-cli-plugin-tauri', root)) {
if (npmScript) {
resolve(usesYarn(root) ? `yarn ${npmScript}` : `npm run ${npmScript}`);
}
Expand Down Expand Up @@ -10750,7 +10751,10 @@ function buildProject(root, debug, { configPath, distPath, iconPath, npmScript }
fs_1.writeFileSync(tauriConfPath, JSON.stringify(tauriConf));
}
const args = debug ? ['--debug'] : [];
return execCommand(`${app.runner} build` + (args.length ? ` ${args.join(' ')}` : ''), { cwd: root })
const buildCommand = hasDependency('vue-cli-plugin-tauri', root)
? (usesYarn(root) ? 'yarn' : 'npm run') + ' tauri:build'
: `${app.runner} build`;
return execCommand(buildCommand + (args.length ? ` ${args.join(' ')}` : ''), { cwd: root })
.then(() => {
const appName = app.name;
const artifactsPath = path_1.join(root, `src-tauri/target/${debug ? 'debug' : 'release'}`);
Expand Down
16 changes: 10 additions & 6 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ function getPackageJson(root) {
}
return null;
}
function hasTauriDependency(root) {
function hasDependency(dependencyName, root) {
const packageJson = getPackageJson(root);
return (packageJson &&
((packageJson.dependencies && packageJson.dependencies.tauri) ||
(packageJson.devDependencies && packageJson.devDependencies.tauri)));
((packageJson.dependencies && packageJson.dependencies[dependencyName]) ||
(packageJson.devDependencies &&
packageJson.devDependencies[dependencyName])));
}
function usesYarn(root) {
return fs_1.existsSync(path_1.join(root, 'yarn.lock'));
Expand All @@ -71,10 +72,10 @@ function execCommand(command, { cwd }) {
function buildProject(root, debug, { configPath, distPath, iconPath, npmScript }) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise(resolve => {
if (core.getInput('preferGlobal') === "true") {
if (core.getInput('preferGlobal') === 'true') {
resolve('tauri');
}
else if (hasTauriDependency(root)) {
else if (hasDependency('tauri', root) || hasDependency('vue-cli-plugin-tauri', root)) {
if (npmScript) {
resolve(usesYarn(root) ? `yarn ${npmScript}` : `npm run ${npmScript}`);
}
Expand Down Expand Up @@ -134,7 +135,10 @@ function buildProject(root, debug, { configPath, distPath, iconPath, npmScript }
fs_1.writeFileSync(tauriConfPath, JSON.stringify(tauriConf));
}
const args = debug ? ['--debug'] : [];
return execCommand(`${app.runner} build` + (args.length ? ` ${args.join(' ')}` : ''), { cwd: root })
const buildCommand = hasDependency('vue-cli-plugin-tauri', root)
? (usesYarn(root) ? 'yarn' : 'npm run') + ' tauri:build'
: `${app.runner} build`;
return execCommand(buildCommand + (args.length ? ` ${args.join(' ')}` : ''), { cwd: root })
.then(() => {
const appName = app.name;
const artifactsPath = path_1.join(root, `src-tauri/target/${debug ? 'debug' : 'release'}`);
Expand Down
18 changes: 11 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ function getPackageJson(root: string): any {
return null
}

function hasTauriDependency(root: string): boolean {
function hasDependency(dependencyName: string, root: string): boolean {
const packageJson = getPackageJson(root)
return (
packageJson &&
((packageJson.dependencies && packageJson.dependencies.tauri) ||
(packageJson.devDependencies && packageJson.devDependencies.tauri))
((packageJson.dependencies && packageJson.dependencies[dependencyName]) ||
(packageJson.devDependencies &&
packageJson.devDependencies[dependencyName]))
)
}

Expand Down Expand Up @@ -73,9 +74,9 @@ async function buildProject(
{configPath, distPath, iconPath, npmScript}: BuildOptions
): Promise<string[]> {
return new Promise<string>(resolve => {
if (core.getInput('preferGlobal') === "true") {
if (core.getInput('preferGlobal') === 'true') {
resolve('tauri')
} else if (hasTauriDependency(root)) {
} else if (hasDependency('tauri', root) || hasDependency('vue-cli-plugin-tauri', root)) {
if (npmScript) {
resolve(usesYarn(root) ? `yarn ${npmScript}` : `npm run ${npmScript}`)
} else {
Expand Down Expand Up @@ -145,8 +146,11 @@ async function buildProject(
}

const args = debug ? ['--debug'] : []
const buildCommand = hasDependency('vue-cli-plugin-tauri', root)
? (usesYarn(root) ? 'yarn' : 'npm run') + ' tauri:build'
: `${app.runner} build`
return execCommand(
`${app.runner} build` + (args.length ? ` ${args.join(' ')}` : ''),
buildCommand + (args.length ? ` ${args.join(' ')}` : ''),
{cwd: root}
)
.then(() => {
Expand Down Expand Up @@ -298,4 +302,4 @@ async function run(): Promise<void> {
}
}

run()
run()

0 comments on commit f043343

Please sign in to comment.