@choiceopen/automation-plugin-cli 0.0.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +0,0 @@
1
- import { Args, Command, Flags } from "@oclif/core";
2
- export default class PluginRun extends Command {
3
- static args = {
4
- file: Args.string({ description: "file to read" }),
5
- };
6
- static description = "describe the command here";
7
- static examples = ["<%= config.bin %> <%= command.id %>"];
8
- static flags = {
9
- // flag with no value (-f, --force)
10
- force: Flags.boolean({ char: "f" }),
11
- // flag with a value (-n, --name=VALUE)
12
- name: Flags.string({ char: "n", description: "name to print" }),
13
- };
14
- async run() {
15
- const { args, flags } = await this.parse(PluginRun);
16
- const name = flags.name ?? "world";
17
- this.log(`hello ${name} from /Users/nightire/Code/github.com/choice-open/automation-plugin-cli/src/commands/plugin/run.ts`);
18
- if (args.file && flags.force) {
19
- this.log(`you input --force and --file: ${args.file}`);
20
- }
21
- }
22
- }
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { run } from "@oclif/core";
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- export { run } from "@oclif/core";
@@ -1,12 +0,0 @@
1
- import { z } from "zod";
2
- declare const ConfigSchema: z.ZodObject<{
3
- auth: z.ZodOptional<z.ZodObject<{
4
- endpoint: z.ZodOptional<z.ZodURL>;
5
- access_token: z.ZodOptional<z.ZodString>;
6
- }, z.core.$strip>>;
7
- }, z.core.$strip>;
8
- export type Config = z.infer<typeof ConfigSchema>;
9
- export declare function save(config: Config): Promise<void>;
10
- export declare function load(): Promise<Config>;
11
- export declare function update(updates: Partial<Config>): Promise<void>;
12
- export {};
@@ -1,55 +0,0 @@
1
- import { promises as fs } from "node:fs";
2
- import { homedir } from "node:os";
3
- import { join } from "node:path";
4
- import { toMerged } from "es-toolkit/object";
5
- import { z } from "zod";
6
- function getConfigDir() {
7
- return process.env.CHOICEFORM_CONFIG_DIR ?? join(homedir(), ".choiceform");
8
- }
9
- function getConfigFile() {
10
- return join(getConfigDir(), "automation.json");
11
- }
12
- const ConfigSchema = z.object({
13
- auth: z
14
- .object({
15
- endpoint: z.url().optional(),
16
- access_token: z.string().optional(),
17
- })
18
- .optional(),
19
- });
20
- export async function save(config) {
21
- const validated = ConfigSchema.parse(config);
22
- const configDir = getConfigDir();
23
- const configFile = getConfigFile();
24
- await fs.mkdir(configDir, { recursive: true });
25
- await fs.writeFile(configFile, JSON.stringify(validated, null, 2), "utf-8");
26
- }
27
- export async function load() {
28
- const configFile = getConfigFile();
29
- try {
30
- await fs.access(configFile);
31
- }
32
- catch (error) {
33
- if (error instanceof Error &&
34
- ("code" in error ? error.code === "ENOENT" : false)) {
35
- const defaultConfig = {
36
- auth: {
37
- endpoint: process.env.NODE_ENV === "production"
38
- ? "https://oneauth.choiceform.io"
39
- : "http://localhost:5001",
40
- },
41
- };
42
- await save(defaultConfig);
43
- return defaultConfig;
44
- }
45
- throw error;
46
- }
47
- const content = await fs.readFile(configFile, "utf-8");
48
- const parsed = JSON.parse(content);
49
- return ConfigSchema.parse(parsed);
50
- }
51
- export async function update(updates) {
52
- const existing = await load();
53
- const merged = toMerged(existing ?? {}, updates);
54
- await save(merged);
55
- }
@@ -1,20 +0,0 @@
1
- import { Eta } from "eta";
2
- export interface PluginGenerator {
3
- context: {
4
- props: Record<string, unknown>;
5
- target: string;
6
- };
7
- renderer: Eta;
8
- type: string;
9
- generate(): Promise<void>;
10
- }
11
- export declare function createPluginGenerator(type: PluginGenerator["type"], context: PluginGenerator["context"]): PluginGenerator;
12
- export declare class TypeScriptPluginGenerator implements PluginGenerator {
13
- #private;
14
- context: PluginGenerator["context"];
15
- type: "typescript";
16
- renderer: Eta;
17
- constructor(context: PluginGenerator["context"]);
18
- generate(): Promise<void>;
19
- private groupPermissions;
20
- }
@@ -1,68 +0,0 @@
1
- import { copyFile, mkdir, readdir, writeFile } from "node:fs/promises";
2
- import { basename, extname, join } from "node:path";
3
- import { Eta } from "eta";
4
- export function createPluginGenerator(type, context) {
5
- switch (type) {
6
- case "typescript":
7
- return new TypeScriptPluginGenerator(context);
8
- default:
9
- throw new Error(`Plugin generator type "${type}" is not implemented.`);
10
- }
11
- }
12
- export class TypeScriptPluginGenerator {
13
- context;
14
- type = "typescript";
15
- renderer = new Eta({
16
- autoTrim: false,
17
- autoEscape: false,
18
- varName: "props",
19
- views: join(import.meta.dirname, "../templates"),
20
- });
21
- constructor(context) {
22
- this.context = context;
23
- this.context.props.permissions = this.groupPermissions(this.context.props.permissions);
24
- }
25
- async generate() {
26
- await Promise.all([
27
- this.#generateFiles(join(import.meta.dirname, "../templates/common")),
28
- this.#generateFiles(join(import.meta.dirname, `../templates/${this.context.props.language}`)),
29
- ]);
30
- }
31
- async #generateFiles(source, target = this.context.target) {
32
- await mkdir(target, { recursive: true });
33
- for (const entry of await readdir(source, { withFileTypes: true })) {
34
- const sourcePath = join(source, entry.name);
35
- if (entry.isDirectory()) {
36
- await this.#generateFiles(sourcePath, join(target, entry.name));
37
- }
38
- else {
39
- if (extname(sourcePath).toLowerCase() === ".eta") {
40
- console.info(sourcePath, entry, this.renderer);
41
- const fileName = basename(sourcePath, extname(sourcePath));
42
- const templatePath = sourcePath.replace(this.renderer.config.views ?? "", "");
43
- const content = this.renderer.render(templatePath, this.context.props);
44
- const targetPath = join(target, fileName);
45
- await writeFile(targetPath, content, "utf-8");
46
- }
47
- else {
48
- await copyFile(sourcePath, join(target, entry.name));
49
- }
50
- }
51
- }
52
- }
53
- groupPermissions(permissions) {
54
- return permissions
55
- .reduce((finale, permission) => {
56
- const [scope, entry] = permission.split(":");
57
- const existing = finale.find((item) => item.scope === scope);
58
- if (existing) {
59
- existing.entries.push(entry);
60
- }
61
- else {
62
- finale.push({ scope, entries: [entry] });
63
- }
64
- return finale;
65
- }, [])
66
- .sort((a, b) => a.scope.localeCompare(b.scope, "en"));
67
- }
68
- }
@@ -1,13 +0,0 @@
1
- export declare const checkboxTheme: {
2
- icon: {
3
- checked: string;
4
- unchecked: string;
5
- cursor: string;
6
- };
7
- };
8
- export declare const selectTheme: {
9
- icon: {
10
- cursor: string;
11
- };
12
- indexMode: "number";
13
- };
@@ -1,13 +0,0 @@
1
- export const checkboxTheme = {
2
- icon: {
3
- checked: " [✔︎]",
4
- unchecked: " [ ]",
5
- cursor: "→",
6
- },
7
- };
8
- export const selectTheme = {
9
- icon: {
10
- cursor: "→",
11
- },
12
- indexMode: "number",
13
- };
@@ -1,2 +0,0 @@
1
- import { Eta } from "eta";
2
- export declare const views: Eta;
@@ -1,8 +0,0 @@
1
- import path from "node:path";
2
- import { Eta } from "eta";
3
- export const views = new Eta({
4
- autoTrim: false,
5
- autoEscape: false,
6
- varName: "props",
7
- views: path.join(import.meta.dirname, "../templates"),
8
- });