|
2 | 2 | * Copyright (c) Microsoft Corporation. All rights reserved. |
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | | - |
6 | 5 | 'use strict'; |
7 | | - |
8 | | -const fs = require('fs'); |
9 | | -const path = require('path'); |
| 6 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 7 | +const fs = require("fs"); |
| 8 | +const path = require("path"); |
| 9 | +const vfs = require("vinyl-fs"); |
| 10 | +const filter = require("gulp-filter"); |
| 11 | +const json = require("gulp-json-editor"); |
| 12 | +const _ = require("underscore"); |
| 13 | +const util = require("./util"); |
| 14 | +const electron = require('gulp-atom-electron'); |
10 | 15 | const root = path.dirname(path.dirname(__dirname)); |
11 | | - |
| 16 | +const product = JSON.parse(fs.readFileSync(path.join(root, 'product.json'), 'utf8')); |
| 17 | +const commit = util.getVersion(root); |
12 | 18 | function getElectronVersion() { |
13 | | - const yarnrc = fs.readFileSync(path.join(root, '.yarnrc'), 'utf8'); |
14 | | - // @ts-ignore |
15 | | - const target = /^target "(.*)"$/m.exec(yarnrc)[1]; |
16 | | - |
17 | | - return target; |
| 19 | + const yarnrc = fs.readFileSync(path.join(root, '.yarnrc'), 'utf8'); |
| 20 | + const target = /^target "(.*)"$/m.exec(yarnrc)[1]; |
| 21 | + return target; |
| 22 | +} |
| 23 | +exports.getElectronVersion = getElectronVersion; |
| 24 | +const darwinCreditsTemplate = product.darwinCredits && _.template(fs.readFileSync(path.join(root, product.darwinCredits), 'utf8')); |
| 25 | +function darwinBundleDocumentType(extensions, icon) { |
| 26 | + return { |
| 27 | + name: product.nameLong + ' document', |
| 28 | + role: 'Editor', |
| 29 | + ostypes: ["TEXT", "utxt", "TUTX", "****"], |
| 30 | + extensions: extensions, |
| 31 | + iconFile: icon |
| 32 | + }; |
| 33 | +} |
| 34 | +exports.config = { |
| 35 | + version: getElectronVersion(), |
| 36 | + productAppName: product.nameLong, |
| 37 | + companyName: 'Microsoft Corporation', |
| 38 | + copyright: 'Copyright (C) 2019 Microsoft. All rights reserved', |
| 39 | + darwinIcon: 'resources/darwin/code.icns', |
| 40 | + darwinBundleIdentifier: product.darwinBundleIdentifier, |
| 41 | + darwinApplicationCategoryType: 'public.app-category.developer-tools', |
| 42 | + darwinHelpBookFolder: 'VS Code HelpBook', |
| 43 | + darwinHelpBookName: 'VS Code HelpBook', |
| 44 | + darwinBundleDocumentTypes: [ |
| 45 | + darwinBundleDocumentType(["bat", "cmd"], 'resources/darwin/bat.icns'), |
| 46 | + darwinBundleDocumentType(["bowerrc"], 'resources/darwin/bower.icns'), |
| 47 | + darwinBundleDocumentType(["c", "h"], 'resources/darwin/c.icns'), |
| 48 | + darwinBundleDocumentType(["config", "editorconfig", "gitattributes", "gitconfig", "gitignore", "ini"], 'resources/darwin/config.icns'), |
| 49 | + darwinBundleDocumentType(["cc", "cpp", "cxx", "hh", "hpp", "hxx"], 'resources/darwin/cpp.icns'), |
| 50 | + darwinBundleDocumentType(["cs", "csx"], 'resources/darwin/csharp.icns'), |
| 51 | + darwinBundleDocumentType(["css"], 'resources/darwin/css.icns'), |
| 52 | + darwinBundleDocumentType(["go"], 'resources/darwin/go.icns'), |
| 53 | + darwinBundleDocumentType(["asp", "aspx", "cshtml", "htm", "html", "jshtm", "jsp", "phtml", "shtml"], 'resources/darwin/html.icns'), |
| 54 | + darwinBundleDocumentType(["jade"], 'resources/darwin/jade.icns'), |
| 55 | + darwinBundleDocumentType(["jav", "java"], 'resources/darwin/java.icns'), |
| 56 | + darwinBundleDocumentType(["js", "jscsrc", "jshintrc", "mjs"], 'resources/darwin/javascript.icns'), |
| 57 | + darwinBundleDocumentType(["json"], 'resources/darwin/json.icns'), |
| 58 | + darwinBundleDocumentType(["less"], 'resources/darwin/less.icns'), |
| 59 | + darwinBundleDocumentType(["markdown", "md", "mdoc", "mdown", "mdtext", "mdtxt", "mdwn", "mkd", "mkdn"], 'resources/darwin/markdown.icns'), |
| 60 | + darwinBundleDocumentType(["php"], 'resources/darwin/php.icns'), |
| 61 | + darwinBundleDocumentType(["ps1", "psd1", "psm1"], 'resources/darwin/powershell.icns'), |
| 62 | + darwinBundleDocumentType(["py"], 'resources/darwin/python.icns'), |
| 63 | + darwinBundleDocumentType(["gemspec", "rb"], 'resources/darwin/ruby.icns'), |
| 64 | + darwinBundleDocumentType(["scss"], 'resources/darwin/sass.icns'), |
| 65 | + darwinBundleDocumentType(["bash", "bash_login", "bash_logout", "bash_profile", "bashrc", "profile", "rhistory", "rprofile", "sh", "zlogin", "zlogout", "zprofile", "zsh", "zshenv", "zshrc"], 'resources/darwin/shell.icns'), |
| 66 | + darwinBundleDocumentType(["sql"], 'resources/darwin/sql.icns'), |
| 67 | + darwinBundleDocumentType(["ts"], 'resources/darwin/typescript.icns'), |
| 68 | + darwinBundleDocumentType(["tsx", "jsx"], 'resources/darwin/react.icns'), |
| 69 | + darwinBundleDocumentType(["vue"], 'resources/darwin/vue.icns'), |
| 70 | + darwinBundleDocumentType(["ascx", "csproj", "dtd", "wxi", "wxl", "wxs", "xml", "xaml"], 'resources/darwin/xml.icns'), |
| 71 | + darwinBundleDocumentType(["eyaml", "eyml", "yaml", "yml"], 'resources/darwin/yaml.icns'), |
| 72 | + darwinBundleDocumentType(["clj", "cljs", "cljx", "clojure", "code-workspace", "coffee", "ctp", "dockerfile", "dot", "edn", "fs", "fsi", "fsscript", "fsx", "handlebars", "hbs", "lua", "m", "makefile", "ml", "mli", "pl", "pl6", "pm", "pm6", "pod", "pp", "properties", "psgi", "pug", "r", "rs", "rt", "svg", "svgz", "t", "txt", "vb", "xcodeproj", "xcworkspace"], 'resources/darwin/default.icns') |
| 73 | + ], |
| 74 | + darwinBundleURLTypes: [{ |
| 75 | + role: 'Viewer', |
| 76 | + name: product.nameLong, |
| 77 | + urlSchemes: [product.urlProtocol] |
| 78 | + }], |
| 79 | + darwinForceDarkModeSupport: true, |
| 80 | + darwinCredits: darwinCreditsTemplate ? Buffer.from(darwinCreditsTemplate({ commit: commit, date: new Date().toISOString() })) : undefined, |
| 81 | + linuxExecutableName: product.applicationName, |
| 82 | + winIcon: 'resources/win32/code.ico', |
| 83 | + token: process.env['VSCODE_MIXIN_PASSWORD'] || process.env['GITHUB_TOKEN'] || undefined, |
| 84 | + repo: product.electronRepository || undefined |
| 85 | +}; |
| 86 | +function getElectron(arch) { |
| 87 | + return () => { |
| 88 | + const electronOpts = _.extend({}, exports.config, { |
| 89 | + platform: process.platform, |
| 90 | + arch, |
| 91 | + ffmpegChromium: true, |
| 92 | + keepDefaultApp: true |
| 93 | + }); |
| 94 | + return vfs.src('package.json') |
| 95 | + .pipe(json({ name: product.nameShort })) |
| 96 | + .pipe(electron(electronOpts)) |
| 97 | + .pipe(filter(['**', '!**/app/package.json'])) |
| 98 | + .pipe(vfs.dest('.build/electron')); |
| 99 | + }; |
| 100 | +} |
| 101 | +async function main(arch = process.arch) { |
| 102 | + const version = getElectronVersion(); |
| 103 | + const electronPath = path.join(root, '.build', 'electron'); |
| 104 | + const versionFile = path.join(electronPath, 'version'); |
| 105 | + const isUpToDate = fs.existsSync(versionFile) && fs.readFileSync(versionFile, 'utf8') === `${version}`; |
| 106 | + if (!isUpToDate) { |
| 107 | + await util.rimraf(electronPath)(); |
| 108 | + await util.streamToPromise(getElectron(arch)()); |
| 109 | + } |
18 | 110 | } |
19 | | - |
20 | | -module.exports.getElectronVersion = getElectronVersion; |
21 | | - |
22 | | -// returns 0 if the right version of electron is in .build/electron |
23 | | -// @ts-ignore |
24 | 111 | if (require.main === module) { |
25 | | - const version = getElectronVersion(); |
26 | | - const versionFile = path.join(root, '.build', 'electron', 'version'); |
27 | | - const isUpToDate = fs.existsSync(versionFile) && fs.readFileSync(versionFile, 'utf8') === `${version}`; |
28 | | - |
29 | | - process.exit(isUpToDate ? 0 : 1); |
| 112 | + main(process.argv[2]).catch(err => { |
| 113 | + console.error(err); |
| 114 | + process.exit(1); |
| 115 | + }); |
30 | 116 | } |
0 commit comments