1.1.1 • Published 9 years ago
shellscript-ts v1.1.1
shellscript-ts
A nodejs module for creating shellscript in TypeScript.
Important
This module is deprecated. It is no longer maintained. Please use ES6 on nodejs v4 or later.
#!/usr/bin/env node --use_strict
class HelloWorld {
sayHello() {
console.log("Hello, World!");
}
}
new HelloWorld().sayHello();
Install
With npm do:
$ npm install -g shellscript-ts
Usage
Put a shebang line on top of your shellscript.
#!/usr/bin/env shellscript-ts
Sample shellscript
Parse arguments
#!/usr/bin/env shellscript-ts
/// <reference path="node.d.ts" />
var options = require('optimist')
.usage('Sample script for shellscript-ts.\nUsage: $0 [options] URL')
// --help
.describe('h', 'Print this message')
.alias('h', 'help')
.default('h', false)
.boolean(['h']);
class ParseArgs {
execute(): void {
var argv = options.argv;
if (argv.h) {
this.options.showHelp();
process.exit(1);
}
console.log("argv=", argv);
}
}
new ParseArgs().execute();
HTTP GET
#!/usr/bin/env shellscript-ts
/// <reference path="node.d.ts" />
var http = require('http');
class HttpClient {
execute(): void {
var url = process.argv[2];
http.get(url, function(res) {
console.log(res.statusCode);
console.log();
for (var key in res.headers) {
console.log(key + "=" + res.headers[key]);
}
console.log();
res.on("data", function(chunk) {
console.log("" + chunk);
});
}).on('error', function(e) {
console.log("Error : " + e.message);
});
}
}
new HttpClient().execute();
Building
In order to build the shellscript-ts, ensure that you have git and node.js installed.
Clone a copy of the repository:
$ git clone git@github.com:CODEYA/node-shellscript-ts.git
Change to the shellscript-ts directory:
$ cd node-shellscript-ts
Install dev dependencies:
$ npm install
Build the shellscript-ts:
$ gulp