-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Port build and test scripts to Windows * Port generate script to JS * Use TypeScript for generate script * Require glob after NPM install * Alter generate to work before first install * Remove unnecessary types * Reinstall NPM packages using .nvmrc Node version
- Loading branch information
1 parent
c511ff3
commit 7a65c0d
Showing
9 changed files
with
1,985 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@IF EXIST "%~dp0\node.exe" ( | ||
"%~dp0\node.exe" "%~dp0\..\lib\index.js" %* | ||
) ELSE ( | ||
@SETLOCAL | ||
@SET PATHEXT=%PATHEXT:;.JS;=;% | ||
node "%~dp0\..\lib\index.js" %* | ||
) |
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,101 @@ | ||
const { spawnSync } = require("child_process"); | ||
|
||
const { existsSync, mkdirSync } = require("fs"); | ||
const { resolve } = require("path"); | ||
|
||
const protocVersion = "3.5.1"; | ||
|
||
const examplesGeneratedPath = resolve(__dirname, "examples", "generated"); | ||
|
||
const binSuffix = process.platform === "win32" ? ".cmd" : ""; | ||
const nodeModulesBin = resolve(__dirname, "node_modules", ".bin"); | ||
|
||
const downloadPath = resolve(nodeModulesBin, "download") + binSuffix; | ||
|
||
const protocRoot = resolve(__dirname, "protoc"); | ||
const protocPath = resolve(protocRoot, "bin", "protoc"); | ||
|
||
const protocPluginPath = resolve(__dirname, "bin", "protoc-gen-ts") + binSuffix; | ||
|
||
const rimrafPath = resolve(nodeModulesBin, "rimraf") + binSuffix; | ||
|
||
const supportedPlatforms = { | ||
darwin: { | ||
downloadSuffix: "osx-x86_64", | ||
name: "Mac" | ||
}, | ||
linux: { | ||
downloadSuffix: "linux-x86_64", | ||
name: "Linux" | ||
}, | ||
win32: { | ||
downloadSuffix: "win32", | ||
name: "Windows" | ||
} | ||
}; | ||
|
||
const platform = supportedPlatforms[process.platform]; | ||
const platformName = platform ? | ||
platform.name : | ||
`UNKNOWN:${process.platform}`; | ||
console.log("You appear to be running on", platformName); | ||
|
||
requireBuild(); | ||
|
||
const glob = require("glob"); | ||
|
||
requireProtoc(); | ||
|
||
if (existsSync(examplesGeneratedPath)) { | ||
run(rimrafPath, examplesGeneratedPath); | ||
} | ||
|
||
mkdirSync(examplesGeneratedPath); | ||
|
||
run(protocPath, | ||
`--proto_path=${__dirname}`, | ||
`--plugin=protoc-gen-ts=${protocPluginPath}`, | ||
`--js_out=import_style=commonjs,binary:${examplesGeneratedPath}`, | ||
`--ts_out=service=true:${examplesGeneratedPath}`, | ||
...glob.sync(resolve(__dirname, "proto", "**/*.proto")) | ||
); | ||
|
||
run(rimrafPath, protocRoot); | ||
|
||
function requireBuild() { | ||
console.log("Ensuring we have NPM packages installed..."); | ||
run("npm", "install"); | ||
|
||
console.log("Compiling ts-protoc-gen..."); | ||
run("npm", "run", "build"); | ||
} | ||
|
||
function requireProtoc() { | ||
if (existsSync(protocPath)) { | ||
return; | ||
} | ||
|
||
if (!platform) { | ||
throw new Error( | ||
"Cannot download protoc. " + | ||
platformName + | ||
" is not currently supported by ts-protoc-gen" | ||
); | ||
} | ||
|
||
console.log(`Downloading protoc v${protocVersion} for ${platform.name}`); | ||
const protocUrl = | ||
`https://github.com/google/protobuf/releases/download/v${protocVersion}/protoc-${protocVersion}-${platform.downloadSuffix}.zip`; | ||
|
||
run(downloadPath, | ||
"--extract", | ||
"--out", protocRoot, | ||
protocUrl); | ||
} | ||
|
||
function run(executablePath, ...args) { | ||
const result = spawnSync(executablePath, args, { shell: true, stdio: "inherit" }); | ||
if (result.status !== 0) { | ||
throw new Error(`Exited ${executablePath} with status ${result.status}`); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.