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
8 changed files
with
3,252 additions
and
94 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,4 @@ | |
"ts-node-dev": "^1.1.6", | ||
"typescript": "^4.2.3" | ||
} | ||
} | ||
} |
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,40 +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' | ||
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', | ||
}, | ||
]) | ||
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) | ||
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 | ||
} | ||
// 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', | ||
}) | ||
fs.writeFileSync(specPath, getBoilerplateSpecContent(cliName), { | ||
encoding: 'utf-8', | ||
}); | ||
|
||
Logger.log( | ||
`Successfully created the new Spec "${specFileName}"! Start editing it in the dev/ folder...`, | ||
Level.SUCCESS | ||
) | ||
} catch (e) { | ||
Logger.log("Couldn't create Spec! Please try again.", Level.ERROR) | ||
} | ||
Logger.log( | ||
`Successfully created the new Spec "${specFileName}"! Start editing it in the dev/ folder...`, | ||
Level.SUCCESS, | ||
); | ||
} catch (e) { | ||
Logger.log("Couldn't create Spec! Please try again.", Level.ERROR); | ||
} | ||
} | ||
|
||
createNewSpecCLI() | ||
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
// Folder names | ||
export const SOURCE_FOLDER_NAME = 'dev' | ||
export const DESTINATION_FOLDER_NAME = 'specs' | ||
|
||
export const SOURCE_FOLDER_NAME = 'dev'; | ||
export const DESTINATION_FOLDER_NAME = 'specs'; | ||
|
||
export const getBoilerplateSpecContent = (specName: string) => ` | ||
export const completion: Fig.Spec = { | ||
name: "${specName}" | ||
}` | ||
}`; |
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