Skip to content

creatium - API documentation

Classes

Creatium

Class of Creatium for create project templates (CLI and Library).

Example

ts
//////////////// core.js ///////////////////

import { Creatium } from 'creatium'
export const core = new Creatium({
  name: 'My Project',
  version: '1.0.0',
  templates: {
    ...
  },
})

//////////////// bin.js ///////////////////

import { core } from './core.js'
core.cli()

//////////////// lib.js ///////////////////

import { core } from './core.js'
export const create = core.build

Constructors

new Creatium()
ts
new Creatium(options: {
  cache: boolean;
  consts: Record<string, string>;
  intro: false | (data: HookParams) => Response<void>;
  name: string;
  onCancel: false | (data: HookParams) => Response<void>;
  opts: {
     install: false | [
        | "bun"
        | "deno"
        | "npm"
        | "pnpm"
        | "yarn", 
        | "bun"
        | "deno"
        | "npm"
        | "pnpm"
        | "yarn", ...("bun" | "deno" | "npm" | "pnpm" | "yarn")[]];
     name: boolean;
     openEditor: false | ["code" | "subl" | "webstorm", "code" | "subl" | "webstorm", ...("code" | "subl" | "webstorm")[]];
    };
  outro: false | (data: HookParams) => Response<void>;
  templates: {};
  updater: boolean;
  version: string;
 }): Creatium
Parameters
ParameterTypeDescription
optionsobject-
options.cache?booleanUse cache Default true
options.consts?Record<string, string>Add consts to use in your templates.
options.intro?false | (data: HookParams) => Response<void>Set custom intro
options.namestringSet name of you project
options.onCancel?false | (data: HookParams) => Response<void>Set custom function foor when user cancels the process
options.opts?objectSet your prompt options
options.opts.install?false | [ | "bun" | "deno" | "npm" | "pnpm" | "yarn", | "bun" | "deno" | "npm" | "pnpm" | "yarn", ...("bun" | "deno" | "npm" | "pnpm" | "yarn")[]]Active/deactivate the install prompt Also, You can set the installators that you want to use.
options.opts.name?booleanActive/deactivate the name prompt
options.opts.openEditor?false | ["code" | "subl" | "webstorm", "code" | "subl" | "webstorm", ...("code" | "subl" | "webstorm")[]]Active/deactivate the openEditor prompt. Also, You can set the editors that you want to use.
options.outro?false | (data: HookParams) => Response<void>Set custom outro
options.templatesobjectSet your template ooptions
options.updater?booleanUse updater Default false
options.versionstringSet version of you current project Used in for the updater notifications.
Returns

Creatium

Methods

build()
ts
build(values?: {
  input: string;
  install: Installer;
  name: string;
  openEditor: TextEditor;
  output: string;
 }, opts?: CreateOpts): Promise<{
  input: string;
  install: undefined;
  name: undefined;
  openEditor: undefined;
  output: string;
}>

A simplified version of the build method from the main class.

Parameters
ParameterTypeDescription
values?objectThe values to override the CLI prompts. If not set, the CLI prompts will be executed.
values.input?stringSet the input path or the template key
values.install?InstallerSet the installer
values.name?stringSet the name of the template
values.openEditor?TextEditorOpen editor
values.output?stringSet the output path
opts?CreateOptsThe options to pass to the CLI.
Returns

Promise<{ input: string; install: undefined; name: undefined; openEditor: undefined; output: string; }>

A promise resolving to the prompt values obtained after executing the CLI.

NameType
input?string
install?undefined
name?undefined
openEditor?undefined
output?string
Examples
ts
// simple usage
await core.build()
ts
// custom usage
await core.build( { args : process.argv.slice(4), hideBin : false } )
cli()
ts
cli(props?: CliOpts): Promise<{
  input: string;
  install: undefined;
  name: undefined;
  openEditor: undefined;
  output: string;
}>

A simplified version of the cli method from the main class. Initializes and executes the command-line interface (CLI) process.

Parameters
ParameterTypeDescription
props?CliOptsOptional CLI options to configure the initialization process.
Returns

Promise<{ input: string; install: undefined; name: undefined; openEditor: undefined; output: string; }>

A promise resolving to the prompt values obtained after executing the CLI.

NameType
input?string
install?undefined
name?undefined
openEditor?undefined
output?string
Examples
ts
// simple usage
await core.cli()
ts
// custom usage
await core.cli( { args : process.argv.slice(4), hideBin : false } )

CreatiumCore<C>

Customizable class of Creatium for create project templates (CLI and Library).

Example

ts
//////////////// core.js ///////////////////

export const core = new CreatiumCore({
  name: 'My Project',
  version: '1.0.0',
  prompts: {
    ...
  },
  ...
})

//////////////// bin.js ///////////////////

import { core } from './core.js'
const res = await core.cli()
// do something with res...
await core.createTemplate( res )

//////////////// lib.js ///////////////////

import { core } from './core.js'
export const create = async (args) => {
  const res = await core.build( args )
  // do something with res...
  await core.createTemplate( res )
}

Type Parameters

Type ParameterDefault typeDescription
C extends ConfigConfig

Accessors

debugMode
Set Signature
ts
set debugMode(value: boolean): void

Force debug mode

Parameters
ParameterType
valueboolean
Returns

void

Constructors

new CreatiumCore()
ts
new CreatiumCore<C>(config: C): CreatiumCore<C>
Parameters
ParameterType
configC
Returns

CreatiumCore<C>

Methods

build()
ts
build(values?: { [K in string | number | symbol]: { [K in string | number | symbol]: { [K in string | number | symbol]?: { [K in string | number | symbol]: ((...)[(...)] extends Object ? (...) extends (...) ? (...) : (...) : never)[K] } }[K] }[K] }, opts?: CreateOpts): Promise<{ [K in string | number | symbol]: { [K in string | number | symbol]?: { [K in string | number | symbol]: (C["prompt"][K] extends Object ? T extends keyof OptionsClasses ? { [K in (...) | (...) | (...)]: (...)[(...)] } : never : never)[K] } }[K] }>

Initialize the CLI and executes the callback function passed in the config.

Parameters
ParameterTypeDescription
values?{ [K in string | number | symbol]: { [K in string | number | symbol]: { [K in string | number | symbol]?: { [K in string | number | symbol]: ((...)[(...)] extends Object ? (...) extends (...) ? (...) : (...) : never)[K] } }[K] }[K] }The values to override the CLI prompts. If not set, the CLI prompts will be executed.
opts?CreateOptsThe options to pass to the CLI.
Returns

Promise<{ [K in string | number | symbol]: { [K in string | number | symbol]?: { [K in string | number | symbol]: (C["prompt"][K] extends Object ? T extends keyof OptionsClasses ? { [K in (...) | (...) | (...)]: (...)[(...)] } : never : never)[K] } }[K] }>

The result of the callback function.

cancel()
ts
cancel(message?: string): Promise<void>

Cancels the current process and exits with code 0.

If a message is provided, it will be displayed in the console. If onCancel is set in the config, it will be called with the current data. If onCancel is not set, a default message will be displayed.

Parameters
ParameterTypeDescription
message?stringThe message to display before exiting.
Returns

Promise<void>

cli()
ts
cli(props?: CliOpts): Promise<{ [K in string | number | symbol]: { [K in string | number | symbol]?: { [K in string | number | symbol]: (C["prompt"][K] extends Object ? T extends keyof OptionsClasses ? { [K in (...) | (...) | (...)]: (...)[(...)] } : never : never)[K] } }[K] }>

Initializes and executes the command-line interface (CLI) process.

Parameters
ParameterTypeDescription
props?CliOptsOptional CLI options to configure the initialization process.
Returns

Promise<{ [K in string | number | symbol]: { [K in string | number | symbol]?: { [K in string | number | symbol]: (C["prompt"][K] extends Object ? T extends keyof OptionsClasses ? { [K in (...) | (...) | (...)]: (...)[(...)] } : never : never)[K] } }[K] }>

A promise resolving to the prompt values obtained after executing the CLI.

Examples
ts
// simple usage
await core.cli()
ts
// custom usage
await core.cli( { args : process.argv.slice( 4), hideBin : false } )
copyDir()
ts
copyDir(data: {
  input: string;
  output: string;
}): Promise<void>

Copy a directory from input path to output path.

Parameters
ParameterTypeDescription
dataobjectOptions object with input and output paths.
data.inputstringThe path to the directory to copy.
data.outputstringThe path to the destination directory.
Returns

Promise<void>

  • Resolves when the directory has been copied.
Example
ts
const copyResult = await core.copyDir({
  input : '/path/to/sourceDir',
  output: '/path/to/destinationDir',
})
createTemplate()
ts
createTemplate(values: CreateTemplateOpts): Promise<void>

Create a new project template.

Parameters
ParameterTypeDescription
valuesCreateTemplateOptsThe values to create the template.
Returns

Promise<void>

  • A promise that resolves when the template is created.
Examples
ts
// basic usage
await core.createTemplate( { input : 'my/template/path', output : 'my/project/path' } )
ts
// custom usage
await core.createTemplate( {
  input : 'my/template/path',
  output : 'my/project/path',
  install : 'pnpm',
  open : 'vscode',
  consts : {
    version : '1.0.0',
    header : '// Template generated by Creatium. a project from PigeonPosse',
  },
} )
getTemplateInput()
ts
getTemplateInput(input?: {
  input: string;
}): Promise<undefined | string>

Return the input path of a template by name or path.

Parameters
ParameterTypeDescription
input?objectThe name of the template or the path to the template.
input.input?string-
Returns

Promise<undefined | string>

The input path of the template or undefined if not found.

Examples
ts
// with template path
const input = await core.getTemplateInput( { input : 'my/template/path' } )
ts
// With template key
// template key must be specified in the config prompt secction.
const input = await core.getTemplateInput( { input : 'templateKey' )
install()
ts
install(options?: {
  input: string;
  installer: Installer;
}): Promise<void>

Installs the project with the given package manager.

Parameters
ParameterTypeDescription
options?objectThe options to install.
options.input?stringThe path to the folder. If not provided, the current directory is used.
options.installer?InstallerThe package manager to use for the installation.
Returns

Promise<void>

Example
ts
await core.install( {
  installer : 'pnpm',
  input     : 'my/project/path',
} )
intro()
ts
intro(message?: string): Promise<void>

Intro prompt line.

If the parameter message is provided, it will be used as the intro message. If the intro option is a function, it will be called with the this.#data as the argument. If the intro option is undefined, the default intro message will be used.

Parameters
ParameterTypeDescription
message?stringThe intro message.
Returns

Promise<void>

openEditor()
ts
openEditor(params: {
  editor: TextEditor;
  input: string;
}): Promise<void>

Open the project in the given editor.

Parameters
ParameterTypeDescription
paramsobjectThe parameters for opening the editor.
params.editor?TextEditorThe editor to open the project in.
params.input?stringThe input path. If not provided, the current directory is used.
Returns

Promise<void>

Example
ts
await core.openEditor( {
  editor : 'vscode',
  input  : 'my/project/path',
 })
outro()
ts
outro(message?: string): Promise<void>

Outro prompt line.

If the parameter message is provided, it will be used as the outro message. If the outro option is a function, it will be called with the this.#data as the argument. If the outro option is undefined, the default outro message will be used.

Parameters
ParameterTypeDescription
message?stringThe outro message.
Returns

Promise<void>

replacePlaceholders()
ts
replacePlaceholders(args: {
  input: string;
  inputOpts: Options;
  params: Params;
}): Promise<void>

Replaces placeholders in files within the specified directory.

This function searches for files in the provided input directory and replaces placeholders within those files using the specified parameters. The placeholders in the content are replaced with values from the params object.

Parameters
ParameterTypeDescription
argsobjectThe arguments object.
args.input?stringThe directory path containing files with placeholders.
args.inputOpts?Options-
args.params?ParamsAn object containing key-value pairs for replacing placeholders.
Returns

Promise<void>

A Promise that resolves once all placeholders have been replaced.

Example
ts
await core.replacePlaceholders( {
  input  : 'my/project/path',
  params : { consts: { version: '1.0.0' }, prompt: { name: 'My Project' } },
})
updateNotify()
ts
updateNotify(opts?: {
  custom: (info?: UpdateInfo) => Response<void>;
  opts: NotifyOptions;
}): Promise<void>

Shows a notification if the current package is outdated.

information: If this 'custom' function is provided, the default notification will not be shown.


Parameters
ParameterTypeDescription
opts?objectOptions for the update notification.
opts.custom?(info?: UpdateInfo) => Response<void>A custom function to run with the update
opts.opts?NotifyOptionsOptions for the update-notifier package.
Returns

Promise<void>

Examples
ts
// With default options. Recommended for most use cases.
await core.updateNotify()
ts
// With custom options
await core.updateNotify({ opts: { ... } })
ts
// With custom function
await core.updateNotify({ custom: () => {} })

Properties

PropertyType
configC
utils__module

Type Aliases

CliOpts

ts
type CliOpts: {
  args: string[];
  hideBin: boolean;
};

Type declaration

NameTypeDescription
args?string[]Arguments to pass to the command Default process.argv.slice(2)
hideBin?booleanHide the first two arguments Default false

Config

ts
type Config: {
  cache: boolean;
  hooks: {
     afterPrompt: <D>(data: D) => Response<D | undefined>;
     beforePrompt: <D>(data: D) => Response<D | undefined>;
    };
  intro: (data: HookParams) => Response<void> | false;
  name: string;
  onCancel: (data: HookParams) => Response<void> | false;
  outro: (data: HookParams) => Response<void> | false;
  prompt: OptionsParams;
  updater: boolean;
  version: string;
};

Type declaration

NameTypeDescription
cache?booleanUse cache Default true
hooks?{ afterPrompt: <D>(data: D) => Response<D | undefined>; beforePrompt: <D>(data: D) => Response<D | undefined>; }hooks for
hooks.afterPrompt?<D>(data: D) => Response<D | undefined>-
hooks.beforePrompt?<D>(data: D) => Response<D | undefined>-
intro?(data: HookParams) => Response<void> | falseSet custom intro
namestringSet name of you project
onCancel?(data: HookParams) => Response<void> | falseSet custom function foor when user cancels the process
outro?(data: HookParams) => Response<void> | falseSet custom outro
promptOptionsParamsSet you prompts config
updater?booleanUse updater Default false
versionstringSet version of you current project Used in for the updater notifications.

CreateOpts

ts
type CreateOpts: CliOpts & {
  activeCli: boolean;
};

Type declaration

NameTypeDescription
activeCli?booleanOptions for activate cli. Default true

CreateTemplateOpts

ts
type CreateTemplateOpts: {
  consts: Record<string, string>;
  input: string;
  install: Installer;
  name: string;
  openEditor: TextEditor;
  output: string;
};

Type declaration

NameTypeDescription
consts?Record<string, string>Add consts to use in your templates.
input?stringSet the input path or the template key
install?InstallerSet the installer
name?stringSet the name of the template
openEditor?TextEditorOpen editor
output?stringSet the output path

Variables

env

ts
const env: {
  isBrowser: boolean;
  isBun: boolean;
  isDeno: boolean;
  isJsDom: boolean;
  isNode: boolean;
  isWebWorker: boolean;
 } = _env;

Environment functions

Type declaration

NameType
isBrowserboolean
isBunboolean
isDenoboolean
isJsDomboolean
isNodeboolean
isWebWorkerboolean

INSTALLER

ts
const INSTALLER: {
  BUN: 'bun';
  DENO: 'deno';
  NONE: 'none';
  NPM: 'npm';
  PNPM: 'pnpm';
  YARN: 'yarn';
};

installer values used in install option.

Type declaration

NameTypeDefault value
BUN"bun"'bun'
DENO"deno"'deno'
NONE"none"'none'
NPM"npm"'npm'
PNPM"pnpm"'pnpm'
YARN"yarn"'yarn'

OPTION

ts
const OPTION: {
  array: 'array';
  boolean: 'boolean';
  install: 'install';
  multiselect: 'multiselect';
  name: 'name';
  number: 'number';
  openEditor: 'openEditor';
  output: 'output';
  path: 'path';
  select: 'select';
  template: 'template';
  text: 'text';
  void: 'void';
};

Object of the CREATIUM types

Type declaration

NameTypeDefault value
array"array"'array'
boolean"boolean"'boolean'
install"install"'install'
multiselect"multiselect"'multiselect'
name"name"'name'
number"number"'number'
openEditor"openEditor"'openEditor'
output"output"'output'
path"path"'path'
select"select"'select'
template"template"'template'
text"text"'text'
void"void"'void'

prompt

ts
const prompt: {
  box: (opts: {
     opts: Options;
     type: PromptLineMethod;
     value: string;
    }) => void;
  columns: (opts: {
     opts: GlobalOptions;
     type: PromptLineMethod;
     value: ColumnData;
    }) => void;
  number: (opts: {
     errorText: string;
    }) => Promise<number | symbol>;
  table: (opts: {
     opts: TableUserConfig;
     type: PromptLineMethod;
     value: TableData;
    }) => void;
 } = _prompt;

Prompt functions

Type declaration

NameType
box(opts: { opts: Options; type: PromptLineMethod; value: string; }) => void
columns(opts: { opts: GlobalOptions; type: PromptLineMethod; value: ColumnData; }) => void
number(opts: { errorText: string; }) => Promise<number | symbol>
table(opts: { opts: TableUserConfig; type: PromptLineMethod; value: TableData; }) => void

style

ts
const style: {
  box: (text: string, options?: Options) => string;
  color: ChalkInstance;
  columns: <Data>(data: Data, options?: GlobalOptions) => string;
  gradient: (txt: string, colors: GradientColors, opts?: GradientOpts) => string;
  line: (__namedParameters: {
     align: 'center';
     lineChar: '⎯';
     title: string;
    }) => string;
  table: (data: TableData, options?: TableUserConfig) => string;
 } = _style;

Style functions

Type declaration

NameType
box(text: string, options?: Options) => string
colorChalkInstance
columns<Data>(data: Data, options?: GlobalOptions) => string
gradient(txt: string, colors: GradientColors, opts?: GradientOpts) => string
line(__namedParameters: { align: 'center'; lineChar: '⎯'; title: string; }) => string
table(data: TableData, options?: TableUserConfig) => string

sys

ts
const sys: __module = _sys;

System functions


TEXT_EDITOR

ts
const TEXT_EDITOR: {
  NONE: 'none';
  SUBLIME: 'subl';
  VSCODE: 'code';
  WEBSTORM: 'webstorm';
};

Text editor values used in openEditor option.

Type declaration

NameTypeDefault value
NONE"none"'none'
SUBLIME"subl"'subl'
VSCODE"code"'code'
WEBSTORM"webstorm"'webstorm'