mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 03:17:04 +00:00
Add notes for the new lead maintainer of the open-source iris project and align with @get-ion/ion by @hiveminded
Former-commit-id: da4f38eb9034daa49446df3ee529423b98f9b331
This commit is contained in:
5
typescript/AUTHORS
Normal file
5
typescript/AUTHORS
Normal file
@@ -0,0 +1,5 @@
|
||||
# This is the official list of Iris Typescript authors for copyright
|
||||
# purposes.
|
||||
|
||||
Gerasimos Maropoulos <kataras2006@hotmail.com>
|
||||
Bill Qeras, Jr. <hiveminded@tutanota.com>
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
||||
Copyright (c) 2017 The Iris Typescript Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
@@ -10,8 +10,8 @@ notice, this list of conditions and the following disclaimer.
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Gerasimos Maropoulos nor the name of his
|
||||
username, kataras, may be used to endorse or promote products derived from
|
||||
* Neither the name of Iris nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
@@ -24,4 +24,4 @@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
9
typescript/README.md
Normal file
9
typescript/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Typescript
|
||||
|
||||
[Typescript](http://www.typescriptlang.org/) and [alm-tools cloud editor](http://alm.tools/) automation tools for the [iris](https://github.com/kataras/iris) web framework.
|
||||
|
||||
|
||||
## Table of contents
|
||||
|
||||
* [Typescript compiler](_examples/typescript/main.go)
|
||||
* [Alm-tools cloud editor](_examples/editor/main.go)
|
||||
34
typescript/_examples/editor/main.go
Normal file
34
typescript/_examples/editor/main.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
|
||||
"github.com/kataras/iris/typescript/editor"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.StaticWeb("/scripts", "./www/scripts") // serve the scripts
|
||||
// when you edit a typescript file from the alm-tools
|
||||
// it compiles it to javascript, have fun!
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.ServeFile("./www/index.html", false)
|
||||
})
|
||||
|
||||
editorConfig := editor.Config{
|
||||
Hostname: "localhost",
|
||||
Port: 4444,
|
||||
WorkingDir: "./www/scripts/", // "/path/to/the/client/side/directory/",
|
||||
Username: "myusername",
|
||||
Password: "mypassword",
|
||||
}
|
||||
e := editor.New(editorConfig)
|
||||
e.Run(app.Logger().Infof) // start the editor's server
|
||||
|
||||
// http://localhost:8080
|
||||
// http://localhost:4444
|
||||
app.Run(iris.Addr(":8080"))
|
||||
e.Stop()
|
||||
}
|
||||
8
typescript/_examples/editor/www/index.html
Normal file
8
typescript/_examples/editor/www/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Load my script</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="scripts/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
16
typescript/_examples/editor/www/scripts/app.ts
Normal file
16
typescript/_examples/editor/www/scripts/app.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
class User{
|
||||
private name: string;
|
||||
|
||||
constructor(fullname:string) {
|
||||
this.name = fullname;
|
||||
}
|
||||
|
||||
Hi(msg: string): string {
|
||||
return msg + " " + this.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var user = new User("iris web framework!");
|
||||
var hi = user.Hi("Hello");
|
||||
window.alert(hi);
|
||||
22
typescript/_examples/editor/www/scripts/tsconfig.json
Normal file
22
typescript/_examples/editor/www/scripts/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": false,
|
||||
"removeComments": true,
|
||||
"preserveConstEnums": true,
|
||||
"sourceMap": false,
|
||||
"target": "ES5",
|
||||
"noEmit": false,
|
||||
"watch":true,
|
||||
"noEmitOnError": true,
|
||||
"experimentalDecorators": false,
|
||||
"outDir": "./",
|
||||
"charset": "UTF-8",
|
||||
"noLib": false,
|
||||
"diagnostics": true,
|
||||
"declaration": false
|
||||
},
|
||||
"files": [
|
||||
"./app.ts"
|
||||
]
|
||||
}
|
||||
41
typescript/_examples/typescript/main.go
Normal file
41
typescript/_examples/typescript/main.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
|
||||
"github.com/kataras/iris/typescript"
|
||||
)
|
||||
|
||||
// NOTE: Some machines don't allow to install typescript automatically, so if you don't have typescript installed
|
||||
// and the typescript adaptor doesn't works for you then follow the below steps:
|
||||
// 1. close the iris server
|
||||
// 2. open your terminal and execute: npm install -g typescript
|
||||
// 3. start your iris server, it should be work, as expected, now.
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.StaticWeb("/scripts", "./www") // serve the scripts
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.ServeFile("./www/index.html", false)
|
||||
})
|
||||
|
||||
ts := typescript.New()
|
||||
ts.Config.Dir = "./www/scripts"
|
||||
ts.Run(app.Logger().Infof)
|
||||
|
||||
// http://localhost:8080
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
|
||||
// open http://localhost:8080
|
||||
// go to ./www/scripts/app.ts
|
||||
// make a change
|
||||
// reload the http://localhost:8080 and you should see the changes
|
||||
//
|
||||
// what it does?
|
||||
// - compiles the typescript files using default compiler options if not tsconfig found
|
||||
// - watches for changes on typescript files, if a change then it recompiles the .ts to .js
|
||||
//
|
||||
// same as you used to do with gulp-like tools, but here I do my bests to help GO developers.
|
||||
8
typescript/_examples/typescript/www/index.html
Normal file
8
typescript/_examples/typescript/www/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Load my script</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="scripts/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
16
typescript/_examples/typescript/www/scripts/app.ts
Normal file
16
typescript/_examples/typescript/www/scripts/app.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
class User{
|
||||
private name: string;
|
||||
|
||||
constructor(fullname:string) {
|
||||
this.name = fullname;
|
||||
}
|
||||
|
||||
Hi(msg: string): string {
|
||||
return msg + " "+ this.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var user = new User("iris web framework");
|
||||
var hi = user.Hi("Hello");
|
||||
window.alert(hi);
|
||||
@@ -1,7 +1,3 @@
|
||||
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package typescript
|
||||
|
||||
import (
|
||||
@@ -169,9 +165,12 @@ func DefaultTsconfig() Tsconfig {
|
||||
Jsx: "react",
|
||||
ModuleResolution: "classic",
|
||||
Locale: "en",
|
||||
Watch: true,
|
||||
Watch: false,
|
||||
NoImplicitAny: false,
|
||||
SourceMap: false,
|
||||
Diagnostics: true,
|
||||
NoEmit: false,
|
||||
OutDir: "", // taken from Config.Dir if it's not empty, otherwise ./ on Run()
|
||||
},
|
||||
Exclude: []string{"node_modules"},
|
||||
}
|
||||
@@ -183,7 +182,7 @@ func DefaultTsconfig() Tsconfig {
|
||||
func DefaultConfig() Config {
|
||||
root, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic("Typescript Adaptor: Cannot get the Current Working Directory !!! [os.getwd()]")
|
||||
panic("typescript: cannot get the cwd")
|
||||
}
|
||||
compilerTsConfig := DefaultTsconfig()
|
||||
c := Config{
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
Copyright (c) 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Gerasimos Maropoulos nor the name of his
|
||||
username, kataras, may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Third-Parties:
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Basarat Ali Syed
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,7 +1,3 @@
|
||||
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package editor
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,32 +1,29 @@
|
||||
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package editor
|
||||
|
||||
// +------------------------------------------------------------+
|
||||
// | Editor usage |
|
||||
// +------------------------------------------------------------+
|
||||
//
|
||||
// import "github.com/kataras/iris/typescript/editor"
|
||||
// [...]
|
||||
//
|
||||
// app := iris.New()
|
||||
// e := editor.New(editor.Config{})
|
||||
// e.Attach(app)
|
||||
//
|
||||
// [...]
|
||||
// app.Run(iris.Addr(":8080"))
|
||||
/* Package editor provides alm-tools cloud editor automation for the iris web framework.
|
||||
|
||||
//
|
||||
// +------------------------------------------------------------+
|
||||
// | General notes for authentication |
|
||||
// +------------------------------------------------------------+
|
||||
//
|
||||
// The Authorization specifies the authentication mechanism (in this case Basic) followed by the username and password.
|
||||
// Although, the string aHR0cHdhdGNoOmY= may look encrypted it is simply a base64 encoded version of <username>:<password>.
|
||||
// Would be readily available to anyone who could intercept the HTTP request.
|
||||
Usage:
|
||||
|
||||
|
||||
import "github.com/kataras/iris/typescript/editor"
|
||||
[...]
|
||||
|
||||
app := iris.New()
|
||||
e := editor.New(editor.Config{})
|
||||
e.Run(app.Logger().Infof)
|
||||
|
||||
[...]
|
||||
app.Run(iris.Addr(":8080"))
|
||||
e.Stop()
|
||||
|
||||
|
||||
General notes for authentication
|
||||
|
||||
|
||||
The Authorization specifies the authentication mechanism (in this case Basic) followed by the username and password.
|
||||
Although, the string aHR0cHdhdGNoOmY= may look encrypted it is simply a base64 encoded version of <username>:<password>.
|
||||
Would be readily available to anyone who could intercept the HTTP request.
|
||||
*/
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
@@ -34,8 +31,6 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/core/host"
|
||||
"github.com/kataras/iris/typescript/npm"
|
||||
)
|
||||
|
||||
@@ -57,6 +52,11 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
// NoOpLogger can be used as the logger argument, it prints nothing.
|
||||
NoOpLogger = func(string, ...interface{}) {}
|
||||
)
|
||||
|
||||
// New creates and returns an Editor Plugin instance
|
||||
func New(cfg ...Config) *Editor {
|
||||
c := DefaultConfig()
|
||||
@@ -110,9 +110,9 @@ func (e *Editor) DisableOutput() {
|
||||
e.config.DisableOutput = true
|
||||
}
|
||||
|
||||
// GetDescription EditorPlugin is a bridge between Iris and the alm-tools, the browser-based IDE for client-side sources.
|
||||
// GetDescription EditorPlugin is a bridge between iris and the alm-tools, the browser-based IDE for client-side sources.
|
||||
func (e *Editor) GetDescription() string {
|
||||
return "A bridge between Iris and the alm-tools, the browser-based IDE."
|
||||
return "A bridge between iris and the alm-tools, the browser-based IDE."
|
||||
}
|
||||
|
||||
// we use that editorWriter to prefix the editor's output with "Editor Adaptor: "
|
||||
@@ -120,9 +120,15 @@ type editorWriter struct {
|
||||
underline io.Writer
|
||||
}
|
||||
|
||||
// build runs before the server's listens, creates the listener ( use of port parent hostname:DefaultPort if not exist)
|
||||
func (e *Editor) build(s *iris.Application) {
|
||||
e.log = s.Log
|
||||
// Run starts the editor's server.
|
||||
//
|
||||
// Developers should call the `Stop` to shutdown the editor's server when main server will be closed.
|
||||
func (e *Editor) Run(logger func(format string, a ...interface{})) {
|
||||
if logger == nil {
|
||||
logger = NoOpLogger
|
||||
}
|
||||
|
||||
e.log = logger
|
||||
if e.config.Hostname == "" {
|
||||
e.config.Hostname = "0.0.0.0"
|
||||
}
|
||||
@@ -138,8 +144,8 @@ func (e *Editor) build(s *iris.Application) {
|
||||
e.start()
|
||||
}
|
||||
|
||||
// close kills the editor's server when Iris is closed
|
||||
func (e *Editor) close(s *iris.Application) {
|
||||
// Stop kills the editor's server.
|
||||
func (e *Editor) Stop() {
|
||||
if e.process != nil {
|
||||
err := e.process.Kill()
|
||||
if err != nil {
|
||||
@@ -210,13 +216,3 @@ func (e *Editor) start() {
|
||||
// no need, alm-tools post these
|
||||
// e.logger.Printf("Editor is running at %s:%d | %s", e.config.Hostname, e.config.Port, e.config.WorkingDir)
|
||||
}
|
||||
|
||||
// Attach adapts the editor to one or more Iris instance(s).
|
||||
func (e *Editor) Attach(app *iris.Application) {
|
||||
|
||||
e.build(app)
|
||||
|
||||
app.Scheduler.Schedule(host.OnInterrupt(func(proc host.TaskProcess) {
|
||||
e.close(app)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package npm // #nosec
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package npm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// nodeModulesPath is the path of the root npm modules
|
||||
// Ex: C:\\Users\\kataras\\AppData\\Roaming\\npm\\node_modules
|
||||
// Ex: C:\\Users\\iris\\AppData\\Roaming\\npm\\node_modules
|
||||
nodeModulesPath string
|
||||
)
|
||||
|
||||
@@ -118,11 +115,10 @@ func NodeModuleAbs(relativePath string) string {
|
||||
// here we have two options
|
||||
//1 . search by command something like npm -ls -g --depth=x
|
||||
//2. search on files, we choose the second
|
||||
func NodeModuleExists(executableRelativePath string) bool {
|
||||
execAbsPath := NodeModuleAbs(executableRelativePath)
|
||||
if execAbsPath == "" {
|
||||
return false
|
||||
func NodeModuleExists(execPath string) bool {
|
||||
if !filepath.IsAbs(execPath) {
|
||||
execPath = NodeModuleAbs(execPath)
|
||||
}
|
||||
|
||||
return Exists(execAbsPath)
|
||||
return Exists(execPath)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package typescript provides a typescript compiler with hot-reloader
|
||||
// and optionally a cloud-based editor, called 'alm-tools'.
|
||||
// typescript (by microsoft) and alm-tools (by @basarat) have their own (open-source) licenses
|
||||
@@ -15,7 +11,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/typescript/npm"
|
||||
)
|
||||
|
||||
@@ -23,26 +18,55 @@ type (
|
||||
// Typescript contains the unique iris' typescript loader, holds all necessary fields & methods.
|
||||
Typescript struct {
|
||||
Config *Config
|
||||
// taken from framework
|
||||
log func(format string, a ...interface{})
|
||||
log func(format string, a ...interface{})
|
||||
}
|
||||
)
|
||||
|
||||
// New creates & returns a new instnace typescript plugin
|
||||
func New() *Typescript {
|
||||
func New(cfg ...Config) *Typescript {
|
||||
c := DefaultConfig()
|
||||
|
||||
if !strings.Contains(c.Ignore, nodeModules) {
|
||||
c.Ignore += "," + nodeModules
|
||||
if len(cfg) > 0 {
|
||||
c = cfg[0]
|
||||
}
|
||||
|
||||
return &Typescript{Config: &c}
|
||||
}
|
||||
|
||||
// implementation
|
||||
var (
|
||||
// NoOpLogger can be used as the logger argument, it prints nothing.
|
||||
NoOpLogger = func(string, ...interface{}) {}
|
||||
)
|
||||
|
||||
// Run starts the typescript filewatcher watcher and the typescript compiler.
|
||||
func (t *Typescript) Run(logger func(format string, a ...interface{})) {
|
||||
c := t.Config
|
||||
if c.Tsconfig == nil {
|
||||
tsC := DefaultTsconfig()
|
||||
c.Tsconfig = &tsC
|
||||
}
|
||||
|
||||
if c.Dir == "" {
|
||||
c.Tsconfig.CompilerOptions.OutDir = c.Dir
|
||||
}
|
||||
|
||||
if c.Dir == "" {
|
||||
c.Dir = "./"
|
||||
}
|
||||
|
||||
if !strings.Contains(c.Ignore, nodeModules) {
|
||||
c.Ignore += "," + nodeModules
|
||||
}
|
||||
|
||||
if logger == nil {
|
||||
logger = NoOpLogger
|
||||
}
|
||||
|
||||
t.log = logger
|
||||
|
||||
t.start()
|
||||
}
|
||||
|
||||
func (t *Typescript) start() {
|
||||
|
||||
if t.hasTypescriptFiles() {
|
||||
//Can't check if permission denied returns always exists = true....
|
||||
|
||||
@@ -59,7 +83,7 @@ func (t *Typescript) start() {
|
||||
projects := t.getTypescriptProjects()
|
||||
if len(projects) > 0 {
|
||||
watchedProjects := 0
|
||||
//typescript project (.tsconfig) found
|
||||
// typescript project (.tsconfig) found
|
||||
for _, project := range projects {
|
||||
cmd := npm.CommandBuilder("node", t.Config.Bin, "-p", project[0:strings.LastIndex(project, npm.PathSeparator)]) //remove the /tsconfig.json)
|
||||
projectConfig, perr := FromFile(project)
|
||||
@@ -74,70 +98,76 @@ func (t *Typescript) start() {
|
||||
go func() {
|
||||
_, err := cmd.Output()
|
||||
if err != nil {
|
||||
t.log(err.Error())
|
||||
t.log("error when 'watch' is true: %v", err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
|
||||
_, err := cmd.Output()
|
||||
if err != nil {
|
||||
t.log(err.Error())
|
||||
t.log("unexpected error from output: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// t.log("%d Typescript project(s) compiled ( %d monitored by a background file watcher", len(projects), watchedProjects)
|
||||
} else {
|
||||
//search for standalone typescript (.ts) files and compile them
|
||||
files := t.getTypescriptFiles()
|
||||
if len(files) > 0 {
|
||||
/* watchedFiles := 0
|
||||
if t.Config.Tsconfig.CompilerOptions.Watch {
|
||||
watchedFiles = len(files)
|
||||
}*/
|
||||
//it must be always > 0 if we came here, because of if hasTypescriptFiles == true.
|
||||
for _, file := range files {
|
||||
absPath, err := filepath.Abs(file)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
//these will be used if no .tsconfig found.
|
||||
// cmd := npm.CommandBuilder("node", t.Config.Bin)
|
||||
// cmd.Arguments(t.Config.Bin, t.Config.Tsconfig.CompilerArgs()...)
|
||||
// cmd.AppendArguments(absPath)
|
||||
compilerArgs := t.Config.Tsconfig.CompilerArgs()
|
||||
cmd := npm.CommandBuilder("node", t.Config.Bin)
|
||||
for _, s := range compilerArgs {
|
||||
cmd.AppendArguments(s)
|
||||
}
|
||||
cmd.AppendArguments(absPath)
|
||||
go func() {
|
||||
compilerMsgB, _ := cmd.Output()
|
||||
compilerMsg := string(compilerMsgB)
|
||||
cmd.Args = cmd.Args[0 : len(cmd.Args)-1] //remove the last, which is the file
|
||||
|
||||
if strings.Contains(compilerMsg, "error") {
|
||||
t.log(compilerMsg)
|
||||
}
|
||||
|
||||
}()
|
||||
|
||||
}
|
||||
// t.log("%d Typescript file(s) compiled ( %d monitored by a background file watcher )", len(files), watchedFiles)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
//search for standalone typescript (.ts) files and compile them
|
||||
files := t.getTypescriptFiles()
|
||||
if len(files) > 0 {
|
||||
/* watchedFiles := 0
|
||||
if t.Config.Tsconfig.CompilerOptions.Watch {
|
||||
watchedFiles = len(files)
|
||||
}*/
|
||||
//it must be always > 0 if we came here, because of if hasTypescriptFiles == true.
|
||||
for _, file := range files {
|
||||
|
||||
absPath, err := filepath.Abs(file)
|
||||
if err != nil {
|
||||
t.log("error while trying to resolve absolute path for %s: %v", file, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// these will be used if no .tsconfig found.
|
||||
// cmd := npm.CommandBuilder("node", t.Config.Bin)
|
||||
// cmd.Arguments(t.Config.Bin, t.Config.Tsconfig.CompilerArgs()...)
|
||||
// cmd.AppendArguments(absPath)
|
||||
compilerArgs := t.Config.Tsconfig.CompilerArgs()
|
||||
cmd := npm.CommandBuilder("node", t.Config.Bin)
|
||||
|
||||
for _, s := range compilerArgs {
|
||||
cmd.AppendArguments(s)
|
||||
}
|
||||
cmd.AppendArguments(absPath)
|
||||
go func() {
|
||||
compilerMsgB, _ := cmd.Output()
|
||||
compilerMsg := string(compilerMsgB)
|
||||
cmd.Args = cmd.Args[0 : len(cmd.Args)-1] //remove the last, which is the file
|
||||
|
||||
if strings.Contains(compilerMsg, "error") {
|
||||
t.log(compilerMsg)
|
||||
}
|
||||
|
||||
}()
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
absPath, err := filepath.Abs(t.Config.Dir)
|
||||
if err != nil {
|
||||
t.log("no typescript file, the directory cannot be resolved: %v", err)
|
||||
return
|
||||
}
|
||||
t.log("no typescript files found on : %s", absPath)
|
||||
}
|
||||
|
||||
func (t *Typescript) hasTypescriptFiles() bool {
|
||||
root := t.Config.Dir
|
||||
ignoreFolders := strings.Split(t.Config.Ignore, ",")
|
||||
ignoreFolders := t.getIgnoreFolders()
|
||||
hasTs := false
|
||||
if !npm.Exists(root) {
|
||||
t.log("typescript error: directory '%s' couldn't be found,\nplease specify a valid path for your *.ts files", root)
|
||||
@@ -145,18 +175,18 @@ func (t *Typescript) hasTypescriptFiles() bool {
|
||||
}
|
||||
// ignore error
|
||||
filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
|
||||
|
||||
if fi.IsDir() {
|
||||
return nil
|
||||
}
|
||||
for i := range ignoreFolders {
|
||||
if strings.Contains(path, ignoreFolders[i]) {
|
||||
return nil
|
||||
for _, s := range ignoreFolders {
|
||||
if strings.HasSuffix(path, s) || path == s {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasSuffix(path, ".ts") {
|
||||
hasTs = true
|
||||
return errors.New("Typescript found, hope that will stop here")
|
||||
return errors.New("typescript found, hope that will stop here")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -164,9 +194,21 @@ func (t *Typescript) hasTypescriptFiles() bool {
|
||||
return hasTs
|
||||
}
|
||||
|
||||
func (t *Typescript) getIgnoreFolders() (folders []string) {
|
||||
ignoreFolders := strings.Split(t.Config.Ignore, ",")
|
||||
|
||||
for _, s := range ignoreFolders {
|
||||
if s != "" {
|
||||
folders = append(folders, s)
|
||||
}
|
||||
}
|
||||
|
||||
return folders
|
||||
}
|
||||
|
||||
func (t *Typescript) getTypescriptProjects() []string {
|
||||
var projects []string
|
||||
ignoreFolders := strings.Split(t.Config.Ignore, ",")
|
||||
ignoreFolders := t.getIgnoreFolders()
|
||||
|
||||
root := t.Config.Dir
|
||||
//t.logger.Printf("\nSearching for typescript projects in %s", root)
|
||||
@@ -176,9 +218,8 @@ func (t *Typescript) getTypescriptProjects() []string {
|
||||
if fi.IsDir() {
|
||||
return nil
|
||||
}
|
||||
for i := range ignoreFolders {
|
||||
if strings.Contains(path, ignoreFolders[i]) {
|
||||
//t.logger.Println(path + " ignored")
|
||||
for _, s := range ignoreFolders {
|
||||
if strings.HasSuffix(path, s) || path == s {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
}
|
||||
@@ -196,7 +237,7 @@ func (t *Typescript) getTypescriptProjects() []string {
|
||||
// this is being called if getTypescriptProjects return 0 len, then we are searching for files using that:
|
||||
func (t *Typescript) getTypescriptFiles() []string {
|
||||
var files []string
|
||||
ignoreFolders := strings.Split(t.Config.Ignore, ",")
|
||||
ignoreFolders := t.getIgnoreFolders()
|
||||
|
||||
root := t.Config.Dir
|
||||
|
||||
@@ -205,9 +246,8 @@ func (t *Typescript) getTypescriptFiles() []string {
|
||||
if fi.IsDir() {
|
||||
return nil
|
||||
}
|
||||
for i := range ignoreFolders {
|
||||
if strings.Contains(path, ignoreFolders[i]) {
|
||||
//t.logger.Println(path + " ignored")
|
||||
for _, s := range ignoreFolders {
|
||||
if strings.HasSuffix(path, s) || path == s {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -221,9 +261,3 @@ func (t *Typescript) getTypescriptFiles() []string {
|
||||
})
|
||||
return files
|
||||
}
|
||||
|
||||
// Attach attaches the typescript to one or more Iris instance(s).
|
||||
func (t *Typescript) Attach(app *iris.Application) {
|
||||
t.log = app.Log
|
||||
t.start()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user