Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TS to use the same paths for build&test for loading package.json #55

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
"scripts": {
"create": "node ./dist/cli/create.js",
"start": "node ./dist/cli/start.js -c ./ai-warp-app/platformatic.json",
"build": "tsc --build && cp -r ./static ./dist/ && cp config.d.ts dist/",
"build:config": "npm run build && node ./dist/lib/schema.js --dump-schema > schema.json && json2ts > config.d.ts < schema.json",
"build": "tsc --build && cp -r ./static ./dist/ && cp src/config.d.ts dist/",
"build:config": "npm run build && node ./dist/lib/schema.js --dump-schema > schema.json && json2ts > src/config.d.ts < schema.json",
"prepare": "npm run build:config",
"clean": "rm -fr ./dist",
"lint": "ts-standard | snazzy",
"lint:fix": "ts-standard --fix | snazzy",
"lint-md": "markdownlint-cli2 .",
"lint-md:fix": "markdownlint-cli2 --fix .",
"test": "npm run test:unit && npm run test:e2e && npm run test:types",
"test:unit": "node --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=spec --test-reporter-destination=stdout --import=tsx --test-concurrency=1 ./tests/unit/*",
"test:e2e": "node --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=spec --test-reporter-destination=stdout --import=tsx --test-concurrency=1 ./tests/e2e/*",
"test:unit": "node --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=spec --test-reporter-destination=stdout --import=tsx --test-concurrency=1 ./src/tests/unit/*",
"test:e2e": "node --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=spec --test-reporter-destination=stdout --import=tsx --test-concurrency=1 ./src/tests/e2e/*",
"test:types": "tsd"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$id": "ai-warp",
"version": "1.37.1",
"version": "0.3.1",
"title": "Ai Warp Config",
"type": "object",
"properties": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 3 additions & 7 deletions config.d.ts → src/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,9 @@ export interface AiWarpConfig {
prefix?: string;
path?: string;
};
plugins?:
| {
[k: string]: unknown;
}
| {
[k: string]: unknown;
};
plugins?: {
[k: string]: unknown;
};
}[];
};
module?: string;
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 4 additions & 7 deletions lib/generator.ts → src/lib/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@
devDependencies: Record<string, string>
}

const dir = import.meta.dirname || dirname(fileURLToPath(import.meta.url))

Check failure on line 16 in src/lib/generator.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected string value in conditional. An explicit empty string check is required
const aiWarpPackageJsonPath = join(dir, '..', '..', 'package.json')

class AiWarpGenerator extends ServiceGenerator {
private _packageJson: PackageJson | null = null

getDefaultConfig (): { [x: string]: BaseGenerator.JSONValue } {
const defaultBaseConfig = super.getDefaultConfig()
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
const dir = import.meta.dirname || dirname(fileURLToPath(import.meta.url))
const defaultConfig = {
aiProvider: 'openai',
aiModel: 'gpt-3.5-turbo',
localSchema: false,

Check failure on line 28 in src/lib/generator.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected trailing comma
// TODO: temporary fix, when running the typescript files directly
// (in tests) this goes a directory above the actual project. Exposing
// temporarily until I come up with something better
aiWarpPackageJsonPath: join(dir, '..', '..', 'package.json')
}
return Object.assign({}, defaultBaseConfig, defaultConfig)
}
Expand Down Expand Up @@ -175,8 +173,7 @@

async getStackablePackageJson (): Promise<PackageJson> {
if (this._packageJson == null) {
const packageJsonPath = this.config.aiWarpPackageJsonPath
const packageJsonFile = await readFile(packageJsonPath, 'utf8')
const packageJsonFile = await readFile(aiWarpPackageJsonPath, 'utf8')
const packageJson: Partial<PackageJson> = JSON.parse(packageJsonFile)

if (packageJson.name === undefined || packageJson.name === null) {
Expand Down
5 changes: 5 additions & 0 deletions lib/schema.ts → src/lib/schema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { join } from 'node:path'
import { readFileSync } from 'node:fs'
import { schema } from '@platformatic/service'

const { version } = JSON.parse(readFileSync(join(import.meta.dirname, '..', '..', 'package.json'), 'utf-8'))

const aiWarpSchema = {
...schema.schema,
$id: 'ai-warp',
title: 'Ai Warp Config',
version,
properties: {
...schema.schema.properties,
module: { type: 'string' },
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ describe('AiWarpGenerator', () => {
const generator = new AiWarpGenerator()
generator.setConfig({
targetDirectory: dir,
aiWarpPackageJsonPath: join(import.meta.dirname, '..', '..', 'package.json'),
aiProvider: 'openai',
aiModel: 'gpt-3.5-turbo'
})
Expand All @@ -57,7 +56,6 @@ describe('AiWarpGenerator', () => {
const generator = new AiWarpGenerator()
generator.setConfig({
targetDirectory: dir,
aiWarpPackageJsonPath: join(import.meta.dirname, '..', '..', 'package.json'),
aiProvider: 'openai',
aiModel: 'gpt-3.5-turbo'
})
Expand All @@ -77,7 +75,6 @@ describe('AiWarpGenerator', () => {
const generator = new AiWarpGenerator()
generator.setConfig({
targetDirectory: dir,
aiWarpPackageJsonPath: join(import.meta.dirname, '..', '..', 'package.json'),
aiProvider: 'openai',
aiModel: 'gpt-3.5-turbo'
})
Expand Down Expand Up @@ -112,7 +109,6 @@ describe('AiWarpGenerator', () => {
const generator = new AiWarpGenerator()
generator.setConfig({
targetDirectory: dir,
aiWarpPackageJsonPath: join(import.meta.dirname, '..', '..', 'package.json'),
aiProvider: 'openai',
aiModel: 'gpt-3.5-turbo'
})
Expand All @@ -128,7 +124,6 @@ describe('AiWarpGenerator', () => {
const generator = new AiWarpGenerator()
generator.setConfig({
targetDirectory: dir,
aiWarpPackageJsonPath: join(import.meta.dirname, '..', '..', 'package.json'),
aiProvider: 'openai',
aiModel: 'gpt-3.5-turbo',
plugin: true
Expand All @@ -148,7 +143,6 @@ describe('AiWarpGenerator', () => {
const generator = new AiWarpGenerator()
generator.setConfig({
targetDirectory: dir,
aiWarpPackageJsonPath: join(import.meta.dirname, '..', '..', 'package.json'),
aiProvider: 'openai',
aiModel: 'gpt-3.5-turbo',
plugin: true,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading