forked from zenstackhq/zenstack
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support object literal in plugin fields processing (zenstackhq#351)
- Loading branch information
Showing
20 changed files
with
108 additions
and
19 deletions.
There are no files selected for viewing
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/// <reference types="@types/jest" /> | ||
|
||
import { getWorkspaceNpmCacheFolder } from '@zenstackhq/testtools'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as tmp from 'tmp'; | ||
import { createProgram } from '../../src/cli'; | ||
|
||
describe('CLI Plugins Tests', () => { | ||
let projDir: string; | ||
let origDir: string; | ||
|
||
beforeEach(() => { | ||
origDir = process.cwd(); | ||
const r = tmp.dirSync(); | ||
projDir = r.name; | ||
console.log(`Project dir: ${projDir}`); | ||
process.chdir(projDir); | ||
}); | ||
|
||
afterEach(() => { | ||
// fs.rmSync(projDir, { recursive: true, force: true }); | ||
process.chdir(origDir); | ||
}); | ||
|
||
function createNpmrc() { | ||
fs.writeFileSync('.npmrc', `cache=${getWorkspaceNpmCacheFolder(__dirname)}`); | ||
} | ||
|
||
const plugins = [ | ||
`plugin prisma { | ||
provider = '@core/prisma' | ||
output = 'prisma/my.prisma' | ||
generateClient = true | ||
}`, | ||
`plugin meta { | ||
provider = '@core/model-meta' | ||
output = 'model-meta' | ||
} | ||
`, | ||
`plugin policy { | ||
provider = '@core/access-policy' | ||
output = 'policy' | ||
}`, | ||
`plugin zod { | ||
provider = '@core/zod' | ||
output = 'zod' | ||
}`, | ||
`plugin react { | ||
provider = '${path.join(__dirname, '../../../plugins/react/dist')}' | ||
output = 'lib/default-hooks' | ||
}`, | ||
`plugin trpc { | ||
provider = '${path.join(__dirname, '../../../plugins/trpc/dist')}' | ||
output = 'lib/trpc' | ||
}`, | ||
`plugin openapi { | ||
provider = '${path.join(__dirname, '../../../plugins/openapi/dist')}' | ||
output = 'myapi.yaml' | ||
specVersion = '3.0.0' | ||
title = 'My Awesome API' | ||
version = '1.0.0' | ||
description = 'awesome api' | ||
prefix = '/myapi' | ||
securitySchemes = { | ||
myBasic: { type: 'http', scheme: 'basic' }, | ||
myBearer: { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }, | ||
myApiKey: { type: 'apiKey', in: 'header', name: 'X-API-KEY' } | ||
} | ||
}`, | ||
]; | ||
|
||
it('all plugins', async () => { | ||
fs.writeFileSync('package.json', JSON.stringify({ name: 'my app', version: '1.0.0' })); | ||
createNpmrc(); | ||
const program = createProgram(); | ||
await program.parseAsync(['init', '--tag', 'latest'], { from: 'user' }); | ||
|
||
let schemaContent = fs.readFileSync('schema.zmodel', 'utf-8'); | ||
for (const plugin of plugins) { | ||
schemaContent += `\n${plugin}`; | ||
} | ||
fs.writeFileSync('schema.zmodel', schemaContent); | ||
await program.parseAsync(['generate', '--no-dependency-check'], { from: 'user' }); | ||
}); | ||
}); |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.