Skip to content

Commit

Permalink
Set up an internals/scripts package, and migrate start-example over (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinscott authored Oct 17, 2023
1 parent 8616d33 commit 9de1206
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 138 deletions.
67 changes: 67 additions & 0 deletions internals/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "@internals/scripts",
"private": true,
"type": "module",
"version": "0.1.0",
"description": "Scripts for managing the UpscalerJS Repo",
"exports": {
"./start-example": "./dist/bin/start-example.js",
".": "./dist/index.js"
},
"author": "Kevin Scott",
"license": "MIT",
"dependencies": {
"@internals/common": "workspace:*"
},
"scripts": {
"start-example": "wireit",
"build": "wireit",
"test:run": "wireit",
"test": "wireit"
},
"wireit": {
"start-example": {
"command": "node ./dist/bin/start-example.js",
"dependencies": [
"build"
]
},
"build": {
"command": "tsc -p ./tsconfig.json",
"dependencies": [
"../common:build"
],
"files": [
"src/**/*.ts",
"src/**/*.mts",
"!src/**/*.test.ts",
"!src/**/*.test.mts",
"package.json",
"vite.config.ts",
"tsconfig.json"
],
"output": [
"dist/**"
]
},
"test:run": {
"command": "vitest run --config ./vite.config.ts",
"dependencies": [
"../common:build"
]
},
"test": {
"command": "vitest --config ./vite.config.ts",
"dependencies": [
"../common:build"
]
}
},
"engines": {
"node": ">=20.0.0"
},
"devDependencies": {
"wireit": "latest",
"vitest": "^0.34.2"
}
}
48 changes: 48 additions & 0 deletions internals/scripts/src/bin/start-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*****
* This script spins up a local instance of a particular example, and sets up a watch command to build UpscalerJS.
*/

import path from 'path';
import { spawn } from 'child_process';
import { EXAMPLES_DIR } from '@internals/common/constants';
import { stat, exists } from '@internals/common/fs';
import { parseArgs } from "node:util";

/****
* Main function
*/

const startExample = (example: string) => {
const examplePath = path.resolve(EXAMPLES_DIR, example);

const command = 'npm install --force --no-package-lock && npm run dev'.split(' ');

return spawn(command[0], command.slice(1), {
shell: true,
cwd: examplePath,
stdio: "inherit"
});
};


const isValidExample = async (exampleDirectory: string) => {
const examplePath = path.resolve(EXAMPLES_DIR, exampleDirectory);
return await exists(examplePath) && (await stat(examplePath)).isDirectory();
};

const main = async () => {
const {
positionals: [
exampleDirectory,
]
} = parseArgs({
allowPositionals: true,
});

if (!await isValidExample(exampleDirectory)) {
throw new Error(`Example directory does not exist: "${exampleDirectory}"`);
}
startExample(exampleDirectory);
};

main();
Empty file added internals/scripts/src/index.ts
Empty file.
9 changes: 9 additions & 0 deletions internals/scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
},
"include": ["./src/**/*.ts", "./src/**/*.mts"],
"exclude": ["./src/**/*.test.ts", "./src/**/*.test.mts"],
}
5 changes: 5 additions & 0 deletions internals/scripts/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig, mergeConfig } from 'vitest/config';
import configShared from '../vite.config';

export default mergeConfig(configShared, defineConfig({
}));
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@internals/bundlers": "workspace:*",
"@internals/common": "workspace:*",
"@internals/http-server": "workspace:*",
"@internals/scripts": "workspace:*",
"@internals/test-runner": "workspace:*",
"@internals/upscaler-cli": "workspace:*",
"@internals/webdriver": "workspace:*",
Expand Down
69 changes: 21 additions & 48 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
"docs:build-guides": "pnpm __run_command ./package-scripts/docs/build-guides.ts",
"docs:link-model-readmes": "pnpm __run_command ./package-scripts/docs/link-model-readmes.ts",
"docs:tense-checks": "pnpm __run_command ./package-scripts/docs/tense-checks.ts",
"example:start": "pnpm __run_command ./start-example.ts",
"find-all-packages": "pnpm __run_command ./package-scripts/find-all-packages.ts",
"model:benchmark:performance": "pnpm __run_command ./package-scripts/benchmark/performance/index.ts",
"model:benchmark:speed": "pnpm __run_command ./package-scripts/benchmark/speed/index.ts",
"model:clean": "pnpm __run_command ./package-scripts/clean-model.ts",
"model:convert-python-model": "pnpm __run_command ./package-scripts/convert-python-model.ts",
"model:convert-python-model-folder": "pnpm __run_command ./package-scripts/convert-python-model-folder.ts",
Expand Down
86 changes: 0 additions & 86 deletions scripts/start-example.ts

This file was deleted.

0 comments on commit 9de1206

Please sign in to comment.