Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
Add skip_build and use_vue_cli options (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
rathboma authored Apr 15, 2020
1 parent 96cd875 commit b5b43b0
Show file tree
Hide file tree
Showing 17 changed files with 379 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
package_manager: [npm, yarn]
package_root: ["./test/app-in-root/", "./test/app-in-subdirectory/"]
package_root: ["./test/app-in-root/", "./test/app-in-subdirectory/", "./test/vue-app"]

steps:
- name: Check out Git repository
Expand All @@ -34,3 +34,4 @@ jobs:
with:
github_token: ${{ secrets.github_token }}
package_root: ${{ matrix.package_root }}
use_vue_cli: ${{ contains(matrix.package_root, 'vue')}}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
test/**/package-lock.json
test/**/yarn.lock
test/**/dist_electron
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ You can configure the action further with the following options:

- `package_root`: Directory where NPM/Yarn commands should be run (default: `"."`)
- `build_script_name`: Name of the optional NPM build script which is executed before `electron-builder` (default: `"build"`)
- `use_vue_cli`: Whether to run `electron-builder` using the [Vue CLI plugin](https://nklayman.github.io/vue-cli-plugin-electron-builder) instead of calling the command directly

See [`action.yml`](./action.yml) for a list of all possible input variables.

Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ inputs:
description: Name of the optional NPM build script which is executed before `electron-builder`
required: false
default: build
skip_build:
description: Whether the action should execute the NPM build script before running `electron-builder`
required: false
default: false
use_vue_cli:
description: Whether to run `electron-builder` using the Vue CLI plugin instead of calling the command directly
required: false
default: false

# Deprecated
app_root:
Expand Down
25 changes: 16 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const runAction = () => {
const release = getInput("release", true) === "true";
const pkgRoot = getInput("package_root", true);
const buildScriptName = getInput("build_script_name", true);
const skipBuild = getInput("skip_build") === "true";
const useVueCli = getInput("use_vue_cli") === "true";

// TODO: Deprecated option, remove in v2.0. `electron-builder` always requires a `package.json` in
// the same directory as the Electron app, so the `package_root` option should be used instead
Expand Down Expand Up @@ -105,21 +107,26 @@ const runAction = () => {
run(useNpm ? "npm install" : "yarn", pkgRoot);

// Run NPM build script if it exists
log("Running the build script…");
if (useNpm) {
run(`npm run ${buildScriptName} --if-present`, pkgRoot);
if (skipBuild) {
log("Skipping build script because `skip_build` option is set");
} else {
// TODO: Use `yarn run ${buildScriptName} --if-present` once supported
// https://github.com/yarnpkg/yarn/issues/6894
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf8"));
if (pkgJson.scripts && pkgJson.scripts[buildScriptName]) {
run(`yarn run ${buildScriptName}`, pkgRoot);
log("Running the build script…");
if (useNpm) {
run(`npm run ${buildScriptName} --if-present`, pkgRoot);
} else {
// TODO: Use `yarn run ${buildScriptName} --if-present` once supported
// https://github.com/yarnpkg/yarn/issues/6894
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf8"));
if (pkgJson.scripts && pkgJson.scripts[buildScriptName]) {
run(`yarn run ${buildScriptName}`, pkgRoot);
}
}
}

log(`Building${release ? " and releasing" : ""} the Electron app…`);
const cmd = useVueCli ? "vue-cli-service electron:build" : "electron-builder";
run(
`${useNpm ? "npx --no-install" : "yarn run"} electron-builder --${platform} ${
`${useNpm ? "npx --no-install" : "yarn run"} ${cmd} --${platform} ${
release ? "--publish always" : ""
}`,
appRoot,
Expand Down
24 changes: 24 additions & 0 deletions test/vue-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.DS_Store
node_modules
/dist

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

#Electron-builder output
/dist_electron
29 changes: 29 additions & 0 deletions test/vue-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# vue-app

## Project setup

```
yarn install
```

### Compiles and hot-reloads for development

```
yarn serve
```

### Compiles and minifies for production

```
yarn build
```

### Lints and fixes files

```
yarn lint
```

### Customize configuration

See [Configuration Reference](https://cli.vuejs.org/config/).
3 changes: 3 additions & 0 deletions test/vue-app/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ["@vue/cli-plugin-babel/preset"],
};
54 changes: 54 additions & 0 deletions test/vue-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "vue-app",
"version": "0.1.0",
"author": {
"email": "matthew@rathbonelabs.com",
"url": "https://github.com/samuelmeuli/action-electron-builder"
},
"repository": "https://github.com/samuelmeuli/action-electron-builder",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"main": "background.js",
"dependencies": {
"core-js": "^3.6.4",
"vue": "^2.6.11"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.3.0",
"@vue/cli-plugin-eslint": "~4.3.0",
"@vue/cli-service": "~4.3.0",
"babel-eslint": "^10.1.0",
"electron": "^6.0.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-cli-plugin-electron-builder": "^2.0.0-beta.6",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
Binary file added test/vue-app/public/favicon.ico
Binary file not shown.
20 changes: 20 additions & 0 deletions test/vue-app/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong
>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without
JavaScript enabled. Please enable it to continue.</strong
>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
28 changes: 28 additions & 0 deletions test/vue-app/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png" />
<HelloWorld msg="Welcome to Your Vue.js App" />
</div>
</template>

<script>
import HelloWorld from "./components/HelloWorld.vue";
export default {
name: "App",
components: {
HelloWorld,
},
};
</script>

<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
Binary file added test/vue-app/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 94 additions & 0 deletions test/vue-app/src/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"use strict";

import { app, protocol, BrowserWindow } from "electron";
import {
createProtocol,
/* installVueDevtools */
} from "vue-cli-plugin-electron-builder/lib";
const isDevelopment = process.env.NODE_ENV !== "production";

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;

// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true } },
]);

function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
});

if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL);
if (!process.env.IS_TEST) win.webContents.openDevTools();
} else {
createProtocol("app");
// Load the index.html when not in development
win.loadURL("app://./index.html");
}

win.on("closed", () => {
win = null;
});
}

// Quit when all windows are closed.
app.on("window-all-closed", () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== "darwin") {
app.quit();
}
});

app.on("activate", () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow();
}
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on("ready", async () => {
if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools
// Devtools extensions are broken in Electron 6.0.0 and greater
// See https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/378 for more info
// Electron will not launch with Devtools extensions installed on Windows 10 with dark mode
// If you are not using Windows 10 dark mode, you may uncomment these lines
// In addition, if the linked issue is closed, you can upgrade electron and uncomment these lines
// try {
// await installVueDevtools()
// } catch (e) {
// console.error('Vue Devtools failed to install:', e.toString())
// }
}
createWindow();
});

// Exit cleanly on request from parent process in development mode.
if (isDevelopment) {
if (process.platform === "win32") {
process.on("message", data => {
if (data === "graceful-exit") {
app.quit();
}
});
} else {
process.on("SIGTERM", () => {
app.quit();
});
}
}
Loading

0 comments on commit b5b43b0

Please sign in to comment.