move launcher.js to cli.js

This commit is contained in:
Joao Moreno
2016-02-12 12:06:05 +01:00
parent c1ef29da9b
commit 8626f24faa
5 changed files with 73 additions and 82 deletions

View File

@@ -217,12 +217,12 @@ function packageTask(platform, arch, opts) {
.pipe(util.cleanNodeModule('native-keymap', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], true))
.pipe(util.cleanNodeModule('weak', ['binding.gyp', 'build/**', 'src/**'], true));
var resources = gulp.src(['resources/*','resources/common/**'], { base: '.' });
var resources;
if (platform === 'win32') {
resources = es.merge(resources, gulp.src('resources/win32/code_file.ico', { base: '.' }));
resources = gulp.src('resources/win32/code_file.ico', { base: '.' });
} else if (platform === 'linux') {
resources = es.merge(resources, gulp.src('resources/linux/code.png', { base: '.' }));
resources = gulp.src('resources/linux/code.png', { base: '.' });
}
var extraExtensions = util.downloadExtensions(builtInExtensions)
@@ -238,7 +238,7 @@ function packageTask(platform, arch, opts) {
sources,
deps,
extraExtensions,
resources
resources || es.through()
).pipe(util.skipDirectories());
var result = all

View File

@@ -3,29 +3,17 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
if [[ "$OSTYPE" == "darwin"* ]]; then
if [ -x "/Applications/Visual Studio Code.app" ]; then
VSCODE_DIR="/Applications/Visual Studio Code.app/Contents/MacOS"
elif [ -x "$HOME/Applications/Visual Studio Code.app" ]; then
VSCODE_DIR="$HOME/Applications/Visual Studio Code.app/Contents/MacOS"
else
echo "Could not locate Visual Studio Code.app"
exit 1
fi
ELECTRON_FILE="Electron"
VSCODE_DIR="/usr/share/code"
if [ -x "$VSCODE_DIR/Code" ]; then
ELECTRON_FILE="Code"
elif [ -x "$VSCODE_DIR/Code - OSS" ]; then
ELECTRON_FILE="Code - OSS"
else
VSCODE_DIR="/usr/share/code"
if [ -x "$VSCODE_DIR/Code" ]; then
ELECTRON_FILE="Code"
elif [ -x "$VSCODE_DIR/Code - OSS" ]; then
ELECTRON_FILE="Code - OSS"
else
echo "Could not locate Visual Studio Code executable."
exit 1
fi
echo "Could not locate Visual Studio Code executable."
exit 1
fi
VSCODE_LAUNCHER="$VSCODE_DIR/resources/app/resources/common/bin/launcher.js"
VSCODE_LAUNCHER="$VSCODE_DIR/resources/app/out/cli.js"
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 VSCODE_PATH="$VSCODE_DIR/$ELECTRON_FILE" \
"$VSCODE_DIR/$ELECTRON_FILE" $VSCODE_LAUNCHER "$@"

View File

@@ -1,58 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/* global process */
var packageJson = require('../../../package.json');
var os = require('os');
var spawn = require('child_process').spawn;
function ArgParser(args) {
this.args = args;
}
ArgParser.prototype.hasFlag = function (flag, alias) {
return (flag && this.args.indexOf('--' + flag) >= 0) ||
(alias && this.args.indexOf('-' + alias) >= 0);
}
ArgParser.prototype.printHelp = function () {
var executable = 'code' + (os.platform() == 'win32' ? '.exe' : '');
console.log(
'Visual Studio Code v' + packageJson.version + '\n' +
'\n' +
'Usage: ' + executable + ' [arguments] [paths...]\n' +
'\n' +
'Options:\n' +
' -h, --help Print usage.\n' +
' --locale Use a specific locale.\n' +
' -n Force a new instance of code.\n' +
' -v, --version Print version.');
}
function parseArgs() {
var argParser = new ArgParser(process.argv.slice(2));
if (argParser.hasFlag('help', 'h')) {
argParser.printHelp();
process.exit(0);
}
if (argParser.hasFlag('version', 'v')) {
console.log(packageJson.version);
process.exit(0);
}
}
function launchCode() {
delete process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'];
spawn(process.env['VSCODE_PATH'], process.argv.slice(2), { detached: true, stdio: 'ignore' });
}
function main() {
parseArgs();
launchCode();
process.exit(0);
}
main();

6
src/cli.js Normal file
View File

@@ -0,0 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
require('./bootstrap-amd').bootstrap('vs/workbench/electron-main/cli');

View File

@@ -0,0 +1,55 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import * as fs from 'fs';
import * as os from 'os';
import { spawn } from 'child_process';
import uri from 'vs/base/common/uri';
const rootPath = path.dirname(uri.parse(require.toUrl('')).fsPath);
const packageJsonPath = path.join(rootPath, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
class ArgParser {
constructor(private argv: string[]) {}
hasFlag(flag, alias): boolean {
return (flag && this.argv.indexOf('--' + flag) >= 0)
|| (alias && this.argv.indexOf('-' + alias) >= 0);
}
help(): string {
const executable = 'code' + (os.platform() == 'win32' ? '.exe' : '');
return `Visual Studio Code v${ packageJson.version }
Usage: ${ executable } [arguments] [paths...]
Options:
-h, --help Print usage.
--locale Use a specific locale.
-n Force a new instance of Code.
-v, --version Print version.`;
}
}
export function main(argv: string[]) {
const argParser = new ArgParser(argv);
if (argParser.hasFlag('help', 'h')) {
console.log(argParser.help());
} else if (argParser.hasFlag('version', 'v')) {
console.log(packageJson.version);
} else {
delete process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'];
spawn(process.env['VSCODE_PATH'], process.argv.slice(2), { detached: true, stdio: 'ignore' });
}
process.exit(0);
}
main(process.argv.slice(2));