-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download the template from the examples repo (#24)
* Download the template from the examples repo * Apply suggestions from code review Co-authored-by: Giselle van Dongen <giselle.vd@gmail.com> --------- Co-authored-by: Giselle van Dongen <giselle.vd@gmail.com>
- Loading branch information
1 parent
f5ebb5c
commit e181e30
Showing
22 changed files
with
1,393 additions
and
1,648 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,41 +1,36 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require("fs"); | ||
const path = require("path"); | ||
const unzipper = require("unzipper"); | ||
|
||
async function unzipTemplate(grpc) { | ||
const archiveName = grpc ? "node-grpc-template.zip" : "node-template.zip"; | ||
const templatePath = path.join(__dirname, "..", "data", archiveName); | ||
const outputPath = process.cwd(); | ||
async function main() { | ||
console.log(`Creating Restate project template for TypeScript...`); | ||
|
||
await fs | ||
.createReadStream(templatePath) | ||
.pipe(unzipper.Extract({ path: outputPath })) | ||
.promise(); | ||
} | ||
const TEMPLATE_LOCATION = | ||
"https://github.com/restatedev/examples/releases/latest/download/typescript-hello-world.zip"; | ||
|
||
let grpcVariant = false; | ||
process.argv.slice(2).forEach((arg) => { | ||
if (arg === "--grpc") { | ||
grpcVariant = true; | ||
} else { | ||
console.error("Unrecognized argument: " + arg); | ||
process.exit(1); | ||
const response = await fetch(TEMPLATE_LOCATION); | ||
if (response.status < 200 || response.status >= 300) { | ||
throw new Error(response.statusText); | ||
} | ||
}); | ||
|
||
console.log( | ||
`Creating Restate project template for TypeScript ${ | ||
grpcVariant ? "(gRPC version)" : "" | ||
}...` | ||
); | ||
// https://github.com/ZJONSSON/node-unzipper/issues/292 | ||
const responseBodyBuffer = Buffer.from( | ||
new Uint8Array(await response.arrayBuffer()) | ||
); | ||
|
||
const outputPath = process.cwd(); | ||
const zip = await unzipper.Open.buffer(responseBodyBuffer); | ||
await zip.extract({ path: outputPath }); | ||
|
||
console.log("...Done"); | ||
} | ||
|
||
unzipTemplate(grpcVariant) | ||
// POSIX compliant apps should report an exit status | ||
main() | ||
.then(() => { | ||
console.log("...Done"); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.error("Failed to unzip project template: " + err); | ||
console.error(err.stack); | ||
console.error(err); // Writes to stderr | ||
process.exit(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import globals from "globals"; | ||
import pluginJs from "@eslint/js"; | ||
|
||
export default [ | ||
pluginJs.configs.recommended, | ||
{ | ||
files: ["**/*.js"], | ||
languageOptions: { | ||
sourceType: "commonjs", | ||
globals: globals.node, | ||
ecmaVersion: "latest" | ||
} | ||
} | ||
]; |
Oops, something went wrong.