From 105843d650bf8562bdcd09b2db4d4894eb0aac33 Mon Sep 17 00:00:00 2001 From: BugDiver Date: Sat, 1 Jun 2019 19:50:47 +0530 Subject: [PATCH] Add windwos support. --- .npmignore | 4 ++ README.md | 12 +++--- build.ps1 | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 3 +- launcher.bat | 2 +- launcher.js | 12 +++++- package.json | 2 +- ts.json | 6 +-- 8 files changed, 139 insertions(+), 13 deletions(-) create mode 100644 build.ps1 diff --git a/.npmignore b/.npmignore index 31c78ba..b56bf95 100644 --- a/.npmignore +++ b/.npmignore @@ -11,3 +11,7 @@ jest* TODO* ts* launcher.js +azure* +.gitmodules +*.ps1 +*.bat diff --git a/README.md b/README.md index ef8b355..8b81c6c 100644 --- a/README.md +++ b/README.md @@ -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) @@ -61,14 +60,14 @@ 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 @@ -76,13 +75,14 @@ To build the project dlls: 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. diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..e1e6dd9 --- /dev/null +++ b/build.ps1 @@ -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 +} \ No newline at end of file diff --git a/build.sh b/build.sh index 6ec98fc..c290b0d 100755 --- a/build.sh +++ b/build.sh @@ -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 diff --git a/launcher.bat b/launcher.bat index 4de1e30..e4af513 100755 --- a/launcher.bat +++ b/launcher.bat @@ -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 \ No newline at end of file diff --git a/launcher.js b/launcher.js index 29161b7..774f83a 100755 --- a/launcher.js +++ b/launcher.js @@ -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) { @@ -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", diff --git a/package.json b/package.json index 9e7f959..a1f008b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/ts.json b/ts.json index 921dee0..51a8839 100644 --- a/ts.json +++ b/ts.json @@ -12,7 +12,7 @@ "--start" ], "windows": [ - "index.bat", + "launcher.bat", "--start" ] }, @@ -26,8 +26,8 @@ "--init" ], "windows": [ - "index.bat", - "--start" + "launcher.bat", + "--init" ] }, "gaugeVersionSupport": {