forked from withfig/autocomplete
-
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
Showing
5 changed files
with
598 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import inquirer from 'inquirer' | ||
import Logger, { Level } from './log' | ||
import fs from 'fs' | ||
import { getBoilerplateSpecContent, SOURCE_FOLDER_NAME } from './constants' | ||
import path from 'path' | ||
|
||
async function createNewSpecCLI() { | ||
try { | ||
const { cliName } = await inquirer.prompt<{ cliName: string }>([ | ||
{ | ||
type: 'input', | ||
message: "What's the name of the CLI you want to create the Spec for?", | ||
name: 'cliName', | ||
}, | ||
]) | ||
|
||
const specFileName = `${cliName.toLowerCase()}.ts` | ||
const specPath = path.join(process.cwd(), SOURCE_FOLDER_NAME, specFileName) | ||
const hasSpec = fs.existsSync(specPath) | ||
|
||
// We don't want to overwrite the spec if it already exists | ||
if (hasSpec) { | ||
Logger.log(`The spec "${specFileName}" already exists.`, Level.ERROR) | ||
return | ||
} | ||
|
||
fs.writeFileSync(specPath, getBoilerplateSpecContent(cliName), { | ||
encoding: 'utf-8', | ||
}) | ||
|
||
Logger.log( | ||
`Successfully created the new Spec "${specFileName}"!`, | ||
Level.SUCCESS | ||
) | ||
} catch (e) { | ||
Logger.log("Couldn't create Spec! Please try again.", Level.ERROR) | ||
} | ||
} | ||
|
||
createNewSpecCLI() |
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,9 @@ | ||
// Folder names | ||
export const SOURCE_FOLDER_NAME = 'dev' | ||
export const DESTINATION_FOLDER_NAME = 'specs' | ||
|
||
|
||
export const getBoilerplateSpecContent = (specName: string) => ` | ||
export const completion: Fig.Spec = { | ||
name: "${specName}" | ||
}` |
Oops, something went wrong.