Substitute ${VERSION} on Windows builds too

This change refactors the way we do ${VERSION} substitution in both
the Node.js SDK's version.js and package.json, so that it can work on
Windows.  This is required now that we are actually parsing semvers.
This commit is contained in:
joeduffy 2018-02-20 14:19:16 -08:00
parent 09a819f801
commit 88dcdd8d2b
3 changed files with 26 additions and 8 deletions

View file

@ -55,8 +55,13 @@
</Target>
<Target Name="TypeScriptCompileNodeSdk">
<Exec Command="yarn run tsc"
WorkingDirectory="$(NodeJSSdkDirectory)" />
<Exec Command="git describe --tags 2>nul" ConsoleToMSBuild="true" Condition="'$(Version)' == ''">
<Output TaskParameter="ConsoleOutput" PropertyName="Version" />
</Exec>
<Exec Command="yarn run tsc" WorkingDirectory="$(NodeJSSdkDirectory)" />
<Copy SourceFiles="$(NodeJSSdkDirectory)\package.json" DestinationFiles="$(NodeJSSdkDirectory)\bin\package.json" />
<Exec Command="node $(RepoRootDirectory)\scripts\reversion.js $(NodeJSSdkDirectory)\bin\package.json $(Version)" />
<Exec Command="node $(RepoRootDirectory)\scripts\reversion.js $(NodeJSSdkDirectory)\bin\version.js $(Version)" />
</Target>
<Target Name="GoCompileNodeSdk">
@ -102,8 +107,6 @@
</Target>
<Target Name="YarnLinkSdk">
<Copy SourceFiles="$(NodeJSSdkDirectory)\package.json"
DestinationFiles="$(NodeJSSdkDirectory)\bin\package.json" />
<Exec Command="yarn link"
WorkingDirectory="$(NodeJSSdkDirectory)\bin" />
</Target>

16
scripts/reversion.js Normal file
View file

@ -0,0 +1,16 @@
// Copyright 2018, Pulumi Corporation. All rights reserved.
var fs = require("fs");
if (process.argv.length < 4) {
console.error("error: missing arguments; usage: <script> <file> <version>");
process.exit(1);
}
var file = process.argv[2];
var data = fs.readFileSync(file).toString("utf8");
var version = process.argv[3];
if (version && version[0] === "v") {
version = version.substring(1);
}
fs.writeFileSync(file, data.replace(/\${VERSION}/g, version));

View file

@ -29,10 +29,9 @@ build::
cp -R ../proto/nodejs/. proto/
cd runtime/native && node-gyp build
tsc
cp README.md ../../LICENSE package.json bin/
cp ./dist/* bin/
sed -i.bak "s/\$${VERSION}/$(VERSION)/g" bin/version.js bin/package.json && \
rm bin/version.js.bak bin/package.json.bak
cp README.md ../../LICENSE package.json ./dist/* bin/
node ../../scripts/reversion.js bin/package.json ${VERSION}
node ../../scripts/reversion.js bin/version.js ${VERSION}
cp -R proto/. bin/proto/
mkdir -p bin/tests/runtime/langhost/cases/
find tests/runtime/langhost/cases/* -type d -exec cp -R {} bin/tests/runtime/langhost/cases/ \;