Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {exec} from "child_process";
import {access} from "fs/promises"
import {parseArgs, ParseArgsConfig} from 'node:util';
import { exec } from "child_process";
import { access } from "fs/promises"
import { parseArgs, ParseArgsConfig } from 'node:util';
import path from "path";
import {simpleGit} from 'simple-git';
import { simpleGit } from 'simple-git';

async function runCmd(cmd:string, cwd:string) {
async function runCmd(cmd: string, cwd: string) {
console.log(`run command:${cmd}`)
const { err, stdout, stderr } = await new Promise((res) =>
exec(
cmd,
{ encoding: "utf8", maxBuffer: 1024 * 1024 * 64, cwd: cwd},
(err: unknown, stdout: unknown, stderr: unknown) =>
res({ err: err, stdout: stdout, stderr: stderr })
cmd,
{ encoding: "utf8", maxBuffer: 1024 * 1024 * 64, cwd: cwd },
(err: unknown, stdout: unknown, stderr: unknown) =>
res({ err: err, stdout: stdout, stderr: stderr })
)
) as any;
let resultString = stderr + stdout;
Expand All @@ -27,21 +27,21 @@ async function runCmd(cmd:string, cwd:string) {
return resultString as string;
}

async function checkFileExists(file:string) {
async function checkFileExists(file: string) {
return access(file)
.then(() => true)
.catch(() => false)
}

export async function main() {
const args = process.argv.slice(2);
const options = {
folder: {
type: 'string',
short: 'f',
type: 'string',
short: 'f',
},
};
const parsedArgs = parseArgs({ args, options, allowPositionals: true} as ParseArgsConfig);
const parsedArgs = parseArgs({ args, options, allowPositionals: true } as ParseArgsConfig);
const folder = parsedArgs.positionals[0];
console.log("Running TypeSpecValidation on folder:", folder);

Expand All @@ -50,7 +50,7 @@ export async function main() {
const actual_npm_prefix = (await runCmd(`npm prefix`, folder)).trim()
if (expected_npm_prefix !== actual_npm_prefix) {
console.log("ERROR: TypeSpec folders MUST NOT contain a package.json, and instead MUST rely on the package.json at repo root.")
throw new Error ("Expected npm prefix: " + expected_npm_prefix +"\nActual npm prefix: " + actual_npm_prefix)
throw new Error("Expected npm prefix: " + expected_npm_prefix + "\nActual npm prefix: " + actual_npm_prefix)
}

// Spec compilation check
Expand Down