Skip to content

Commit

Permalink
feat(linux): use ${macro} syntax for linux templates
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jan 2, 2017
1 parent b6ae449 commit fe137fc
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 106 deletions.
4 changes: 3 additions & 1 deletion docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ FROM buildpack-deps:yakkety-curl
# install modern multi-thread xz
# ldconfig - see 4.6. liblzma.so (or similar) not found when running xz

# python for node-gyp

ENV XZ_VERSION 5.2.2

# we don't use our bundled 7za because it is better to build for specific platform - not generic
Expand All @@ -18,7 +20,7 @@ ENV FORCE_COLOR true
ENV DEBIAN_FRONTEND noninteractive

RUN curl -L https://yarnpkg.com/latest.tar.gz | tar xvz && mv dist yarn && apt-get update -y && apt-get upgrade -y && \
apt-get install --no-install-recommends -y xvfb git snapcraft qtbase5-dev xorriso bsdtar build-essential autoconf libssl-dev icnsutils libopenjp2-7 graphicsmagick gcc-multilib g++-multilib libgnome-keyring-dev lzip rpm yasm && \
apt-get install --no-install-recommends -y xvfb git snapcraft qtbase5-dev xorriso bsdtar build-essential autoconf libssl-dev icnsutils libopenjp2-7 graphicsmagick gcc-multilib g++-multilib libgnome-keyring-dev lzip rpm yasm python && \
curl -O http://mirrors.kernel.org/ubuntu/pool/universe/libi/libicns/libicns1_0.8.1-3.1_amd64.deb && dpkg --install libicns1_0.8.1-3.1_amd64.deb && unlink libicns1_0.8.1-3.1_amd64.deb && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \
apt-get update && apt-get install -y google-chrome-stable && \
Expand Down
2 changes: 2 additions & 0 deletions docs/Docker.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
To build Linux or Windows (only if you don't have native dependencies) on any platform:

1. Run docker container:

```sh
docker run --rm -ti -v ${PWD}:/project -v ${PWD##*/}-node-modules:/project/node_modules -v ~/.electron:/root/.electron electronuserland/electron-builder:wine
```

2. Type in `npm install && npm prune && npm run dist`

If you don't have `dist` npm script in your `package.json`, call `./node_modules/.bin/build` directly.
Expand Down
49 changes: 5 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
{
"name": "electron-builder",
"description": "A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out of the box",
"version": "0.0.0-semantic-release",
"main": "out/index.js",
"files": [
"out",
"templates",
"certs/root_certs.keychain"
],
"bin": {
"build": "./out/cli/build-cli.js",
"install-app-deps": "./out/cli/install-app-deps.js",
"node-gyp-rebuild": "./out/cli/node-gyp-rebuild.js"
},
"private": true,
"license": "MIT",
"scripts": {
"compile": "ts-babel packages/electron-builder-http packages/electron-builder packages/electron-auto-updater test",
"lint": "node ./packages/lint.js",
"pretest": "node ./test/vendor/yarn.js run compile && node ./test/vendor/yarn.js run lint",
"pretest": "node ./test/vendor/yarn.js compile && node ./test/vendor/yarn.js lint && node ./test/vendor/yarn.js check-deps",
"check-deps": "node ./test/out/helpers/checkDeps.js",
"test": "node ./test/out/helpers/runTests.js",
"test-linux": "docker run --rm -ti -v ${PWD}:/project -v ${PWD##*/}-node-modules:/project/node_modules -v ~/.electron:/root/.electron electronuserland/electron-builder:wine /test.sh",
Expand All @@ -26,36 +14,9 @@
"whitespace": "whitespace 'src/**/*.ts'",
"docker-images": "docker/build.sh",
"test-deps-mac": "brew install rpm dpkg mono lzip gnu-tar graphicsmagick xz && brew install wine --without-x11",
"postinstall": "lerna bootstrap"
"postinstall": "lerna bootstrap",
"update-deps": "lerna exec -- npm-check-updates --reject 'electron-builder-http'"
},
"repository": "electron-userland/electron-builder",
"engines": {
"node": ">=0.4.0"
},
"keywords": [
"electron",
"builder",
"build",
"installer",
"install",
"packager",
"pack",
"nsis",
"app",
"dmg",
"msi",
"exe",
"setup",
"Windows",
"OS X",
"MacOS",
"Mac",
"appx"
],
"author": "Stefan Judis",
"license": "MIT",
"bugs": "https://github.com/electron-userland/electron-builder/issues",
"homepage": "https://github.com/electron-userland/electron-builder",
"devDependencies": {
"@develar/semantic-release": "^6.3.26",
"@types/electron": "^1.4.30",
Expand Down
16 changes: 2 additions & 14 deletions packages/electron-auto-updater/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"module": "es2015",
"target": "es2017",
"noImplicitAny": true,
"outDir": "out",
"newLine": "LF",
"noEmitOnError": true,
"inlineSources": true,
"sourceMap": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"noEmitHelpers": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"skipLibCheck": true
"outDir": "out"
},
"declaration": {
"electron-auto-updater": "out/electron-auto-updater.d.ts"
Expand Down
16 changes: 2 additions & 14 deletions packages/electron-builder-http/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"module": "es2015",
"target": "es2017",
"noImplicitAny": true,
"outDir": "out",
"newLine": "LF",
"noEmitOnError": true,
"inlineSources": true,
"sourceMap": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"noEmitHelpers": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"skipLibCheck": true
"outDir": "out"
},
"declaration": {
"electron-builder-http": "out/electron-builder-http.d.ts"
Expand Down
6 changes: 2 additions & 4 deletions packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@
"chromium-pickle-js": "^0.2.0",
"cli-cursor": "^1.0.2",
"cuint": "^0.2.2",
"debug": "2.5.2",
"debug": "2.6.0",
"electron-download-tf": "3.1.0",
"electron-macos-sign": "~1.4.0",
"fs-extra-p": "^3.0.3",
"hosted-git-info": "^2.1.5",
"ini": "^1.3.4",
"interactive": "^0.1.9",
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.1",
"js-yaml": "^3.7.0",
"lodash.template": "^4.4.0",
"mime": "^1.3.4",
"minimatch": "^3.0.3",
"node-emoji": "^1.4.3",
Expand All @@ -80,7 +78,7 @@
"tunnel-agent": "^0.4.3",
"update-notifier": "^1.0.3",
"uuid-1345": "^0.99.6",
"yargs": "^6.5.0",
"yargs": "^6.6.0",
"electron-builder-http": "0.0.0-semantic-release"
},
"typings": "./out/electron-builder.d.ts",
Expand Down
24 changes: 16 additions & 8 deletions packages/electron-builder/src/targets/fpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import { LinuxTargetHelper, installPrefix } from "./LinuxTargetHelper"
import * as errorMessages from "../errorMessages"
import { TmpDir } from "../util/tmp"
import { LinuxPackager } from "../linuxPackager"
import { log } from "../util/log"
import { log, warn } from "../util/log"
import { Target } from "./targetFactory"
import { unlinkIfExists } from "../util/fs"

const template = require("lodash.template")

const fpmPath = (process.platform === "win32" || process.env.USE_SYSTEM_FPM === "true") ?
BluebirdPromise.resolve("fpm") : downloadFpm()

Expand Down Expand Up @@ -172,11 +170,21 @@ export default class FpmTarget extends Target {
}

async function writeConfigFile(tmpDir: TmpDir, templatePath: string, options: any): Promise<string> {
const config = template(await readFile(templatePath, "utf8"),
{
// set interpolate explicitly to avoid troubles with templating of installer.nsi.tpl
interpolate: /<%=([\s\S]+?)%>/g
})(options)
//noinspection JSUnusedLocalSymbols
function replacer(match: string, p1: string) {
if (p1 in options) {
return options[p1]
}
else {
throw new Error(`Macro ${p1} is not defined`)
}
}
const config = (await readFile(templatePath, "utf8"))
.replace(/\$\{([a-zA-Z]+)\}/g, replacer)
.replace(/<%=([a-zA-Z]+)%>/g, (match, p1) => {
warn("<%= varName %> is deprecated, please use ${varName} instead")
return replacer(match, p1.trim())
})

const outputPath = await tmpDir.getTempFile(path.basename(templatePath, ".tpl"))
await outputFile(outputPath, config)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

# Link to the binary
ln -sf '/opt/<%= productFilename %>/<%= executable %>' '/usr/local/bin/<%= executable %>'
ln -sf '/opt/${productFilename}/${executable}' '/usr/local/bin/${executable}'
2 changes: 1 addition & 1 deletion packages/electron-builder/templates/linux/after-remove.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

# Delete the link to the binary
rm -f '/usr/local/bin/<%= executable %>'
rm -f '/usr/local/bin/${executable}'
17 changes: 2 additions & 15 deletions packages/electron-builder/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"module": "es2015",
"target": "es2017",
"noImplicitAny": true,
"outDir": "out",
"newLine": "LF",
"noEmitOnError": true,
"inlineSources": true,
"sourceMap": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"noEmitHelpers": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"skipLibCheck": true
"outDir": "out"
},
"declaration": {
"electron-builder": "out/electron-builder.d.ts"
},
"docs": "../../docs/Options.md",
"files": [
"node_modules/fs-extra-p/index.d.ts",
"node_modules/bluebird-lst-c/index.d.ts",
Expand Down
17 changes: 17 additions & 0 deletions packages/tsconfig-base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "es2015",
"target": "es2017",
"noImplicitAny": true,
"newLine": "LF",
"noEmitOnError": true,
"inlineSources": true,
"sourceMap": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"noEmitHelpers": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"skipLibCheck": true
}
}
14 changes: 10 additions & 4 deletions test/src/helpers/checkDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { readJson } from "fs-extra-p"
import BluebirdPromise from "bluebird-lst-c"
import depCheck, { DepCheckResult } from "depcheck"

const printErrorAndExit = require("../../../out/util/promise").printErrorAndExit
const printErrorAndExit = require("../../../packages/electron-builder/out/util/promise").printErrorAndExit

const knownUnusedDevDependencies = new Set([
"@develar/types",
Expand All @@ -17,14 +17,15 @@ const knownUnusedDevDependencies = new Set([
])

async function main(): Promise<void> {
const projectDir = path.join(__dirname, "..", "..", "..")
const rootDir = path.join(__dirname, "../../..")
const projectDir = path.join(rootDir, "packages/electron-builder")

console.log(`Checking ${projectDir}`)

const result = await new BluebirdPromise<DepCheckResult>(function (resolve) {
depCheck(projectDir, {
ignoreDirs: [
"out", "test", "docs", "typings", "docker", "certs", "templates", ".idea", ".github",
"out", "test", "docs", "typings", "docker", "certs", "templates", "vendor",
],
}, resolve)
})
Expand All @@ -43,7 +44,12 @@ async function main(): Promise<void> {
}

const packageData = await readJson(path.join(projectDir, "package.json"))
for (const name of Object.keys(packageData.devDependencies)) {
const devPackageData = await readJson(path.join(rootDir, "package.json"))
for (const name of Object.keys(devPackageData.devDependencies)) {
if (packageData.dependencies[name] != null) {
continue
}

const usages = result.using[name]
if (usages == null || usages.length === 0) {
continue
Expand Down

0 comments on commit fe137fc

Please sign in to comment.