-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from elsoul/backend
add skeet create --backend option
- Loading branch information
Showing
13 changed files
with
370 additions
and
224 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,50 @@ | ||
import { | ||
BACKEND_FUNCTIONS_REPO_URL, | ||
BACKEND_GRAPHQL_REPO_URL, | ||
FUNCTIONS_PATH, | ||
Logger, | ||
execSyncCmd, | ||
} from '@/lib' | ||
import { generateInitFiles } from './create' | ||
import { sleep } from '@/utils/time' | ||
import { SkeetTemplateBackend } from '@/types/skeetTypes' | ||
import { DEFAULT_FUNCTION_NAME } from '@/index' | ||
import { existsSync } from 'fs' | ||
import { questionList } from '../init/questionList' | ||
import inquirer from 'inquirer' | ||
|
||
export const createBackend = async (appName: string) => { | ||
const { template } = await inquirer.prompt<{ template: string }>( | ||
questionList.backendTemplateQuestions | ||
) | ||
const appDir = './' + appName | ||
if (existsSync(appDir)) { | ||
Logger.error(`Directory ${appName} already exists.`) | ||
process.exit(0) | ||
} | ||
let gitCloneCmd = null | ||
let backendRootPath = '' | ||
if (template === SkeetTemplateBackend.Firestore) { | ||
gitCloneCmd = ['git', 'clone', BACKEND_FUNCTIONS_REPO_URL, appName] | ||
backendRootPath = `${appDir}/${FUNCTIONS_PATH}/${DEFAULT_FUNCTION_NAME}` | ||
} else { | ||
gitCloneCmd = ['git', 'clone', BACKEND_GRAPHQL_REPO_URL, appName] | ||
backendRootPath = `${appDir}/graphql` | ||
} | ||
|
||
await execSyncCmd(gitCloneCmd) | ||
const yarnApiCmd = ['yarn'] | ||
await execSyncCmd(yarnApiCmd, appDir) | ||
await execSyncCmd(yarnApiCmd, backendRootPath) | ||
const rmDefaultGit = ['rm', '-rf', '.git'] | ||
await execSyncCmd(rmDefaultGit, appDir) | ||
await sleep(1000) | ||
|
||
await generateInitFiles(appName, template) | ||
Logger.skeetAA() | ||
Logger.welcomText(appName, template) | ||
const nmb = Math.floor(Math.random() * 4 + 1) | ||
if (nmb === 4) { | ||
Logger.cmText() | ||
} | ||
} |
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,12 +1,18 @@ | ||
import { program } from '@/index' | ||
import { create } from './create' | ||
import { createBackend } from './createBackend' | ||
|
||
export const createCommands = async () => { | ||
program | ||
.command('create') | ||
.argument('<appName>', 'Name of the app') | ||
.description('Create Skeet Framework App') | ||
.action(async (appName: string) => { | ||
await create(appName) | ||
.option('-b, --backend', 'Create Backend Only', false) | ||
.action(async (appName: string, options: { backend: boolean }) => { | ||
if (options.backend) { | ||
await createBackend(appName) | ||
} else { | ||
await create(appName) | ||
} | ||
}) | ||
} |
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,6 @@ | ||
import { spawnSync } from 'child_process' | ||
|
||
export const dockerBuild = async () => { | ||
const cmd = `yarn docker:build` | ||
spawnSync(cmd, { shell: true, stdio: 'inherit' }) | ||
} |
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,6 @@ | ||
import { spawnSync } from 'child_process' | ||
|
||
export const dockerRm = async () => { | ||
const cmd = `yarn docker:rm` | ||
spawnSync(cmd, { shell: true, stdio: 'inherit' }) | ||
} |
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,6 @@ | ||
import { spawnSync } from 'child_process' | ||
|
||
export const dockerRun = async () => { | ||
const cmd = `yarn docker:run` | ||
spawnSync(cmd, { shell: true, stdio: 'inherit' }) | ||
} |
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