gen-jhipster
Version:
VHipster - Spring Boot + Angular/React/Vue in one handy generator
104 lines (103 loc) • 3.81 kB
TypeScript
import type { CascatedEditFileCallback, EditFileCallback } from '../api.ts';
import type CoreGenerator from '../index.ts';
export type NeedleCallback = (content: string) => string;
type NeedleContentToAddCallback = {
/**
* Position of the needle start.
*/
needleIndex: number;
/**
* Position of the needle line's new line char.
*/
needleLineIndex: number;
needleIndent: number;
indentPrefix: string;
};
type ContentToAdd = {
content: string;
contentToCheck?: string | RegExp;
};
export type NeedleInsertion = {
/**
* Needle identifier.
* The `jhipster-needle-` prefix is optional.
* An empty string can be provided to append content at the end of the file.
*/
needle: string;
/**
* Content to add.
*/
contentToAdd: string | string[] | ContentToAdd[] | ((content: string, options: NeedleContentToAddCallback) => string);
contentToCheck?: string | RegExp;
/**
* check existing content ignoring white spaces and new lines.
*/
ignoreWhitespaces?: boolean;
/**
* throw error if needle was not found
*/
optional?: boolean;
/**
* Detect and apply indent
*/
autoIndent?: boolean;
};
type NeedleFileInsertion = Omit<NeedleInsertion, 'needle' | 'contentToAdd'> & {
/**
* Path to file.
* The generator context must be passed.
*/
filePath?: string;
/**
* Common needle prefix
*/
needlesPrefix?: string;
};
type NeedleContentInsertion = Pick<NeedleInsertion, 'needle' | 'autoIndent'> & {
content: string;
contentToAdd: string | string[] | ((content: string, options: NeedleContentToAddCallback) => string);
};
/**
* Change spaces sequences and characters that prettier breaks line (<>()) to allow any number of spaces or new line prefix
*/
export declare const convertToPrettierExpressions: (str: string) => string;
export declare const createNeedleRegexp: (needle: string) => RegExp;
type NeedleLinePosition = {
start: number;
end: number;
};
export declare const getNeedlesPositions: (content: string, needle?: string) => NeedleLinePosition[];
/**
* Check if contentToCheck existing in content
*
* @param contentToCheck
* @param content
* @param [ignoreWhitespaces=true]
*/
export declare const checkContentIn: (contentToCheck: string | RegExp, content: string, ignoreWhitespaces?: boolean) => boolean;
/**
* Write content before needle applying indentation
*
* @param args
* @returns null if needle was not found, new content otherwise
*/
export declare const insertContentBeforeNeedle: ({ content, contentToAdd, needle, autoIndent }: NeedleContentInsertion) => string | null;
/**
* Create an callback to insert the new content into existing content.
*
* A `contentToAdd` of string type will remove leading `\n`.
* Leading `\n` allows a prettier template formatting.
*
* @param options
*/
export declare const createNeedleCallback: <Generator extends CoreGenerator = CoreGenerator>({ needle, contentToAdd, contentToCheck, optional, ignoreWhitespaces, autoIndent, }: NeedleInsertion) => EditFileCallback<Generator>;
/**
* Inject content before needle or create a needle insertion callback.
*
* @param this - generator if provided, editFile will be executed
*/
export declare function createBaseNeedle(options: Omit<NeedleFileInsertion, 'filePath'>, needles: Record<string, string>): NeedleCallback;
export declare function createBaseNeedle(needles: Record<string, string>): NeedleCallback;
export declare function createBaseNeedle<Generator extends CoreGenerator = CoreGenerator>(this: Generator, options: NeedleFileInsertion, needles: Record<string, string>): CascatedEditFileCallback<Generator>;
export declare const createNeedleTransform: () => import("stream").Transform;
export {};