@swyger/cli
Advanced tools
Comparing version 0.1.2 to 0.1.4
383
bin/index.js
#!/usr/bin/env node | ||
// Run `npm run start` to start the demo | ||
import { | ||
@@ -11,3 +12,3 @@ intro, | ||
cancel, | ||
text, | ||
text, multiselect, | ||
} from '@clack/prompts'; | ||
@@ -29,3 +30,3 @@ import { setTimeout as sleep } from 'node:timers/promises'; | ||
//console.log(usage); | ||
console.log(usage); | ||
let args=hideBin(process.argv) //Or process.argv.slice(2) | ||
@@ -63,3 +64,6 @@ | ||
message: 'What is your server name?', | ||
placeholder: 'swyger', | ||
placeholder: 'swyger-clone', | ||
validate(value) { | ||
if (value.length === 0) return `Value is required!`; | ||
} | ||
}); | ||
@@ -73,2 +77,3 @@ | ||
} | ||
app.name=app.name.toLowerCase() | ||
@@ -94,2 +99,6 @@ | ||
}); | ||
if (isCancel(sideType)) { | ||
cancel('Operation cancelled'); | ||
return process.exit(0); | ||
} | ||
app.sideType=sideType | ||
@@ -99,129 +108,178 @@ } | ||
let serviceType | ||
let apiClientType | ||
let serverLanguageType | ||
let projectFolder='./'+app.name | ||
let shouldUseApiClient | ||
let projectUrl | ||
const projectSpinner = spinner(); | ||
let repo | ||
switch (app?.sideType) { | ||
case 'server': | ||
serviceType = await select({ | ||
message: 'Pick a service you need', | ||
serverLanguageType=await select({ | ||
message: 'Pick your Language', | ||
options: [ | ||
{ value: 'all', label: 'All services(auth,database,storage...)' }, | ||
{ value: 'auth', label: 'This will create only an auth server (register,login,refresh token...)' }, | ||
{ value: 'database', label: 'This will create only a database server(create,read,update,delete data in realtime)' }, | ||
//{ value: 'storage', label: 'This will create only a storage server', hint: 'oh no' }, | ||
{ value: 'storage', label: 'This will create only a storage server(create,read,update,delete file in realtime)'}, | ||
{ value: 'node-js', label: 'Create the server with NodeJS' }, | ||
], | ||
}); | ||
if (isCancel(serviceType)) { | ||
}) | ||
if (isCancel(serverLanguageType)) { | ||
cancel('Operation cancelled'); | ||
return process.exit(0); | ||
} | ||
await git.clone('https://github.com/coorise/swyger-nodejs-base.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-base')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-base/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-base/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/base' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-base/package.json", JSON.stringify(jsonData,null, 4)) | ||
switch (serverLanguageType) { | ||
case 'node-js': | ||
serviceType = await select({ | ||
message: 'Pick a service you need', | ||
options: [ | ||
{ value: 'all', label: 'All services(auth,database,storage...)' }, | ||
{ value: 'auth', label: 'This will create only an auth server (register,login,refresh token...)' }, | ||
{ value: 'database', label: 'This will create only a database server(create,read,update,delete data in realtime)' }, | ||
//{ value: 'storage', label: 'This will create only a storage server', hint: 'oh no' }, | ||
{ value: 'storage', label: 'This will create only a storage server(create,read,update,delete file in realtime)'}, | ||
], | ||
}); | ||
if (isCancel(serviceType)) { | ||
cancel('Operation cancelled'); | ||
return process.exit(0); | ||
} | ||
fs.moveSync('./swyger-nodejs-base',projectFolder+'/server/base') | ||
} | ||
}) | ||
switch (serviceType) { | ||
case 'all': | ||
await git.clone('https://github.com/coorise/swyger-nodejs-auth.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-auth/package.json", "utf8") | ||
repo='https://github.com/coorise/swyger-nodejs-base.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-base')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-base/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-base/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/auth' | ||
jsonData.name='@'+app.name+'/base' | ||
jsonData.version='0.1.0' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-auth/package.json", JSON.stringify(jsonData,null, 4)) | ||
fs.writeFileSync("./swyger-nodejs-base/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-auth',projectFolder+'/server/auth') | ||
fs.moveSync('./swyger-nodejs-base',projectFolder+'/server/base') | ||
} | ||
}) | ||
await git.clone('https://github.com/coorise/swyger-nodejs-database.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-database')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-database/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-database/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/database' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-database/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-database',projectFolder+'/server/database') | ||
} | ||
}) | ||
await git.clone('https://github.com/coorise/swyger-nodejs-storage.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-storage/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/storage' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-storage/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-storage',projectFolder+'/server/storage') | ||
} | ||
}) | ||
switch (serviceType) { | ||
case 'all': | ||
repo='https://github.com/coorise/swyger-nodejs-auth.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-auth/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/auth' | ||
jsonData.version='0.1.0' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-auth/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-auth',projectFolder+'/server/auth') | ||
} | ||
}) | ||
repo='https://github.com/coorise/swyger-nodejs-database.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-database')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-database/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-database/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/database' | ||
jsonData.version='0.1.0' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-database/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-database',projectFolder+'/server/database') | ||
} | ||
}) | ||
repo='https://github.com/coorise/swyger-nodejs-storage.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-storage/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/storage' | ||
jsonData.version='0.1.0' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-storage/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-storage',projectFolder+'/server/storage') | ||
} | ||
}) | ||
break; | ||
case 'auth': | ||
repo='https://github.com/coorise/swyger-nodejs-auth.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-auth/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/auth' | ||
jsonData.version='0.1.0' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-auth/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-auth',projectFolder+'/server/auth') | ||
} | ||
}) | ||
break; | ||
case 'database': | ||
repo='https://github.com/coorise/swyger-nodejs-database.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-database')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-database/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-database/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/database' | ||
jsonData.version='0.1.0' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-database/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-database',projectFolder+'/server/database') | ||
} | ||
}) | ||
break; | ||
case 'storage': | ||
repo='https://github.com/coorise/swyger-nodejs-storage.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-storage/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/storage' | ||
jsonData.version='0.1.0' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-storage/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-storage',projectFolder+'/server/storage') | ||
} | ||
}) | ||
break; | ||
} | ||
app.serviceType=serviceType | ||
break; | ||
case 'auth': | ||
await git.clone('https://github.com/coorise/swyger-nodejs-auth.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-auth/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/auth' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-auth/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-auth',projectFolder+'/server/auth') | ||
} | ||
}) | ||
break; | ||
case 'database': | ||
await git.clone('https://github.com/coorise/swyger-nodejs-database.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-database')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-database/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-database/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/database' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-database/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-database',projectFolder+'/server/database') | ||
} | ||
}) | ||
break; | ||
case 'storage': | ||
await git.clone('https://github.com/coorise/swyger-nodejs-storage.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-storage/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/storage' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-storage/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-storage',projectFolder+'/server/storage') | ||
} | ||
}) | ||
break; | ||
} | ||
app.serviceType=serviceType | ||
break; | ||
case 'client': | ||
projectType = await select({ | ||
message: 'What is the client type you want to build?', | ||
message: 'What is the platform you want to build?', | ||
options: [ | ||
{ value: 'browser', label: 'Html/CSS SPA Boilerplate + Rest Api consumer' }, | ||
{ value: 'browser', label: 'Bowser: Html/CSS SPA Boilerplate to create Static Website (like NuxtJS, NextJS...)' }, | ||
], | ||
@@ -234,7 +292,37 @@ }); | ||
} | ||
shouldUseApiClient=await confirm({ | ||
message: 'Do you want to add swyger api consumer client (auth,database,storage...)?', | ||
}) | ||
if (isCancel(shouldUseApiClient)) { | ||
cancel('Operation cancelled'); | ||
return process.exit(0); | ||
} | ||
if(shouldUseApiClient){ | ||
apiClientType = await multiselect({ | ||
message: 'What is the client api type you want to build? (Select: Space bar |__|, Enter: Continue', | ||
options: [ | ||
{ value: 'all', label: 'All Rest Api consumer(authentication,database,storage...)' }, | ||
{ value: 'auth', label: 'Auth Rest Api consumer' }, | ||
//{ value: 'database', label: 'Database Rest Api consumer' }, | ||
//{ value: 'storage', label: 'Storage Rest Api consumer' }, | ||
], | ||
}); | ||
if (isCancel(apiClientType)) { | ||
cancel('Operation cancelled'); | ||
return process.exit(0); | ||
} | ||
} | ||
switch (projectType) { | ||
case 'browser': | ||
await git.clone('https://github.com/coorise/swyger-browser.git', 'master')?.then(()=>{ | ||
projectUrl='swyger-spa.git' | ||
if(shouldUseApiClient){ | ||
projectUrl='swyger-browser.git' | ||
} | ||
repo='https://github.com/coorise/'+projectUrl | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-browser')){ | ||
if(fs.pathExistsSync('./swyger-browser/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-browser/package.json", "utf8") | ||
@@ -244,4 +332,74 @@ // Use JSON.parse to convert string to JSON Object | ||
jsonData.name='@'+app.name+'/browser' | ||
jsonData.version='0.1.0' | ||
if(!apiClientType.includes('all')){ | ||
let fileImport='' | ||
let client="const SwygerClient= {\n" + | ||
" init:(ClientConfig)=>{\n" + | ||
"\n" + | ||
" return {\n" | ||
delete jsonData.dependencies['@swyger/client'] | ||
if(apiClientType.includes('auth')) { | ||
jsonData.dependencies['@swyger/client-auth'] = 'latest' | ||
fileImport="import SwygerAuthClient from '@swyger/client-auth'\n" | ||
client=client+" auth:SwygerAuthClient.init(ClientConfig),\n" | ||
}else{ | ||
if(fs.pathExistsSync('./swyger-browser/src/app/rest/core/index.js')){ | ||
let coreData = fs.readFileSync("./swyger-browser/src/app/rest/core/index.js", "utf8") | ||
coreData=coreData.replace(/import AuthModule?\n/,'') | ||
coreData=coreData.replace(/...AuthModule,/,'') | ||
fs.writeFileSync("./swyger-browser/src/app/rest/core/index.js", coreData) | ||
} | ||
if(fs.pathExistsSync('./swyger-browser/static/public/themes/dashui/app/core/auth')){ | ||
fs.removeSync('./swyger-browser/static/public/themes/dashui/app/core/auth') | ||
} | ||
} | ||
if(apiClientType.includes('database')) { | ||
jsonData.dependencies['@swyger/client-database'] = 'latest' | ||
fileImport=fileImport+"import SwygerDatabaseClient from '@swyger/client-database'\n" | ||
client=client+" database:SwygerDatabaseClient.init(ClientConfig),\n" | ||
}else{ | ||
if(fs.pathExistsSync('./swyger-browser/src/app/rest/core/index.js')){ | ||
let coreData = fs.readFileSync("./swyger-browser/src/app/rest/core/index.js", "utf8") | ||
coreData=coreData.replace(/import DatabaseModule?\n/,'') | ||
coreData=coreData.replace(/...DatabaseModule,/,'') | ||
fs.writeFileSync("./swyger-browser/src/app/rest/core/index.js", coreData) | ||
} | ||
if(fs.pathExistsSync('./swyger-browser/static/public/themes/dashui/app/core/database')){ | ||
fs.removeSync('./swyger-browser/static/public/themes/dashui/app/core/database') | ||
} | ||
} | ||
if(apiClientType.includes('storage')) { | ||
jsonData.dependencies['@swyger/client-storage'] = 'latest' | ||
fileImport=fileImport+"import SwygerStorageClient from '@swyger/client-storage'\n" | ||
client=client+" storage:SwygerStorageClient.init(ClientConfig),\n" | ||
}else{ | ||
if(fs.pathExistsSync('./swyger-browser/src/app/rest/core/index.js')){ | ||
let coreData = fs.readFileSync("./swyger-browser/src/app/rest/core/index.js", "utf8") | ||
coreData=coreData.replace(/import StorageModule?\n/,'') | ||
coreData=coreData.replace(/...StorageModule,/,'') | ||
fs.writeFileSync("./swyger-browser/src/app/rest/core/index.js", coreData) | ||
} | ||
if(fs.pathExistsSync('./swyger-browser/static/public/themes/dashui/app/core/storage')){ | ||
fs.removeSync('./swyger-browser/static/public/themes/dashui/app/core/storage') | ||
} | ||
} | ||
//Rewriting the route.js for client | ||
if(fs.pathExistsSync('./swyger-browser/src/route.js')){ | ||
client=client + | ||
" }\n" + | ||
" }\n" + | ||
"}" | ||
let routeData = fs.readFileSync("./swyger-browser/src/route.js", "utf8") | ||
routeData=routeData.replace(/import SwygerClient from '@swyger\/client'/,fileImport+'\n') | ||
routeData=routeData.replace(/let client=/,client+'\nlet client=') | ||
fs.writeFileSync("./swyger-browser/src/route.js", routeData) | ||
} | ||
} | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-browser/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
@@ -259,4 +417,4 @@ fs.moveSync('./swyger-browser',projectFolder+'/client/browser') | ||
const projectUsage =chalk.red(boxen(chalk.green("\n" + app.name.toUpperCase()+" v0.1.0 project." + "\nEnter in your sub folder(s) by cmd: cd folder_name, \nthen cmd: npm install \n cmd: npm run dev (for development) \n"), {padding: 1, borderColor: 'red', dimBorder: true}) + "\n"); | ||
//console.log(projectUsage) | ||
outro("You're all set!"); | ||
console.log(projectUsage) | ||
outro("You're all set! Don't forget to read the README.md for each project!"); | ||
@@ -279,1 +437,2 @@ await sleep(1000); | ||
main().catch(console.error); | ||
374
index.js
@@ -10,3 +10,3 @@ // Run `npm run start` to start the demo | ||
cancel, | ||
text, | ||
text, multiselect, | ||
} from '@clack/prompts'; | ||
@@ -28,3 +28,3 @@ import { setTimeout as sleep } from 'node:timers/promises'; | ||
//console.log(usage); | ||
console.log(usage); | ||
let args=hideBin(process.argv) //Or process.argv.slice(2) | ||
@@ -62,3 +62,6 @@ | ||
message: 'What is your server name?', | ||
placeholder: 'swyger', | ||
placeholder: 'swyger-clone', | ||
validate(value) { | ||
if (value.length === 0) return `Value is required!`; | ||
} | ||
}); | ||
@@ -72,2 +75,3 @@ | ||
} | ||
app.name=app.name.toLowerCase() | ||
@@ -93,2 +97,6 @@ | ||
}); | ||
if (isCancel(sideType)) { | ||
cancel('Operation cancelled'); | ||
return process.exit(0); | ||
} | ||
app.sideType=sideType | ||
@@ -98,129 +106,171 @@ } | ||
let serviceType | ||
let apiClientType | ||
let serverLanguageType | ||
let projectFolder='./'+app.name | ||
let shouldUseApiClient | ||
let projectUrl | ||
const projectSpinner = spinner(); | ||
let repo | ||
switch (app?.sideType) { | ||
case 'server': | ||
serviceType = await select({ | ||
message: 'Pick a service you need', | ||
serverLanguageType=await select({ | ||
message: 'Pick your Language', | ||
options: [ | ||
{ value: 'all', label: 'All services(auth,database,storage...)' }, | ||
{ value: 'auth', label: 'This will create only an auth server (register,login,refresh token...)' }, | ||
{ value: 'database', label: 'This will create only a database server(create,read,update,delete data in realtime)' }, | ||
//{ value: 'storage', label: 'This will create only a storage server', hint: 'oh no' }, | ||
{ value: 'storage', label: 'This will create only a storage server(create,read,update,delete file in realtime)'}, | ||
{ value: 'node-js', label: 'Create the server with NodeJS' }, | ||
], | ||
}); | ||
if (isCancel(serviceType)) { | ||
}) | ||
if (isCancel(serverLanguageType)) { | ||
cancel('Operation cancelled'); | ||
return process.exit(0); | ||
} | ||
await git.clone('https://github.com/coorise/swyger-nodejs-base.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-base')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-base/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-base/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/base' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-base/package.json", JSON.stringify(jsonData,null, 4)) | ||
switch (serverLanguageType) { | ||
case 'node-js': | ||
serviceType = await select({ | ||
message: 'Pick a service you need', | ||
options: [ | ||
{ value: 'all', label: 'All services(auth,database,storage...)' }, | ||
{ value: 'auth', label: 'This will create only an auth server (register,login,refresh token...)' }, | ||
{ value: 'database', label: 'This will create only a database server(create,read,update,delete data in realtime)' }, | ||
//{ value: 'storage', label: 'This will create only a storage server', hint: 'oh no' }, | ||
{ value: 'storage', label: 'This will create only a storage server(create,read,update,delete file in realtime)'}, | ||
], | ||
}); | ||
if (isCancel(serviceType)) { | ||
cancel('Operation cancelled'); | ||
return process.exit(0); | ||
} | ||
fs.moveSync('./swyger-nodejs-base',projectFolder+'/server/base') | ||
} | ||
}) | ||
switch (serviceType) { | ||
case 'all': | ||
await git.clone('https://github.com/coorise/swyger-nodejs-auth.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-auth/package.json", "utf8") | ||
repo='https://github.com/coorise/swyger-nodejs-base.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-base')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-base/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-base/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/auth' | ||
jsonData.name='@'+app.name+'/base' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-auth/package.json", JSON.stringify(jsonData,null, 4)) | ||
fs.writeFileSync("./swyger-nodejs-base/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-auth',projectFolder+'/server/auth') | ||
fs.moveSync('./swyger-nodejs-base',projectFolder+'/server/base') | ||
} | ||
}) | ||
await git.clone('https://github.com/coorise/swyger-nodejs-database.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-database')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-database/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-database/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/database' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-database/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-database',projectFolder+'/server/database') | ||
} | ||
}) | ||
await git.clone('https://github.com/coorise/swyger-nodejs-storage.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-storage/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/storage' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-storage/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-storage',projectFolder+'/server/storage') | ||
} | ||
}) | ||
switch (serviceType) { | ||
case 'all': | ||
repo='https://github.com/coorise/swyger-nodejs-auth.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-auth/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/auth' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-auth/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-auth',projectFolder+'/server/auth') | ||
} | ||
}) | ||
repo='https://github.com/coorise/swyger-nodejs-database.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-database')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-database/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-database/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/database' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-database/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-database',projectFolder+'/server/database') | ||
} | ||
}) | ||
repo='https://github.com/coorise/swyger-nodejs-storage.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-storage/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/storage' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-storage/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-storage',projectFolder+'/server/storage') | ||
} | ||
}) | ||
break; | ||
case 'auth': | ||
repo='https://github.com/coorise/swyger-nodejs-auth.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-auth/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/auth' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-auth/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-auth',projectFolder+'/server/auth') | ||
} | ||
}) | ||
break; | ||
case 'database': | ||
repo='https://github.com/coorise/swyger-nodejs-database.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-database')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-database/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-database/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/database' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-database/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-database',projectFolder+'/server/database') | ||
} | ||
}) | ||
break; | ||
case 'storage': | ||
repo='https://github.com/coorise/swyger-nodejs-storage.git' | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-nodejs-storage/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/storage' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-storage/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-storage',projectFolder+'/server/storage') | ||
} | ||
}) | ||
break; | ||
} | ||
app.serviceType=serviceType | ||
break; | ||
case 'auth': | ||
await git.clone('https://github.com/coorise/swyger-nodejs-auth.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-auth/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-auth/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/auth' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-auth/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-auth',projectFolder+'/server/auth') | ||
} | ||
}) | ||
break; | ||
case 'database': | ||
await git.clone('https://github.com/coorise/swyger-nodejs-database.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-database')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-database/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-database/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/database' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-database/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-database',projectFolder+'/server/database') | ||
} | ||
}) | ||
break; | ||
case 'storage': | ||
await git.clone('https://github.com/coorise/swyger-nodejs-storage.git', 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage')){ | ||
if(fs.pathExistsSync('./swyger-nodejs-storage/package.json')){ | ||
const fileData = fs.readFileSync("./swyger-nodejs-storage/package.json", "utf8") | ||
// Use JSON.parse to convert string to JSON Object | ||
const jsonData = JSON.parse(fileData) | ||
jsonData.name='@'+app.name+'/storage' | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-nodejs-storage/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
fs.moveSync('./swyger-nodejs-storage',projectFolder+'/server/storage') | ||
} | ||
}) | ||
break; | ||
} | ||
app.serviceType=serviceType | ||
break; | ||
case 'client': | ||
projectType = await select({ | ||
message: 'What is the client type you want to build?', | ||
message: 'What is the platform you want to build?', | ||
options: [ | ||
{ value: 'browser', label: 'Html/CSS SPA Boilerplate + Rest Api consumer' }, | ||
{ value: 'browser', label: 'Bowser: Html/CSS SPA Boilerplate to create Static Website (like NuxtJS, NextJS...)' }, | ||
], | ||
@@ -233,7 +283,37 @@ }); | ||
} | ||
shouldUseApiClient=await confirm({ | ||
message: 'Do you want to add swyger api consumer client (auth,database,storage...)?', | ||
}) | ||
if (isCancel(shouldUseApiClient)) { | ||
cancel('Operation cancelled'); | ||
return process.exit(0); | ||
} | ||
if(shouldUseApiClient){ | ||
apiClientType = await multiselect({ | ||
message: 'What is the client api type you want to build? (Select: Space bar |__|, Enter: Continue', | ||
options: [ | ||
{ value: 'all', label: 'All Rest Api consumer(authentication,database,storage...)' }, | ||
{ value: 'auth', label: 'Auth Rest Api consumer' }, | ||
//{ value: 'database', label: 'Database Rest Api consumer' }, | ||
//{ value: 'storage', label: 'Storage Rest Api consumer' }, | ||
], | ||
}); | ||
if (isCancel(apiClientType)) { | ||
cancel('Operation cancelled'); | ||
return process.exit(0); | ||
} | ||
} | ||
switch (projectType) { | ||
case 'browser': | ||
await git.clone('https://github.com/coorise/swyger-browser.git', 'master')?.then(()=>{ | ||
projectUrl='swyger-spa.git' | ||
if(shouldUseApiClient){ | ||
projectUrl='swyger-browser.git' | ||
} | ||
repo='https://github.com/coorise/'+projectUrl | ||
projectSpinner.start('Downloading browser repo from github: '+repo+'\n'); | ||
await git.clone(repo, 'master')?.then(()=>{ | ||
if(fs.pathExistsSync('./swyger-browser')){ | ||
if(fs.pathExistsSync('./swyger-browser/package.json')){ | ||
projectSpinner.stop('The repo from github: '+repo+' was cloned successfully!\n'); | ||
const fileData = fs.readFileSync("./swyger-browser/package.json", "utf8") | ||
@@ -243,4 +323,74 @@ // Use JSON.parse to convert string to JSON Object | ||
jsonData.name='@'+app.name+'/browser' | ||
jsonData.version='0.1.0' | ||
if(!apiClientType.includes('all')){ | ||
let fileImport='' | ||
let client="const SwygerClient= {\n" + | ||
" init:(ClientConfig)=>{\n" + | ||
"\n" + | ||
" return {\n" | ||
delete jsonData.dependencies['@swyger/client'] | ||
if(apiClientType.includes('auth')) { | ||
jsonData.dependencies['@swyger/client-auth'] = 'latest' | ||
fileImport="import SwygerAuthClient from '@swyger/client-auth'\n" | ||
client=client+" auth:SwygerAuthClient.init(ClientConfig),\n" | ||
}else{ | ||
if(fs.pathExistsSync('./swyger-browser/src/app/rest/core/index.js')){ | ||
let coreData = fs.readFileSync("./swyger-browser/src/app/rest/core/index.js", "utf8") | ||
coreData=coreData.replace(/import AuthModule?\n/,'') | ||
coreData=coreData.replace(/...AuthModule,/,'') | ||
fs.writeFileSync("./swyger-browser/src/app/rest/core/index.js", coreData) | ||
} | ||
if(fs.pathExistsSync('./swyger-browser/static/public/themes/dashui/app/core/auth')){ | ||
fs.removeSync('./swyger-browser/static/public/themes/dashui/app/core/auth') | ||
} | ||
} | ||
if(apiClientType.includes('database')) { | ||
jsonData.dependencies['@swyger/client-database'] = 'latest' | ||
fileImport=fileImport+"import SwygerDatabaseClient from '@swyger/client-database'\n" | ||
client=client+" database:SwygerDatabaseClient.init(ClientConfig),\n" | ||
}else{ | ||
if(fs.pathExistsSync('./swyger-browser/src/app/rest/core/index.js')){ | ||
let coreData = fs.readFileSync("./swyger-browser/src/app/rest/core/index.js", "utf8") | ||
coreData=coreData.replace(/import DatabaseModule?\n/,'') | ||
coreData=coreData.replace(/...DatabaseModule,/,'') | ||
fs.writeFileSync("./swyger-browser/src/app/rest/core/index.js", coreData) | ||
} | ||
if(fs.pathExistsSync('./swyger-browser/static/public/themes/dashui/app/core/database')){ | ||
fs.removeSync('./swyger-browser/static/public/themes/dashui/app/core/database') | ||
} | ||
} | ||
if(apiClientType.includes('storage')) { | ||
jsonData.dependencies['@swyger/client-storage'] = 'latest' | ||
fileImport=fileImport+"import SwygerStorageClient from '@swyger/client-storage'\n" | ||
client=client+" storage:SwygerStorageClient.init(ClientConfig),\n" | ||
}else{ | ||
if(fs.pathExistsSync('./swyger-browser/src/app/rest/core/index.js')){ | ||
let coreData = fs.readFileSync("./swyger-browser/src/app/rest/core/index.js", "utf8") | ||
coreData=coreData.replace(/import StorageModule?\n/,'') | ||
coreData=coreData.replace(/...StorageModule,/,'') | ||
fs.writeFileSync("./swyger-browser/src/app/rest/core/index.js", coreData) | ||
} | ||
if(fs.pathExistsSync('./swyger-browser/static/public/themes/dashui/app/core/storage')){ | ||
fs.removeSync('./swyger-browser/static/public/themes/dashui/app/core/storage') | ||
} | ||
} | ||
//Rewriting the route.js for client | ||
if(fs.pathExistsSync('./swyger-browser/src/route.js')){ | ||
client=client + | ||
" }\n" + | ||
" }\n" + | ||
"}" | ||
let routeData = fs.readFileSync("./swyger-browser/src/route.js", "utf8") | ||
routeData=routeData.replace(/import SwygerClient from '@swyger\/client'/,fileImport+'\n') | ||
routeData=routeData.replace(/let client=/,client+'\nlet client=') | ||
fs.writeFileSync("./swyger-browser/src/route.js", routeData) | ||
} | ||
} | ||
// Write it back to your json file | ||
fs.writeFileSync("./swyger-browser/package.json", JSON.stringify(jsonData,null, 4)) | ||
} | ||
@@ -258,4 +408,4 @@ fs.moveSync('./swyger-browser',projectFolder+'/client/browser') | ||
const projectUsage =chalk.red(boxen(chalk.green("\n" + app.name.toUpperCase()+" v0.1.0 project." + "\nEnter in your sub folder(s) by cmd: cd folder_name, \nthen cmd: npm install \n cmd: npm run dev (for development) \n"), {padding: 1, borderColor: 'red', dimBorder: true}) + "\n"); | ||
//console.log(projectUsage) | ||
outro("You're all set!"); | ||
console.log(projectUsage) | ||
outro("You're all set! Don't forget to read the README.md for each project!"); | ||
@@ -262,0 +412,0 @@ await sleep(1000); |
{ | ||
"name": "@swyger/cli", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"description": "Swyger CLI is used to create projects(Server/Client) with boilerplate!", | ||
@@ -36,3 +36,5 @@ "type": "module", | ||
"SPA", | ||
"Components" | ||
"Components", | ||
"strapi", | ||
"firebase" | ||
], | ||
@@ -39,0 +41,0 @@ "author": "Agglomy", |
@@ -9,4 +9,4 @@ # <span style="color: red;">Swyger</span> <span style="color: blue;">CLI</span> | ||
Note:Look for rollup option in **vite.config.js** | ||
## Prerequisite: | ||
@@ -32,3 +32,3 @@ - NodeJS 16+: https://nodejs.org/ | ||
- ``swyger-cli -- -h``: To get th commands and option | ||
- ``swyger-cli -- -h``: To get the commands and option | ||
- ``swyger-cli -- init``: To init the project | ||
@@ -38,3 +38,3 @@ - ``init`` command can be directly chained with: | ||
Note: In case you don't know options, just type ``swyger-cli init`` and follow the scripts. | ||
Note: In case you don't know the options, just type ``swyger-cli init`` and follow the scripts. | ||
@@ -41,0 +41,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108207
802