Skip to content

Autocompletion #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/nativescript.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@node %~dp0\nativescript.js %*
1 change: 1 addition & 0 deletions bin/nativescript.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node

"use strict";
require("../lib/nativescript-cli.js");
1 change: 1 addition & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ $injector.requireCommand("run", "./commands/run");
$injector.requireCommand("prepare", "./commands/prepare");
$injector.requireCommand("build", "./commands/build");
$injector.requireCommand("deploy", "./commands/deploy");
$injector.requireCommand("dev-post-install", "./commands/post-install");

$injector.require("npm", "./node-package-manager");
$injector.require("config", "./config");
86 changes: 86 additions & 0 deletions lib/commands/post-install.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
///<reference path="../.d.ts"/>
"use strict";
import osenv = require("osenv");
import path = require("path");

export class PostInstallCommand implements ICommand {
private static CALL_PROFILE_SCRIPT =
"if [ -f ~/.profile ]; then\n" +
" . ~/.profile\n" +
"fi\n";

constructor(private $fs: IFileSystem,
private $childProcess: IChildProcess,
private $logger: ILogger) { }

public disableAnalytics = true;

public execute(args: string[]): IFuture<void> {
return (() => {
var scriptsOk = true;

try {
this.updateShellScript(".profile").wait();
this.updateShellScript(".bashrc").wait();

this.updateBashProfile().wait();

// zsh - http://www.acm.uiuc.edu/workshops/zsh/startup_files.html
this.updateShellScript(".zshrc").wait();
} catch(err) {
this.$logger.out("Failed to update all shell start-up scripts. Auto-completion may not work. " + err);
scriptsOk = false;
}

if(scriptsOk) {
this.$logger.out("Restart your shell to enable command auto-completion.");
}
}).future<void>()();
}

private updateShellScript(fileName: string): IFuture<void> {
return (() => {
var filePath = this.getHomePath(fileName);

var doUpdate = true;
if (this.$fs.exists(filePath).wait()) {
var contents = this.$fs.readText(filePath).wait();
if (contents.match(/nativescript\s+completion\s+--\s+/) || contents.match(/tns\s+completion\s+--\s+/)) {
doUpdate = false;
}
}

if(doUpdate) {
this.updateShellScriptCore(filePath).wait();
}

}).future<void>()();
}

private updateShellScriptCore(filePath: string): IFuture<void> {
return (() => {
this.$childProcess.exec("nativescript completion >> " + filePath).wait();
this.$childProcess.exec("tns completion >> " + filePath).wait();
}).future<void>()();
}

private getHomePath(fileName: string): string {
return path.join(osenv.home(), fileName);
}

private updateBashProfile(): IFuture<void> {
return (() => {
var bashProfileFileName = this.getHomePath(".bash_profile");
if (this.$fs.exists(bashProfileFileName).wait()) {
var contens = this.$fs.readText(bashProfileFileName).wait();
if (contens.indexOf(PostInstallCommand.CALL_PROFILE_SCRIPT) < 0) {
this.updateShellScript(".bash_profile");
}
} else {
this.$fs.writeFile(bashProfileFileName, PostInstallCommand.CALL_PROFILE_SCRIPT).wait();
this.updateShellScriptCore(bashProfileFileName).wait();
}
}).future<void>()();
}
}
$injector.registerCommand("dev-post-install", PostInstallCommand);
2 changes: 1 addition & 1 deletion lib/common
1 change: 1 addition & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import util = require("util");
export class StaticConfig implements IStaticConfig {
public PROJECT_FILE_NAME = ".tnsproject";
public CLIENT_NAME = "nativescript";
public CLIENT_NAME_ALIAS = "tns";
public ANALYTICS_API_KEY = "5752dabccfc54c4ab82aea9626b7338e";
public TRACK_FEATURE_USAGE_SETTING_NAME = "TrackFeatureUsage";
public ANALYTICS_INSTALLATION_ID_SETTING_NAME = "AnalyticsInstallationID";
Expand Down
1 change: 1 addition & 0 deletions lib/nativescript-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ $injector.register("config", {

var dispatcher = $injector.resolve("dispatcher");
dispatcher.runMainFiber();

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"main": "./lib/nativescript-cli.js",
"scripts": {
"test": "node_modules\\.bin\\_mocha --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 15000 test/"
"test": "node_modules\\.bin\\_mocha --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 15000 test/",
"postinstall": "node postinstall.js"
},
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

var child_process = require("child_process");
child_process.exec('node bin/nativescript.js dev-post-install');