Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for building with vue cli #60

Merged
merged 5 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
? (usesYarn(root) ? 'yarn' : 'npm run') + ' tauri:build'
? (npmScript || (usesYarn(root) ? 'yarn' : 'npm run') + ' tauri:build')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah that's not a bad idea. However, the npm script is expected to be used like this: yarn/npm run ${npmScript} build. Is it a bad idea to make it function slightly differently in the case of the vue cli plugin? We would have to update the docs as well. At the very least it should probably still add yarn/npm run automatically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could leave it the way you wrote since this action is mostly for simple apps

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I doubt people will change the script name, if someone needs to and opens and issue we can just add it then. Ready to merge IMO 👍.

: `${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()