Quick Start
Ensure you have the latest version of NodeJS and a package manager such as NPM. Running one command starts the interactive project creator:
npm init func
# or
pnpm create funcDevelopment
After you create an initial project, you will see these files:
.
|-- src
| |-- app.module.ts application module
| |-- commands
| | |-- hello.ts "hello" command
| | |-- major.ts empty invocation, --help, --version
| | +-- index.ts command list
| +-- index.ts runs AppModule
|-- tests testcases
| |-- commands test for commands
| +-- utils test utils
|-- package.json
|-- tsconfig.json
+-- README.mdBefore editing, install the dependencies and set up the development environment:
npm i
npm run dev --At this point, all preparation is complete.
You can browse the examples in commands, modify them, and run your
commands through the local TypeScript entry:
npm run dev -- hello
npm run dev -- --versionThe template registers commands through a root application module:
import { FuncModule } from 'func'
import { commands } from './commands'
@FuncModule({
commands,
})
export class AppModule {}
A command is a class with one or more @Handler methods:
import { Command, Handler } from 'func'
@Command({
name: 'hello',
description: 'print hello text',
})
export class Hello {
@Handler()
run() {
console.log('hello command trigger!')
}
}Bundle
If you use the template to create a project, you only need one command to package it:
npm run buildAfter running the command, your project is packaged into the configured output directory.
funcgo build bundles the configured entry and writes an executable
bin.js. The template already points package.json#bin
at that generated file.
Publish
Publish your package after the build output has been generated. The template
already points package.json#bin at the generated executable.