Skip to content

CODEYA/node-shellscript-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shellscript-ts

A nodejs module for creating shellscript in TypeScript.

CircleCI badge npm version npm downloads npm license Dependency Status

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

About

A nodejs module for creating shellscript in TypeScript.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •