Skip to content

Commit

Permalink
fix: prettier fix files
Browse files Browse the repository at this point in the history
  • Loading branch information
cstrnt committed Mar 29, 2021
1 parent 60387c2 commit c18bea5
Show file tree
Hide file tree
Showing 8 changed files with 3,252 additions and 94 deletions.
4 changes: 1 addition & 3 deletions dev/cd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ export const cdCompletionSpec: Fig.Spec = {
args: {
template: 'folders',
},
subcommands: [
{ name: "cat" }
]
subcommands: [{ name: 'cat' }],
};

// var completionSpec = {
Expand Down
3,174 changes: 3,173 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"ts-node-dev": "^1.1.6",
"typescript": "^4.2.3"
}
}
}
64 changes: 32 additions & 32 deletions scripts/cli.ts
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();
1 change: 0 additions & 1 deletion scripts/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const options: ts.TranspileOptions = {
},
};


if (process.argv[2] == 'INVALIDATE_CACHE') {
exec('fig settings autocomplete.developerModeNPMInvalidateCache true', (error, stdout, stderr) => {
if (error) {
Expand Down
7 changes: 3 additions & 4 deletions scripts/constants.ts
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}"
}`
}`;
3 changes: 0 additions & 3 deletions scripts/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import chalk from 'chalk';
// An enum representing the log level and the color to use
// in chalk to render this level.
export enum Level {

INFO = 'blue',
ERROR = 'red',
SUCCESS = 'green',
Expand All @@ -24,9 +23,7 @@ export enum Level {
* @param level The level to log
*/
export default abstract class SpecLogger {

static log(message: string, level: Level = Level.INFO) {

console.log(chalk[level](message));
}
}
91 changes: 42 additions & 49 deletions scripts/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {
factory,
isVariableStatement,
Node,
SourceFile,
SyntaxKind,
TransformerFactory,
updateVariableDeclaration,
updateVariableDeclarationList,
updateVariableStatement,
VariableStatement,
visitEachChild,
visitNode,
} from 'typescript'
factory,
isVariableStatement,
Node,
SourceFile,
SyntaxKind,
TransformerFactory,
updateVariableDeclaration,
updateVariableDeclarationList,
updateVariableStatement,
VariableStatement,
visitEachChild,
visitNode,
} from 'typescript';

// The name of the spec variable
const SPEC_NAME = 'completionSpec'
const EXPORT_KEYWORD = SyntaxKind.ExportKeyword
const SPEC_NAME = 'completionSpec';
const EXPORT_KEYWORD = SyntaxKind.ExportKeyword;

/**
* The TypeScript transformer to rename the export spec variable name to SPEC_NAME,
Expand All @@ -24,40 +24,33 @@ const EXPORT_KEYWORD = SyntaxKind.ExportKeyword
* @param context The current context
*/
export const specTransformer: TransformerFactory<SourceFile> = (context) => {
return (sourceFile) => {
let updated = false
const visitor = (node: Node) => {
if (!updated && isVariableStatement(node)) {
const { declarationList, modifiers } = node as VariableStatement
// Only process if there is a modifier, and if this modifier
// is an export.
if (
modifiers &&
modifiers.length === 1 &&
modifiers[0].kind === EXPORT_KEYWORD
) {
const variableNode = declarationList.declarations[0]
return (sourceFile) => {
let updated = false;
const visitor = (node: Node) => {
if (!updated && isVariableStatement(node)) {
const { declarationList, modifiers } = node as VariableStatement;
// Only process if there is a modifier, and if this modifier
// is an export.
if (modifiers && modifiers.length === 1 && modifiers[0].kind === EXPORT_KEYWORD) {
const variableNode = declarationList.declarations[0];

updated = true
updated = true;

// Update the variable name to SPEC_NAME
const newVariableNode = updateVariableDeclaration(
variableNode,
factory.createIdentifier(SPEC_NAME),
variableNode.type,
variableNode.initializer
)
const newDeclarationlist = updateVariableDeclarationList(
declarationList,
[newVariableNode]
)
// Update the variable name to SPEC_NAME
const newVariableNode = updateVariableDeclaration(
variableNode,
factory.createIdentifier(SPEC_NAME),
variableNode.type,
variableNode.initializer,
);
const newDeclarationlist = updateVariableDeclarationList(declarationList, [newVariableNode]);

// Remove the export keyword
return updateVariableStatement(node, [], newDeclarationlist)
}
}
return visitEachChild(node, visitor, context)
}
return visitNode(sourceFile, visitor)
}
}
// Remove the export keyword
return updateVariableStatement(node, [], newDeclarationlist);
}
}
return visitEachChild(node, visitor, context);
};
return visitNode(sourceFile, visitor);
};
};

0 comments on commit c18bea5

Please sign in to comment.