Programmatic Usage
Kosko provides a programmatic API. You can generate manifests directly from Node.js.
Install
- NPM
- Yarn
- PNPM
npm install @kosko/env @kosko/generate
yarn add @kosko/env @kosko/generate
pnpm install @kosko/env @kosko/generate
Example
- TypeScript
- JavaScript (ESM)
- JavaScript (CJS)
import env from "@kosko/env";
import { generate, print, PrintFormat } from "@kosko/generate";
import path from "node:path";
(async () => {
// Set environment
env.env = "dev";
// Set CWD (Optional)
env.cwd = __dirname;
// Generate manifests
const result = await generate({
path: path.join(env.cwd, "components"),
components: ["*"]
});
// Print manifests to stdout
print(result, {
format: PrintFormat.YAML,
writer: process.stdout
});
})();
import env from "@kosko/env";
import { generate, print, PrintFormat } from "@kosko/generate";
import path from "node:path";
(async () => {
// Set environment
env.env = "dev";
// Set CWD (Optional)
env.cwd = __dirname;
// Generate manifests
const result = await generate({
path: path.join(env.cwd, "components"),
components: ["*"]
});
// Print manifests to stdout
print(result, {
format: PrintFormat.YAML,
writer: process.stdout
});
})();
const env = require("@kosko/env");
const { generate, print, PrintFormat } = require("@kosko/generate");
const path = require("node:path");
(async () => {
// Set environment
env.env = "dev";
// Set CWD (Optional)
env.cwd = __dirname;
// Generate manifests
const result = await generate({
path: path.join(env.cwd, "components"),
components: ["*"]
});
// Print manifests to stdout
print(result, {
format: PrintFormat.YAML,
writer: process.stdout
});
})();