-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added text:replace step Fixed cwd on steps running
- Loading branch information
Showing
15 changed files
with
434 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package hxextern; | ||
|
||
class Tools | ||
{ | ||
public static function escapeEReg(value : String) : String | ||
{ | ||
return ~/([-[\]{}()*+?.,\\^$|#\s])/g.replace(value, '\\$1'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
package hxextern.step; | ||
|
||
import hxextern.service.Process; | ||
import hxextern.step.IStep; | ||
|
||
@:skip | ||
class AbstractCommandStep extends AbstractStep | ||
{ | ||
public function new(type : String) | ||
@inject | ||
public var process(default, null) : Process; | ||
|
||
public function new() | ||
{ | ||
super(); | ||
} | ||
|
||
public override function run(context : StepContext) : Void | ||
{ | ||
super(type); | ||
super.run(context); | ||
} | ||
|
||
public override function run(definitions : TypeDefinitionMap, options : Null<Dynamic>) : TypeDefinitionMap | ||
private function exec(command : String, ?args : Array<String>) : ProcessOutput | ||
{ | ||
return definitions; | ||
this.process.checkCommand(command); | ||
return this.process.execute(command, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
package hxextern.step; | ||
|
||
import haxe.DynamicAccess; | ||
import hxextern.service.Console; | ||
import hxextern.step.IStep; | ||
|
||
@:skip | ||
class AbstractStep implements IStep | ||
{ | ||
public var type(default, null) : String; | ||
@inject | ||
public var console(default, null) : Console; | ||
|
||
public function new(type : String) | ||
public function new() | ||
{ | ||
this.type = type; | ||
// ... | ||
} | ||
|
||
public function run(definitions : TypeDefinitionMap, options : Null<Dynamic>) : TypeDefinitionMap | ||
public function initialize(options : DynamicAccess<Dynamic>) : Void | ||
{ | ||
throw 'Must be overriden'; | ||
// ... | ||
} | ||
|
||
public function run(context : StepContext) : Void | ||
{ | ||
// ... | ||
} | ||
|
||
private function getOption(options : DynamicAccess<Dynamic>, field : String, type : Dynamic, ?defaultValue : Dynamic) : Dynamic | ||
{ | ||
if (!options.exists(field)) { | ||
if (null != defaultValue) { | ||
return defaultValue; | ||
} | ||
throw 'Missing field "${field}" in step options'; | ||
} | ||
|
||
return definitions; | ||
var value = options[field]; | ||
if (!Std.is(value, type)) { | ||
throw 'Invalid type for field "${field}". Expected ${type}, but got ${Type.typeof(value)}'; | ||
} | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package hxextern.step; | ||
|
||
import haxe.DynamicAccess; | ||
import hxextern.step.IStep; | ||
import sys.FileSystem; | ||
import sys.io.File; | ||
|
||
class AbstractTextStep extends AbstractStep | ||
{ | ||
private var file : String; | ||
|
||
public function new() | ||
{ | ||
super(); | ||
} | ||
|
||
public override function initialize(options : DynamicAccess<Dynamic>) : Void | ||
{ | ||
super.initialize(options); | ||
|
||
this.file = FileSystem.absolutePath(this.getOption(options, 'file', String)); | ||
} | ||
|
||
public override function run(context : StepContext) : Void | ||
{ | ||
super.run(context); | ||
|
||
// Ensure that file exists | ||
if (!FileSystem.exists(this.file)) { | ||
throw 'Cannot find file "${this.file}"'; | ||
} | ||
} | ||
|
||
private function getLines() : Array<String> | ||
{ | ||
var input = File.read(this.file); | ||
var lines = []; | ||
try { | ||
while (true) { | ||
lines.push(input.readLine()); | ||
} | ||
} catch (e : haxe.io.Eof) {} | ||
input.close(); | ||
|
||
return lines; | ||
} | ||
|
||
private function setLines(lines : Array<String>) : Void | ||
{ | ||
var output = File.write(this.file); | ||
for (line in lines) { | ||
output.writeString(line); | ||
output.writeString('\n'); | ||
} | ||
output.flush(); | ||
output.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package hxextern.step; | ||
|
||
import haxe.DynamicAccess; | ||
import hxextern.service.Process; | ||
import hxextern.step.IStep; | ||
|
||
using hxextern.Tools; | ||
using StringTools; | ||
|
||
@:step('command:npm') | ||
class CommandNpmStep extends AbstractCommandStep | ||
{ | ||
private var module : String; | ||
private var version : String; | ||
|
||
public function new() | ||
{ | ||
super(); | ||
} | ||
|
||
public override function initialize(options : DynamicAccess<Dynamic>) : Void | ||
{ | ||
super.initialize(options); | ||
|
||
this.module = this.getOption(options, 'module', String); | ||
this.version = this.getOption(options, 'version', String, ''); | ||
} | ||
|
||
public override function run(context : StepContext) : Void | ||
{ | ||
super.run(context); | ||
|
||
// Prepare package name | ||
var packageName = this.module; | ||
if (this.version.length > 0) { | ||
packageName += '@${this.version}'; | ||
} | ||
|
||
// Install module | ||
var result = this.exec('npm', ['install', packageName, '--silent']); | ||
if (0 == result.code) { | ||
this.console.success('NPM module "${packageName}" installed'); | ||
|
||
// Extract installed npm module version | ||
var ereg = new EReg('${this.module.escapeEReg()}@([0-9.]+)', 'ig'); | ||
if (ereg.match(result.output)) { | ||
context.registerVariable('npm', { | ||
module: { | ||
name: this.module, | ||
version: ereg.matched(1), | ||
}, | ||
}); | ||
} | ||
} else { | ||
this.console | ||
.error('NPM module "${this.module}" has not been installed') | ||
.error(result.error) | ||
; | ||
} | ||
} | ||
} |
Oops, something went wrong.