Skip to content

Commit

Permalink
feat: rename LICENSE from electron dist to LICENSE.electron.txt
Browse files Browse the repository at this point in the history
Closes #916
  • Loading branch information
develar committed Nov 19, 2016
1 parent 223a6aa commit e05cd17
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 155 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
],
"bin": {
"build": "./out/build-cli.js",
"cleanup": "./out/cleanup.js",
"install-app-deps": "./out/install-app-deps.js",
"node-gyp-rebuild": "./out/node-gyp-rebuild.js"
},
Expand Down Expand Up @@ -102,13 +101,12 @@
"@types/source-map-support": "^0.2.28",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-async-to-module-method": "^6.16.0",
"babel-plugin-transform-es2015-destructuring": "^6.18.0",
"babel-plugin-transform-es2015-destructuring": "^6.19.0",
"babel-plugin-transform-es2015-parameters": "^6.18.0",
"babel-plugin-transform-es2015-spread": "^6.8.0",
"babel-plugin-transform-inline-imports-commonjs": "^1.2.0",
"babel-register": "^6.18.0",
"decompress-zip": "^0.3.0",
"depcheck": "^0.6.4",
"depcheck": "^0.6.5",
"diff": "^3.0.1",
"husky": "^0.11.9",
"jest-cli": "^17.0.3",
Expand Down
59 changes: 0 additions & 59 deletions src/cleanup.ts

This file was deleted.

9 changes: 1 addition & 8 deletions src/packager/dirPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function subOptionWarning (properties: any, optionName: any, parameter: any, val
properties[parameter] = value
}

export async function pack(packager: PlatformPackager<any>, out: string, platform: string, arch: string, electronVersion: string, initializeApp: () => Promise<any>) {
export async function unpackElectron(packager: PlatformPackager<any>, out: string, platform: string, arch: string, electronVersion: string) {
const electronDist = packager.devMetadata.build.electronDist
if (electronDist == null) {
const zipPath = (await BluebirdPromise.all<any>([
Expand All @@ -50,11 +50,4 @@ export async function pack(packager: PlatformPackager<any>, out: string, platfor
chmod(path.join(out, "resources"), "0755")
])
}

if (platform === "darwin" || platform === "mas") {
await(<any>require("./mac")).createApp(packager, out, initializeApp)
}
else {
await initializeApp()
}
}
9 changes: 2 additions & 7 deletions src/packager/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function filterCFBundleIdentifier(identifier: string) {
return identifier.replace(/ /g, "-").replace(/[^a-zA-Z0-9.-]/g, "")
}

export async function createApp(packager: PlatformPackager<any>, appOutDir: string, initializeApp: () => Promise<any>) {
export async function createApp(packager: PlatformPackager<any>, appOutDir: string) {
const appInfo = packager.appInfo
const appFilename = appInfo.productFilename

Expand All @@ -37,12 +37,7 @@ export async function createApp(packager: PlatformPackager<any>, appOutDir: stri
const helperNPPlistFilename = path.join(frameworksPath, "Electron Helper NP.app", "Contents", "Info.plist")

const buildMetadata = packager.devMetadata.build!

const result = await BluebirdPromise.all<any | n>([
initializeApp(),
BluebirdPromise.map([appPlistFilename, helperPlistFilename, helperEHPlistFilename, helperNPPlistFilename, (<any>buildMetadata)["extend-info"]], it => it == null ? it : readFile(it, "utf8"))
])
const fileContents: Array<string> = result[1]!
const fileContents: Array<string> = await BluebirdPromise.map([appPlistFilename, helperPlistFilename, helperEHPlistFilename, helperNPPlistFilename, (<any>buildMetadata)["extend-info"]], it => it == null ? it : readFile(it, "utf8"))
const appPlist = parsePlist(fileContents[0])
const helperPlist = parsePlist(fileContents[1])
const helperEHPlist = parsePlist(fileContents[2])
Expand Down
145 changes: 76 additions & 69 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppMetadata, DevMetadata, Platform, PlatformSpecificBuildOptions, Arch,
import EventEmitter = NodeJS.EventEmitter
import BluebirdPromise from "bluebird-lst-c"
import * as path from "path"
import { readdir, remove } from "fs-extra-p"
import { readdir, remove, rename } from "fs-extra-p"
import { statOrNull, use, unlinkIfExists, isEmptyOrSpaces, asArray, debug } from "./util/util"
import { Packager } from "./packager"
import { AsarOptions } from "asar-electron-builder"
Expand All @@ -11,7 +11,7 @@ import { checkFileInArchive, createAsarArchive } from "./asarUtil"
import { warn, log } from "./util/log"
import { AppInfo } from "./appInfo"
import { copyFiltered } from "./util/filter"
import { pack } from "./packager/dirPackager"
import { unpackElectron } from "./packager/dirPackager"
import { TmpDir } from "./util/tmp"
import { FileMatchOptions, FileMatcher, FilePattern, deprecatedUserIgnoreFilter } from "./fileMatcher"
import { BuildOptions } from "./builder"
Expand Down Expand Up @@ -189,81 +189,89 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
const resourcesPath = this.platform === Platform.MAC ? path.join(appOutDir, "Electron.app", "Contents", "Resources") : path.join(appOutDir, "resources")

log(`Packaging for ${platformName} ${Arch[arch]} using electron ${this.info.electronVersion} to ${path.relative(this.projectDir, appOutDir)}`)
await pack(this, appOutDir, platformName, Arch[arch], this.info.electronVersion, async () => {
const appDir = this.info.appDir
const ignoreFiles = new Set([path.resolve(appDir, outDir), path.resolve(appDir, this.buildResourcesDir)])
// prune dev or not listed dependencies
await dependencies(appDir, true, ignoreFiles)

if (debug.enabled) {
const nodeModulesDir = path.join(appDir, "node_modules")
debug(`Pruned dev or extraneous dependencies: ${Array.from(ignoreFiles).slice(2).map(it => path.relative(nodeModulesDir, it)).join(", ")}`)
}

const patterns = this.getFileMatchers("files", appDir, path.join(resourcesPath, "app"), false, fileMatchOptions, platformSpecificBuildOptions)
let defaultMatcher = patterns == null ? new FileMatcher(appDir, path.join(resourcesPath, "app"), fileMatchOptions) : patterns[0]
if (defaultMatcher.isEmpty()) {
defaultMatcher.addPattern("**/*")
const appDir = this.info.appDir
const ignoreFiles = new Set([path.resolve(appDir, outDir), path.resolve(appDir, this.buildResourcesDir)])
// prune dev or not listed dependencies
await BluebirdPromise.all([
dependencies(appDir, true, ignoreFiles),
unpackElectron(this, appOutDir, platformName, Arch[arch], this.info.electronVersion),
])

if (debug.enabled) {
const nodeModulesDir = path.join(appDir, "node_modules")
debug(`Pruned dev or extraneous dependencies: ${Array.from(ignoreFiles).slice(2).map(it => path.relative(nodeModulesDir, it)).join(", ")}`)
}

const patterns = this.getFileMatchers("files", appDir, path.join(resourcesPath, "app"), false, fileMatchOptions, platformSpecificBuildOptions)
let defaultMatcher = patterns == null ? new FileMatcher(appDir, path.join(resourcesPath, "app"), fileMatchOptions) : patterns[0]
if (defaultMatcher.isEmpty()) {
defaultMatcher.addPattern("**/*")
}
else {
defaultMatcher.addPattern("package.json")
}
defaultMatcher.addPattern("!**/node_modules/*/{CHANGELOG.md,ChangeLog,changelog.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}")
defaultMatcher.addPattern("!**/node_modules/.bin")
defaultMatcher.addPattern("!**/*.{o,hprof,orig,pyc,pyo,rbc,swp}")
defaultMatcher.addPattern("!**/._*")
defaultMatcher.addPattern("!.idea")
defaultMatcher.addPattern("!*.iml")
//noinspection SpellCheckingInspection
defaultMatcher.addPattern("!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes,.editorconfig,.flowconfig,.yarn-metadata.json,.idea,appveyor.yml,.travis.yml,circle.yml,npm-debug.log,.nyc_output,yarn.lock,.yarn-integrity}")

let rawFilter: any = null
const deprecatedIgnore = (<any>this.devMetadata.build).ignore
if (deprecatedIgnore != null) {
if (typeof deprecatedIgnore === "function") {
warn(`"ignore" is specified as function, may be new "files" option will be suit your needs? Please see https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files`)
}
else {
defaultMatcher.addPattern("package.json")
}
defaultMatcher.addPattern("!**/node_modules/*/{CHANGELOG.md,ChangeLog,changelog.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}")
defaultMatcher.addPattern("!**/node_modules/.bin")
defaultMatcher.addPattern("!**/*.{o,hprof,orig,pyc,pyo,rbc,swp}")
defaultMatcher.addPattern("!**/._*")
defaultMatcher.addPattern("!.idea")
defaultMatcher.addPattern("!*.iml")
//noinspection SpellCheckingInspection
defaultMatcher.addPattern("!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes,.editorconfig,.flowconfig,.yarn-metadata.json,.idea,appveyor.yml,.travis.yml,circle.yml,npm-debug.log,.nyc_output,yarn.lock,.yarn-integrity}")

let rawFilter: any = null
const deprecatedIgnore = (<any>this.devMetadata.build).ignore
if (deprecatedIgnore != null) {
if (typeof deprecatedIgnore === "function") {
warn(`"ignore" is specified as function, may be new "files" option will be suit your needs? Please see https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files`)
}
else {
warn(`"ignore" is deprecated, please use "files", see https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files`)
}
rawFilter = deprecatedUserIgnoreFilter(deprecatedIgnore, appDir)
warn(`"ignore" is deprecated, please use "files", see https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files`)
}
rawFilter = deprecatedUserIgnoreFilter(deprecatedIgnore, appDir)
}

let excludePatterns: Array<Minimatch> = []
if (extraResourceMatchers != null) {
for (let i = 0; i < extraResourceMatchers.length; i++) {
const patterns = extraResourceMatchers[i].getParsedPatterns(this.info.projectDir)
excludePatterns = excludePatterns.concat(patterns)
}
let excludePatterns: Array<Minimatch> = []
if (extraResourceMatchers != null) {
for (let i = 0; i < extraResourceMatchers.length; i++) {
const patterns = extraResourceMatchers[i].getParsedPatterns(this.info.projectDir)
excludePatterns = excludePatterns.concat(patterns)
}
if (extraFileMatchers != null) {
for (let i = 0; i < extraFileMatchers.length; i++) {
const patterns = extraFileMatchers[i].getParsedPatterns(this.info.projectDir)
excludePatterns = excludePatterns.concat(patterns)
}
}
if (extraFileMatchers != null) {
for (let i = 0; i < extraFileMatchers.length; i++) {
const patterns = extraFileMatchers[i].getParsedPatterns(this.info.projectDir)
excludePatterns = excludePatterns.concat(patterns)
}
}

const filter = defaultMatcher.createFilter(ignoreFiles, rawFilter, excludePatterns.length ? excludePatterns : null)
let promise
if (asarOptions == null) {
promise = copyFiltered(appDir, path.join(resourcesPath, "app"), filter, this.info.devMetadata.build.dereference || this.platform === Platform.WINDOWS)
}
else {
const unpackPattern = this.getFileMatchers("asarUnpack", appDir, path.join(resourcesPath, "app"), false, fileMatchOptions, platformSpecificBuildOptions)
const fileMatcher = unpackPattern == null ? null : unpackPattern[0]
//noinspection ES6MissingAwait
promise = createAsarArchive(appDir, resourcesPath, asarOptions, filter, fileMatcher == null ? null : fileMatcher.createFilter())
}
const filter = defaultMatcher.createFilter(ignoreFiles, rawFilter, excludePatterns.length ? excludePatterns : null)
let promise
if (asarOptions == null) {
promise = copyFiltered(appDir, path.join(resourcesPath, "app"), filter, this.info.devMetadata.build.dereference || this.platform === Platform.WINDOWS)
}
else {
const unpackPattern = this.getFileMatchers("asarUnpack", appDir, path.join(resourcesPath, "app"), false, fileMatchOptions, platformSpecificBuildOptions)
const fileMatcher = unpackPattern == null ? null : unpackPattern[0]
promise = createAsarArchive(appDir, resourcesPath, asarOptions, filter, fileMatcher == null ? null : fileMatcher.createFilter())
}

const promises = [promise, unlinkIfExists(path.join(resourcesPath, "default_app.asar")), unlinkIfExists(path.join(appOutDir, "version"))]
if (this.info.electronVersion != null && this.info.electronVersion[0] === "0") {
// electron release >= 0.37.4 - the default_app/ folder is a default_app.asar file
promises.push(remove(path.join(resourcesPath, "default_app")))
}
//noinspection ES6MissingAwait
const promises = [promise, unlinkIfExists(path.join(resourcesPath, "default_app.asar")), unlinkIfExists(path.join(appOutDir, "version")), this.postInitApp(appOutDir)]
if (this.platform !== Platform.MAC) {
promises.push(rename(path.join(appOutDir, "LICENSE"), path.join(appOutDir, "LICENSE.electron.txt")) .catch(() => {/* ignore */}))
}
if (this.info.electronVersion != null && this.info.electronVersion[0] === "0") {
// electron release >= 0.37.4 - the default_app/ folder is a default_app.asar file
promises.push(remove(path.join(resourcesPath, "default_app")))
}

promises.push(this.postInitApp(appOutDir))
await BluebirdPromise.all(promises)
})
await BluebirdPromise.all(promises)

if (platformName === "darwin" || platformName === "mas") {
await (<any>require("./packager/mac")).createApp(this, appOutDir)
}

await this.doCopyExtraFiles(extraResourceMatchers)
await this.doCopyExtraFiles(extraFileMatchers)
Expand All @@ -280,8 +288,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
await this.sanityCheckPackage(appOutDir, asarOptions != null)
}

protected postInitApp(executableFile: string): Promise<any> {
return BluebirdPromise.resolve(null)
protected async postInitApp(executableFile: string): Promise<any> {
}

async getIconPath(): Promise<string | null> {
Expand Down
7 changes: 6 additions & 1 deletion src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getBinFromBintray } from "../util/binDownload"
import { v5 as uuid5 } from "uuid-1345"
import { normalizeExt, Target, getPublishConfigs, getResolvedPublishConfig, ArtifactCreated } from "../platformPackager"
import { archive } from "./archive"
import { subTask, log } from "../util/log"
import { subTask, log, warn } from "../util/log"
import { unlink, readFile, writeFile, createReadStream } from "fs-extra-p"
import { SemVer } from "semver"
import { NsisOptions } from "../options/winOptions"
Expand Down Expand Up @@ -35,6 +35,11 @@ export default class NsisTarget extends Target {

constructor(private packager: WinPackager, private outDir: string) {
super("nsis")

const deps = packager.info.metadata.dependencies
if (deps != null && deps["electron-squirrel-startup"] != null) {
warn('"electron-squirrel-startup" dependency is not required for NSIS')
}
}

private computePublishConfigs(): Promise<Array<PublishConfiguration> | null> {
Expand Down
1 change: 0 additions & 1 deletion src/targets/squirrelPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ async function pack(options: SquirrelOptions, directory: string, updateFile: str
<Default Extension="exe" ContentType="application/octet" />
<Default Extension="dat" ContentType="application/octet" />
<Default Extension="psmdcp" ContentType="application/vnd.openxmlformats-package.core-properties+xml" />
<Override PartName="/lib/net45/LICENSE" ContentType="application/octet" />
<Default Extension="diff" ContentType="application/octet" />
<Default Extension="bsdiff" ContentType="application/octet" />
<Default Extension="shasum" ContentType="text/plain" />
Expand Down
3 changes: 2 additions & 1 deletion test/src/helpers/checkDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ const printErrorAndExit = require("../../../out/util/promise").printErrorAndExit

const knownUnusedDevDependencies = new Set([
"@develar/types",
"ava-tf",
"jest-cli",
"decompress-zip",
"diff",
"husky",
"json8",
"path-sort",
"typescript",
"tslint",
"depcheck"
])

Expand Down
6 changes: 3 additions & 3 deletions test/src/helpers/expectedContents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const expectedLinuxContents = ["/",
"/opt/TestApp/icudtl.dat",
"/opt/TestApp/libffmpeg.so",
"/opt/TestApp/libnode.so",
"/opt/TestApp/LICENSE",
"/opt/TestApp/LICENSE.electron.txt",
"/opt/TestApp/LICENSES.chromium.html",
"/opt/TestApp/natives_blob.bin",
"/opt/TestApp/snapshot_blob.bin",
Expand Down Expand Up @@ -67,7 +67,7 @@ export const expectedWinContents = [
"lib/net45/icudtl.dat",
"lib/net45/libEGL.dll",
"lib/net45/libGLESv2.dll",
"lib/net45/LICENSE",
"lib/net45/LICENSE.electron.txt",
"lib/net45/LICENSES.chromium.html",
"lib/net45/natives_blob.bin",
"lib/net45/node.dll",
Expand Down Expand Up @@ -96,7 +96,7 @@ export const nsisPerMachineInstall = pathSorter([
"Program Files/TestApp/1.1.0/icudtl.dat",
"Program Files/TestApp/1.1.0/libEGL.dll",
"Program Files/TestApp/1.1.0/libGLESv2.dll",
"Program Files/TestApp/1.1.0/LICENSE",
"Program Files/TestApp/1.1.0/LICENSE.electron.txt",
"Program Files/TestApp/1.1.0/LICENSES.chromium.html",
"Program Files/TestApp/1.1.0/locales",
"Program Files/TestApp/1.1.0/natives_blob.bin",
Expand Down
Loading

0 comments on commit e05cd17

Please sign in to comment.