Programmatic Usage
Kosko provides a programmatic API. You can generate manifests directly from Node.js.
Install
In order to use the programmatic API, you have to install @kosko/env
and @kosko/generate
package.
npm install @kosko/env @kosko/generate
Example
- TypeScript
- JavaScript
import env from "@kosko/env";
import { generate, print, PrintFormat } from "@kosko/generate";
import path from "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("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
});
})();
Related
📄️ @kosko/env
This page is for @kosko/env v2.0.
📄️ @kosko/generate
Enumerations