microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
269a1a0cecc92b3a0734a25526925bbcfaad50cc

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

npm/generate_samples_content.js

31lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// @ts-check
5
6import { readFileSync, writeFileSync } from "node:fs";
7import { dirname, join } from "node:path";
8import { fileURLToPath } from "node:url";
9
10import samples from "../samples/samples.mjs";
11
12const thisDir = dirname(fileURLToPath(import.meta.url));
13const sampleDir = join(thisDir, "..", "samples");
14const sampleGeneratedDir = join(thisDir, "src");
15
16const result = samples.map((sample) => {
17 const samplePath = join(sampleDir, sample.file);
18 const sampleText = readFileSync(samplePath, "utf8");
19 return {
20 title: sample.title,
21 shots: sample.shots,
22 code: sampleText,
23 };
24});
25
26const contentPath = join(sampleGeneratedDir, "samples.generated.ts");
27writeFileSync(
28 contentPath,
29 `export default ${JSON.stringify(result, undefined, 2)}`,
30 "utf-8"
31);
32