typescript

package
v3.0.0-beta+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2016 License: Apache-2.0 Imports: 13 Imported by: 0

README

Package information

This is an Iris and typescript bridge plugin.

  1. Search for typescript files (.ts)
  2. Search for typescript projects (.tsconfig)
  3. If 1 || 2 continue else stop
  4. Check if typescript is installed, if not then auto-install it (always inside npm global modules, -g)
  5. If typescript project then build the project using tsc -p $dir
  6. If typescript files and no project then build each typescript using tsc $filename
  7. Watch typescript files if any changes happens, then re-build (5|6)

Note: Ignore all typescript files & projects whose path has '/node_modules/'

Options

This plugin has optionally options

  1. Bin: string, the typescript installation path/bin/tsc or tsc.cmd, if empty then it will search to the global npm modules
  2. Dir: string, Dir set the root, where to search for typescript files/project. Default "./"
  3. Ignore: string, comma separated ignore typescript files/project from these directories. Default "" (node_modules are always ignored)
  4. Tsconfig: &typescript.Tsconfig{}, here you can set all compilerOptions if no tsconfig.json exists inside the 'Dir'
  5. Editor: typescript.Editor(), if setted then alm-tools browser-based typescript IDE will be available. Defailt is nil

Note: if any string in Ignore doesn't start with './' then it will ignore all files which contains this path string. For example /node_modules/ will ignore all typescript files that are inside at ANY '/node_modules/', that means and the submodules.

How to use


package main

import (
	"github.com/kataras/iris"
	"github.com/kataras/iris/plugin/typescript"
)

func main(){
	/* Options
	Bin ->  		  the typescript installation path/bin/tsc or tsc.cmd, if empty then it will search to the global npm modules
	Dir    ->		   where to search for typescript files/project. Default "./"
	Ignore ->        comma separated ignore typescript files/project from these directories (/node_modules/ are always ignored). Default ""
    Tsconfig -> 		&typescript.Tsconfig{}, here you can set all compilerOptions if no tsconfig.json exists inside the 'Dir'
    Editor ->			typescript.Editor(), if setted then alm-tools browser-based typescript IDE will be available. Default is nil.
	*/

	ts := typescript.Options {
		Dir: "./scripts/src",
		Tsconfig: &typescript.Tsconfig{Module: "commonjs", Target: "es5"}, // or typescript.DefaultTsconfig()
	}

	//if you want to change only certain option(s) but you want default to all others then you have to do this:
	ts = typescript.DefaultOptions()
	//

	iris.Plugins().Add(typescript.New(ts)) //or with the default options just: typescript.New()

	iris.Get("/", func (ctx *iris.Context){})

	iris.Listen(":8080")
}


Editor

alm-tools is a typescript online IDE/Editor, made by @basarat one of the top contributors of the Typescript.

Iris gives you the opportunity to edit your client-side using the alm-tools editor, via the editor plugin. With typescript plugin you have to set the Editor option and you're ready:

typescript.Options {
	//...
	Editor: typescript.Editor("username","passowrd")
	//...
}

Read more for Editor

Documentation

Index

Constants

View Source
const Name = "TypescriptPlugin"

Name the name of the plugin, is "TypescriptPlugin"

Variables

This section is empty.

Functions

func Editor

func Editor(username, password string) *editor.Plugin

Editor is just a shortcut for github.com/kataras/iris/plugin/editor.New() returns a new (Editor)Plugin, it's exists here because the typescript plugin has direct interest with the EditorPlugin

Types

type CompilerOptions

type CompilerOptions struct {
	Declaration                      bool   `json:"declaration"`
	Module                           string `json:"module"`
	Target                           string `json:"target"`
	Watch                            bool   `json:"watch"`
	Charset                          string `json:"charset"`
	Diagnostics                      bool   `json:"diagnostics"`
	EmitBOM                          bool   `json:"emitBOM"`
	EmitDecoratorMetadata            bool   `json:"emitDecoratorMetadata"`
	ExperimentalDecorators           bool   `json:"experimentalDecorators"`
	InlineSourceMap                  bool   `json:"inlineSourceMap"`
	InlineSources                    bool   `json:"inlineSources"`
	IsolatedModules                  bool   `json:"isolatedModules"`
	Jsx                              string `json:"jsx"`
	ReactNamespace                   string `json:"reactNamespace"`
	ListFiles                        bool   `json:"listFiles"`
	Locale                           string `json:"locale"`
	MapRoot                          string `json:"mapRoot"`
	ModuleResolution                 string `json:"moduleResolution"`
	NewLine                          string `json:"newLine"`
	NoEmit                           bool   `json:"noEmit"`
	NoEmitOnError                    bool   `json:"noEmitOnError"`
	NoEmitHelpers                    bool   `json:"noEmitHelpers"`
	NoImplicitAny                    bool   `json:"noImplicitAny"`
	NoLib                            bool   `json:"noLib"`
	NoResolve                        bool   `json:"noResolve"`
	SkipDefaultLibCheck              bool   `json:"skipDefaultLibCheck"`
	OutDir                           string `json:"outDir"`
	OutFile                          string `json:"outFile"`
	PreserveConstEnums               bool   `json:"preserveConstEnums"`
	Pretty                           bool   `json:"pretty"`
	RemoveComments                   bool   `json:"removeComments"`
	RootDir                          string `json:"rootDir"`
	SourceMap                        bool   `json:"sourceMap"`
	SourceRoot                       string `json:"sourceRoot"`
	StripInternal                    bool   `json:"stripInternal"`
	SuppressExcessPropertyErrors     bool   `json:"suppressExcessPropertyErrors"`
	SuppressImplicitAnyIndexErrors   bool   `json:"suppressImplicitAnyIndexErrors"`
	AllowUnusedLabels                bool   `json:"allowUnusedLabels"`
	NoImplicitReturns                bool   `json:"noImplicitReturns"`
	NoFallthroughCasesInSwitch       bool   `json:"noFallthroughCasesInSwitch"`
	AllowUnreachableCode             bool   `json:"allowUnreachableCode"`
	ForceConsistentCasingInFileNames bool   `json:"forceConsistentCasingInFileNames"`
	AllowSyntheticDefaultImports     bool   `json:"allowSyntheticDefaultImports"`
	AllowJs                          bool   `json:"allowJs"`
	NoImplicitUseStrict              bool   `json:"noImplicitUseStrict"`
}

CompilerOptions contains all the compiler options used by the tsc (typescript compiler)

type Options

type Options struct {
	Bin      string
	Dir      string
	Ignore   string
	Tsconfig *Tsconfig
	Editor   *editor.Plugin // the editor is just a plugin also
}

Options the struct which holds the TypescriptPlugin options Has five (5) fields

1. Bin: string, the typescript installation directory/typescript/lib/tsc.js, if empty it will search inside global npm modules 2. Dir: string, Dir set the root, where to search for typescript files/project. Default "./" 3. Ignore: string, comma separated ignore typescript files/project from these directories. Default "" (node_modules are always ignored) 4. Tsconfig: &typescript.Tsconfig{}, here you can set all compilerOptions if no tsconfig.json exists inside the 'Dir' 5. Editor: typescript.Editor("username","password"), if setted then alm-tools browser-based typescript IDE will be available. Defailt is nil

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the default Options of the Plugin

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin the struct of the Typescript Plugin, holds all necessary fields & methods

func New

func New(_opt ...Options) *Plugin

New creates & returns a new instnace typescript plugin

func (*Plugin) Activate

func (t *Plugin) Activate(container iris.IPluginContainer) error

Activate ...

func (*Plugin) GetDescription

func (t *Plugin) GetDescription() string

GetDescription TypescriptPlugin scans and compile typescript files with ease

func (*Plugin) GetName

func (t *Plugin) GetName() string

GetName ...

func (*Plugin) PreListen

func (t *Plugin) PreListen(s *iris.Iris)

PreListen ...

type Tsconfig

type Tsconfig struct {
	CompilerOptions CompilerOptions `json:"compilerOptions"`
	Exclude         []string        `json:"exclude"`
}

Tsconfig the struct for tsconfig.json

func DefaultTsconfig

func DefaultTsconfig() *Tsconfig

DefaultTsconfig returns the default Tsconfig, with CompilerOptions module: commonjs, target: es5 and ignore the node_modules

func FromFile

func FromFile(tsConfigAbsPath string) *Tsconfig

FromFile reads a file & returns the Tsconfig by its contents

func (*Tsconfig) CompilerArgs

func (tsconfig *Tsconfig) CompilerArgs() []string

CompilerArgs returns the CompilerOptions' contents of the Tsconfig it reads the json tags, add '--' at the start of each one and returns an array of strings

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL