-
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.
- Loading branch information
1 parent
238d4aa
commit 5ff128e
Showing
36 changed files
with
57,094 additions
and
16,436 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,9 @@ jobs: | |
strategy: | ||
matrix: | ||
node: | ||
- 14 | ||
- 16 | ||
- 18 | ||
- 20 | ||
steps: | ||
- uses: actions/setup-node@v3 | ||
with: | ||
|
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 |
---|---|---|
|
@@ -18,9 +18,9 @@ jobs: | |
strategy: | ||
matrix: | ||
node: | ||
- 14 | ||
- 16 | ||
- 18 | ||
- 20 | ||
steps: | ||
- uses: actions/setup-node@v3 | ||
with: | ||
|
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 |
---|---|---|
@@ -1,79 +1,87 @@ | ||
#!/usr/bin/env node | ||
|
||
import yargs from 'yargs'; | ||
import { hideBin } from 'yargs/helpers' | ||
import { hideBin } from 'yargs/helpers'; | ||
import { Generator, getDirectories } from '../src/generator.js'; | ||
import swaggerMerger from 'swagger-merger' | ||
import { cosmiconfigSync } from 'cosmiconfig' | ||
import openapiMerger from 'openapi-merger'; | ||
import { cosmiconfigSync } from 'cosmiconfig'; | ||
import Debug from 'debug'; | ||
import npmAddScript from 'npm-add-script' | ||
|
||
|
||
import npmAddScript from 'npm-add-script'; | ||
import PostmanConverter from 'openapi-to-postmanv2'; | ||
import fs from 'fs'; | ||
// import swagToStatic from './static.js' | ||
|
||
Debug.colors = [1,3,6,2,4,5]; | ||
const debug = Debug('foas') | ||
Debug.colors = [1, 3, 6, 2, 4, 5]; | ||
const debug = Debug('foas'); | ||
|
||
debug('booting %o', 'foas'); | ||
|
||
|
||
// **** Get cli arguments ****// | ||
const argv = yargs(hideBin(process.argv)) | ||
.option('config', { | ||
alias: 'c', | ||
type: 'string', | ||
description: 'set config file' | ||
}) | ||
.argv | ||
|
||
debug('argv %O', argv) | ||
|
||
|
||
const libName = 'feathers-oas' | ||
const searchPlaces = argv.config ? [argv.config] : [ | ||
'package.json', | ||
'.feathers-oas.json' | ||
] | ||
|
||
const explorer = cosmiconfigSync(libName,{searchPlaces}); | ||
const fullConfig = explorer.search() || {} | ||
let { config } = fullConfig | ||
|
||
|
||
if(argv._[0] === 'generate'){ | ||
|
||
let dirs = config?.entities || await getDirectories('./src/services') || [] | ||
for (const entity of dirs){ | ||
console.log(entity) | ||
let gen = new Generator(entity, fullConfig) | ||
await gen.init() | ||
await gen.generate() | ||
} | ||
|
||
const argv = yargs(hideBin(process.argv)).option('config', { | ||
alias: 'c', | ||
type: 'string', | ||
description: 'set config file' | ||
}).argv; | ||
|
||
debug('argv %O', argv); | ||
|
||
const libName = 'feathers-oas'; | ||
const searchPlaces = argv.config ? [argv.config] : ['package.json', '.feathers-oas.json']; | ||
|
||
const explorer = cosmiconfigSync(libName, { searchPlaces }); | ||
const fullConfig = explorer.search() || {}; | ||
const { config } = fullConfig; | ||
|
||
if (argv._[0] === 'generate') { | ||
const dirs = config?.entities || (await getDirectories('./src/services')) || []; | ||
for (const entity of dirs) { | ||
console.log(entity); | ||
const gen = new Generator(entity, fullConfig); | ||
await gen.init(); | ||
await gen.generate(); | ||
} | ||
} | ||
|
||
if(argv._[0] == 'merge'){ | ||
swaggerMerger({ | ||
input: './specifications/openapi/spec.yml', | ||
output: './specifications/openapi/_merged.yml', | ||
compact: false | ||
}).catch(e => { | ||
console.error(e) | ||
}) | ||
if (argv._[0] === 'merge') { | ||
openapiMerger({ | ||
input: './specifications/openapi/spec.yml', | ||
output: config.mergePath || './specifications/openapi/_merged.yml', | ||
compact: false | ||
}).catch(e => { | ||
console.error(e); | ||
}); | ||
} | ||
|
||
if(argv._[0] == 'swagger'){ | ||
if (argv._[0] === 'postman') { | ||
await fs.promises.mkdir('./specifications/postman/', { recursive: true }); | ||
const openapiData = fs.readFileSync('./specifications/openapi/_merged.yml', { encoding: 'UTF8' }); | ||
PostmanConverter.convert({ type: 'string', data: openapiData, parametersResolution: 'Example' }, {}, (err, conversionResult) => { | ||
if (err) { | ||
console.error(err); | ||
} | ||
if (!conversionResult.result) { | ||
console.log('Could not convert', conversionResult.reason); | ||
} else { | ||
fs.writeFileSync('./specifications/postman/postman.json', JSON.stringify(conversionResult.output[0].data)); | ||
console.log('Postman collection has been written to ./postman/postman.json'); | ||
} | ||
}); | ||
} | ||
|
||
// if (argv._[0] === 'swagger') { | ||
|
||
} | ||
// } | ||
|
||
if(argv._[0] == 'init'){ | ||
npmAddScript({key: "spec:build" , value: "npm run spec:generate; npm run spec:merge; npm run spec:validate; npm run spec:swagger"}) | ||
npmAddScript({key: "spec:merge" , value: "npx foas merge"}) | ||
npmAddScript({key: "spec:generate" , value: "npx foas generate"}) | ||
npmAddScript({key: "spec:validate" , value: "npx swagger-cli validate ./specifications/openapi/_merged.yml"}) | ||
npmAddScript({key: "spec:mock" , value: "npx @stoplight/prism-cli mock ./specifications/openapi/_merged.yml"}) | ||
npmAddScript({key: "spec:swagger'" , value: "node ./node_modules/swagger-to-static/index.js ./specifications/openapi/_merged.yml ./specifications/build"}) | ||
if (argv._[0] === 'init') { | ||
npmAddScript({ key: 'spec:build', value: 'npm run spec:generate; npm run spec:merge; npm run spec:validate; npm run spec:swagger' }); | ||
npmAddScript({ key: 'spec:merge', value: 'npx foas merge' }); | ||
npmAddScript({ key: 'spec:generate', value: 'npx foas generate' }); | ||
npmAddScript({ key: 'spec:validate', value: 'npx @redocly/cli lint --extends=minimal ./specifications/openapi/_merged.yml' }); | ||
npmAddScript({ key: 'spec:mock', value: 'npx @stoplight/prism-cli mock ./specifications/openapi/_merged.yml' }); | ||
npmAddScript({ | ||
key: 'spec:swagger', | ||
value: 'node ./node_modules/feathers-oas/node_modules/swagger-to-static/index.js ./specifications/openapi/_merged.yml ./specifications/build' | ||
}); | ||
} | ||
|
||
// "spec:swagger": "node ./node_modules/swagger-to-static/index.js ./specifications/openapi/_merged.yml ./specifications/build", |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// For more information about this file see https://dove.feathersjs.com/guides/cli/databases.html | ||
import { app } from './src/app.js' | ||
import { app } from './src/app.js'; | ||
|
||
// Load our database connection info from the app configuration | ||
const config = app.get('sqlite') | ||
const config = app.get('sqlite'); | ||
|
||
export default config | ||
export default config; |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
export async function up(knex) { | ||
export async function up (knex) { | ||
await knex.schema.createTable('books', (table) => { | ||
table.increments('id') | ||
table.string('text') | ||
}) | ||
table.increments('id'); | ||
table.string('text'); | ||
}); | ||
} | ||
|
||
export async function down(knex) { | ||
await knex.schema.dropTable('books') | ||
export async function down (knex) { | ||
await knex.schema.dropTable('books'); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
export async function up(knex) { | ||
export async function up (knex) { | ||
await knex.schema.createTable('ducks', (table) => { | ||
table.increments('id') | ||
table.string('text') | ||
}) | ||
table.increments('id'); | ||
table.string('text'); | ||
}); | ||
} | ||
|
||
export async function down(knex) { | ||
await knex.schema.dropTable('ducks') | ||
export async function down (knex) { | ||
await knex.schema.dropTable('ducks'); | ||
} |
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
Oops, something went wrong.