Skip to content

Commit

Permalink
feat: LSTypeIsPackage for file associations
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Dec 21, 2016
1 parent 090150c commit dcf3dbb
Show file tree
Hide file tree
Showing 27 changed files with 438 additions and 171 deletions.
3 changes: 2 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ macOS and NSIS only. Array of option objects.
| **name** | <a name="FileAssociation-name"></a>The name. e.g. `PNG`.
| description | <a name="FileAssociation-description"></a>*windows-only.* The description.
| icon | <a name="FileAssociation-icon"></a>The path to icon (`.icns` for MacOS and `.ico` for Windows), relative to `build` (build resources directory). Defaults to `${firstExt}.icns`/`${firstExt}.ico` (if several extensions specified, first is used) or to application icon.
| role | <a name="FileAssociation-role"></a>*macOS-only* The app’s role with respect to the type. The value can be `Editor`, `Viewer`, `Shell`, or `None`. Defaults to `Editor`.
| role | <a name="FileAssociation-role"></a>*macOS-only* The app’s role with respect to the type. The value can be `Editor`, `Viewer`, `Shell`, or `None`. Defaults to `Editor`. Corresponds to `CFBundleTypeRole`.
| isPackage | <a name="FileAssociation-isPackage"></a>*macOS-only* Whether the document is distributed as a bundle. If set to true, the bundle directory is treated as a file. Corresponds to `LSTypeIsPackage`.

<a name="LinuxBuildOptions"></a>
### `.build.linux`
Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"chromium-pickle-js": "^0.2.0",
"cli-cursor": "^1.0.2",
"cuint": "^0.2.2",
"debug": "2.4.5",
"debug": "2.5.1",
"electron-download-tf": "3.1.0",
"electron-macos-sign": "^1.3.4",
"fs-extra-p": "^3.0.3",
Expand Down Expand Up @@ -97,10 +97,10 @@
},
"devDependencies": {
"@develar/semantic-release": "^6.3.26",
"@types/electron": "^1.4.29",
"@types/electron": "^1.4.30",
"@types/ini": "^1.3.29",
"@types/jest": "^16.0.1",
"@types/js-yaml": "^3.5.28",
"@types/jest": "^16.0.2",
"@types/js-yaml": "^3.5.29",
"@types/source-map-support": "^0.2.28",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-async-to-module-method": "^6.16.0",
Expand All @@ -110,10 +110,8 @@
"babel-plugin-transform-inline-imports-commonjs": "^1.2.0",
"decompress-zip": "^0.3.0",
"depcheck": "^0.6.7",
"diff": "^3.1.0",
"jest-cli": "^18.0.0",
"jest-environment-node-debug": "^0.0.2",
"json8": "^0.9.2",
"path-sort": "^0.1.0",
"ts-babel": "^1.2.2",
"tslint": "^4.1.1",
Expand Down
7 changes: 6 additions & 1 deletion src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,14 @@ export interface FileAssociation {
readonly icon?: string

/*
*macOS-only* The app’s role with respect to the type. The value can be `Editor`, `Viewer`, `Shell`, or `None`. Defaults to `Editor`.
*macOS-only* The app’s role with respect to the type. The value can be `Editor`, `Viewer`, `Shell`, or `None`. Defaults to `Editor`. Corresponds to `CFBundleTypeRole`.
*/
readonly role?: string

/*
*macOS-only* Whether the document is distributed as a bundle. If set to true, the bundle directory is treated as a file. Corresponds to `LSTypeIsPackage`.
*/
readonly isPackage?: boolean
}

/*
Expand Down
8 changes: 6 additions & 2 deletions src/packager/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ export async function createApp(packager: PlatformPackager<any>, appOutDir: stri
await copyFile(customIcon, path.join(resourcesPath, iconFile))
}

// todo rename electron.icns
return <any>{
const result = <any>{
CFBundleTypeExtensions: extensions,
CFBundleTypeName: fileAssociation.name,
CFBundleTypeRole: fileAssociation.role || "Editor",
CFBundleTypeIconFile: iconFile
}

if (fileAssociation.isPackage) {
result.LSTypeIsPackage = true
}
return result
})
}

Expand Down
205 changes: 205 additions & 0 deletions test/out/__snapshots__/BuildTest.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
exports[`test cli 1`] = `
Object {
"draft": undefined,
"extraMetadata": undefined,
"prerelease": undefined,
"publish": undefined,
"targets": Map {
Platform {
"buildConfigurationKey": "mac",
"name": "mac",
"nodeName": "darwin",
} => Map {
1 => Array [],
},
},
}
`;

exports[`test cli 2`] = `
Object {
"draft": undefined,
"extraMetadata": undefined,
"prerelease": undefined,
"publish": undefined,
"targets": Map {
Platform {
"buildConfigurationKey": "mac",
"name": "mac",
"nodeName": "darwin",
} => Map {
1 => Array [
"dir",
],
},
},
}
`;

exports[`test cli 3`] = `
Object {
"draft": undefined,
"extraMetadata": undefined,
"prerelease": undefined,
"publish": undefined,
"targets": Map {
Platform {
"buildConfigurationKey": "linux",
"name": "linux",
"nodeName": "linux",
} => Map {
1 => Array [
"dir",
],
},
},
}
`;

exports[`test cli 4`] = `
Object {
"draft": undefined,
"extraMetadata": undefined,
"prerelease": undefined,
"publish": undefined,
"targets": Map {
Platform {
"buildConfigurationKey": "linux",
"name": "linux",
"nodeName": "linux",
} => Map {
1 => Array [],
},
},
}
`;

exports[`test cli 5`] = `
Object {
"draft": undefined,
"extraMetadata": undefined,
"prerelease": undefined,
"publish": undefined,
"targets": Map {
Platform {
"buildConfigurationKey": "win",
"name": "windows",
"nodeName": "win32",
} => Map {
1 => Array [],
},
},
}
`;

exports[`test cli 6`] = `
Object {
"draft": undefined,
"extraMetadata": undefined,
"prerelease": undefined,
"publish": undefined,
"targets": Map {
Platform {
"buildConfigurationKey": "mac",
"name": "mac",
"nodeName": "darwin",
} => Map {
1 => Array [],
},
Platform {
"buildConfigurationKey": "linux",
"name": "linux",
"nodeName": "linux",
} => Map {
1 => Array [],
},
Platform {
"buildConfigurationKey": "win",
"name": "windows",
"nodeName": "win32",
} => Map {
1 => Array [],
},
},
}
`;

exports[`test cli 7`] = `
Object {
"draft": undefined,
"extraMetadata": undefined,
"prerelease": undefined,
"publish": undefined,
"targets": Map {
Platform {
"buildConfigurationKey": "linux",
"name": "linux",
"nodeName": "linux",
} => Map {
0 => Array [
"tar.gz",
],
},
},
}
`;

exports[`test cli 8`] = `
Object {
"draft": undefined,
"extraMetadata": undefined,
"prerelease": undefined,
"publish": undefined,
"targets": Map {
Platform {
"buildConfigurationKey": "linux",
"name": "linux",
"nodeName": "linux",
} => Map {
1 => Array [
"tar.gz",
],
},
},
}
`;

exports[`test cli 9`] = `
Object {
"draft": undefined,
"extraMetadata": undefined,
"prerelease": undefined,
"publish": undefined,
"targets": Map {
Platform {
"buildConfigurationKey": "linux",
"name": "linux",
"nodeName": "linux",
} => Map {
1 => Array [
"tar.gz",
],
},
},
}
`;

exports[`test cli 10`] = `
Object {
"draft": undefined,
"extraMetadata": undefined,
"prerelease": undefined,
"publish": undefined,
"targets": Map {
Platform {
"buildConfigurationKey": "win",
"name": "windows",
"nodeName": "win32",
} => Map {
1 => Array [
"tar.gz",
],
},
},
}
`;
65 changes: 65 additions & 0 deletions test/out/__snapshots__/RepoSlugTest.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
exports[`test repo slug from APPVEYOR 1`] = `
Object {
"auth": null,
"browsetemplate": "https://{domain}/{user}/{project}{/tree/committish}",
"bugstemplate": "https://{domain}/{user}/{project}/issues",
"committish": null,
"default": "shortcut",
"docstemplate": "https://{domain}/{user}/{project}{/tree/committish}#readme",
"domain": "github.com",
"filetemplate": "https://{auth@}raw.githubusercontent.com/{user}/{project}/{committish}/{path}",
"gittemplate": "git://{auth@}{domain}/{user}/{project}.git{#committish}",
"httpstemplate": "git+https://{auth@}{domain}/{user}/{project}.git{#committish}",
"pathmatch": /^[\\/]([^\\/]+)[\\/]([^\\/]+?)(?:[.]git)?$/,
"pathtemplate": "{user}/{project}{#committish}",
"project": "travis-build",
"protocols": Array [
"git",
"http",
"git+ssh",
"git+https",
"ssh",
"https",
],
"protocols_re": /^(git|http|git\\+ssh|git\\+https|ssh|https):$/,
"shortcuttemplate": "{type}:{user}/{project}{#committish}",
"sshtemplate": "git@{domain}:{user}/{project}.git{#committish}",
"sshurltemplate": "git+ssh://git@{domain}/{user}/{project}.git{#committish}",
"treepath": "tree",
"type": "github",
"user": "travis-ci",
}
`;

exports[`test repo slug from TRAVIS_REPO_SLUG 1`] = `
Object {
"auth": null,
"browsetemplate": "https://{domain}/{user}/{project}{/tree/committish}",
"bugstemplate": "https://{domain}/{user}/{project}/issues",
"committish": null,
"default": "shortcut",
"docstemplate": "https://{domain}/{user}/{project}{/tree/committish}#readme",
"domain": "github.com",
"filetemplate": "https://{auth@}raw.githubusercontent.com/{user}/{project}/{committish}/{path}",
"gittemplate": "git://{auth@}{domain}/{user}/{project}.git{#committish}",
"httpstemplate": "git+https://{auth@}{domain}/{user}/{project}.git{#committish}",
"pathmatch": /^[\\/]([^\\/]+)[\\/]([^\\/]+?)(?:[.]git)?$/,
"pathtemplate": "{user}/{project}{#committish}",
"project": "travis-build",
"protocols": Array [
"git",
"http",
"git+ssh",
"git+https",
"ssh",
"https",
],
"protocols_re": /^(git|http|git\\+ssh|git\\+https|ssh|https):$/,
"shortcuttemplate": "{type}:{user}/{project}{#committish}",
"sshtemplate": "git@{domain}:{user}/{project}.git{#committish}",
"sshurltemplate": "git+ssh://git@{domain}/{user}/{project}.git{#committish}",
"treepath": "tree",
"type": "github",
"user": "travis-ci",
}
`;
30 changes: 30 additions & 0 deletions test/out/__snapshots__/extraMetadataTest.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
exports[`test extra metadata 1`] = `
Object {
"author": "Foo Bar <[email protected]>",
"build": Object {
"appId": "org.electron-builder.testApp",
"compression": "store",
"electronVersion": "1.4.12",
"iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico",
"linux": Object {
"category": "Development",
"packageCategory": "devel",
},
"mac": Object {
"category": "your.app.category.type",
},
"npmRebuild": false,
},
"description": "Test Application (test quite \" #378)",
"foo": Object {
"bar": 12,
"existingProp": 22,
},
"homepage": "http://foo.example.com",
"license": "MIT",
"name": "TestApp",
"private": true,
"productName": "Test App ß/W",
"version": "1.1.0",
}
`;
5 changes: 5 additions & 0 deletions test/out/__snapshots__/globTest.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports[`test link 1`] = `
Object {
"link": "index.js",
}
`;
Loading

0 comments on commit dcf3dbb

Please sign in to comment.