Skip to content

Commit

Permalink
Add windwos support.
Browse files Browse the repository at this point in the history
  • Loading branch information
BugDiver committed Jun 1, 2019
1 parent 24141ef commit 105843d
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ jest*
TODO*
ts*
launcher.js
azure*
.gitmodules
*.ps1
*.bat
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ gauge install ts --file gauge-ts-0.0.1.zip

#### Build from Source

Currently only available for *nix

##### Requirements
- [Gauge](https://gauge.org)
Expand All @@ -61,28 +60,29 @@ Currently only available for *nix
- [JQ](https://stedolan.github.io/jq/) (for unix)


Running `build.sh` should give the list of all tasks available. Below sections detail some commonly used tasks.
Running `build.sh`(*nix), or `.\build.ps1`(windwos/powershell) should give the list of all tasks available. Below sections detail some commonly used tasks.

##### Compiling

To build the project dlls:
To compile typescript to commonjs:

````
./build.sh build
./build.sh | .\build.ps1 build
````

##### Installing

To install the the typescript plugin use(Note, this will uninstall gauge-ts before installing the compiled version):

````
./build.sh forceinstall
./build.sh | .\build.ps1 package
./build.sh | .\build.ps1 forceinstall
````

##### Creating distributable

````
./build.sh package
./build.sh | .\build.ps1 package
````

New distribution details need to be updated in the dotnet-install.json file in [gauge plugin repository](https://github.com/getgauge/gauge-repository) for a new verison update.
Expand Down
111 changes: 111 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
Param(
[String]$TaskName # The name of the task to run
)

# Define the tasks
$tasks = @{}

$tasks.Add('build', @{
description = "Compiles typescript files to js with diclaration, add generated code to dist";
script = {
clean
npm run build
Copy-Item -Recurse .\src\gen .\dist
}
})


$tasks.Add('package', @{
description = "Generate gauge-ts plugin zip file";
script = {
Invoke-Command $tasks.Get_Item("build").script
mkdir -p deploy
Copy-Item launcher.* deploy
Copy-Item ts.json deploy
mkdir artifacts
$version = version
$src = Join-Path -Path (Get-Location).Path -ChildPath "deploy"
$artifacts = Join-Path -Path (Get-Location).Path -ChildPath "artifacts"
$dest = Join-Path -Path $artifacts -ChildPath "gauge-ts-$version.zip"
Add-Type -Assembly "System.IO.Compression.FileSystem" ;
[System.IO.Compression.ZipFile]::CreateFromDirectory($src, $dest)
}
})


$tasks.Add('install', @{
description = "Install's gauge-ts plugin from the files in artifacts dir";
script = {
$version = version
gauge install ts -f ".\artifacts\gauge-ts-$version.zip"
}
})


$tasks.Add('uninstall', @{
description = "UnInstall gauge-ts plugin's current version";
script = {
$version = version
gauge uninstall ts -v $version
}
})



$tasks.Add('forceinstall', @{
description = "Insatall gauge-ts plugin after uninstall the current version";
script = {
Invoke-Command $tasks.Get_Item("uninstall").script
Invoke-Command $tasks.Get_Item("install").script
}
})


# Helper functions
function version {
$runnerManifest = Get-Content .\ts.json | Out-String | ConvertFrom-Json
$version = $runnerManifest.version
return $version
}

function clean {
$dirs = "dist", "deploy", "artifacts"
foreach ($dir in $dirs) {
if (Test-Path $dir) {
Remove-Item -Recurse -Force $dir
}
}
}

# Some helpful strings for formatting output
$indent = (" " * 4);
$spacer = ("-" * 40);

function DisplayHelpText {
$help_text = Get-Help $MyInvocation.ScriptName
$syn = $help_text.Synopsis
Write-Output "build.ps1 - runtask TaskName"
DisplayTaskList
}

function DisplayTaskList {
Write-Output "`nList of Tasks:`n$spacer"
foreach ($task in $tasks.GetEnumerator()) {
Write-Output "$indent$($task.Key)"
Write-Output "$($indent * 2)$($task.Value.description)"
}
}

# Now process the given task name
if (-not $taskname) {
DisplayHelpText
exit
}
$task = $tasks.Get_Item($taskname)
if ($task) {
Invoke-Command $task.script
}
else {
Write-Output "'$taskname' is not a valid task name."
DisplayTaskList
}
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ function version() {
function package() {
checkCommand "npm"
checkCommand "zip"
rm -rf deploy artifacts
rm -rf dist deploy artifacts
npm run build
cp -r ./src/gen ./dist
mkdir -p deploy
cp launcher.* deploy
cp ts.json deploy
Expand Down
2 changes: 1 addition & 1 deletion launcher.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
echo "Windows support is not tested yet. There might be some issues."
@echo off
echo "Windows support is not tested yet. There might be some issues."
node launcher.js %1
12 changes: 11 additions & 1 deletion launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,21 @@ let packageJson = `
let fs = require("fs");
let path = require("path");
let cp = require("child_process");
let os = require('os');

let testsDir = path.join(process.env.GAUGE_PROJECT_ROOT, 'tests');
let envDir = path.join(process.env.GAUGE_PROJECT_ROOT, 'env');
let packageJsonFile = path.join(process.env.GAUGE_PROJECT_ROOT, 'package.json');

function getCommand(command) {
let validExecExt = [""];
if (os.platform() === 'win32') validExecExt.push(".bat", ".exe", ".cmd");
for (const ext of validExecExt) {
let executable = `${command}${ext}`;
if (!cp.spawnSync(executable).error) return executable;
}
}

if (process.argv[2] === "--init") {
console.log("Initializing Gauge TypeScript project");
fs.mkdir(testsDir, 484, function (err) {
Expand Down Expand Up @@ -108,7 +118,7 @@ else if (process.argv[2] === "--start") {
+ `let runner = new GaugeRuntime();`
+ `runner.start();`
var options = `{"experimentalDecorators": true,"emitDecoratorMetadata": true}`
var runner = cp.spawn('npx', ["--no-install", 'ts-node', '-O', options, '-e', script], {
var runner = cp.spawn(getCommand("npx"), ["--no-install", 'ts-node', '-O', options, '-e', script], {
env: process.env,
silent: false,
stdio: "inherit",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "rm -rf dist && tsc && cp -r src/gen dist/",
"build": "tsc",
"test:coverage": "jest --coverage",
"codecov": "codecov",
"test": "jest --verbose",
Expand Down
6 changes: 3 additions & 3 deletions ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"--start"
],
"windows": [
"index.bat",
"launcher.bat",
"--start"
]
},
Expand All @@ -26,8 +26,8 @@
"--init"
],
"windows": [
"index.bat",
"--start"
"launcher.bat",
"--init"
]
},
"gaugeVersionSupport": {
Expand Down

0 comments on commit 105843d

Please sign in to comment.