depicta 0.9.0
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.
- package/bin/depicta.js +6 -0
- package/dist/client.d.ts +59 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +163 -0
- package/dist/client.js.map +1 -0
- package/dist/commands/auth.d.ts +13 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +188 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/docs.d.ts +10 -0
- package/dist/commands/docs.d.ts.map +1 -0
- package/dist/commands/docs.js +165 -0
- package/dist/commands/docs.js.map +1 -0
- package/dist/commands/generate.d.ts +17 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +254 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/guidelines.d.ts +9 -0
- package/dist/commands/guidelines.d.ts.map +1 -0
- package/dist/commands/guidelines.js +58 -0
- package/dist/commands/guidelines.js.map +1 -0
- package/dist/commands/jobs.d.ts +9 -0
- package/dist/commands/jobs.d.ts.map +1 -0
- package/dist/commands/jobs.js +89 -0
- package/dist/commands/jobs.js.map +1 -0
- package/dist/commands/process.d.ts +16 -0
- package/dist/commands/process.d.ts.map +1 -0
- package/dist/commands/process.js +412 -0
- package/dist/commands/process.js.map +1 -0
- package/dist/commands/story.d.ts +18 -0
- package/dist/commands/story.d.ts.map +1 -0
- package/dist/commands/story.js +182 -0
- package/dist/commands/story.js.map +1 -0
- package/dist/commands/utility.d.ts +11 -0
- package/dist/commands/utility.d.ts.map +1 -0
- package/dist/commands/utility.js +118 -0
- package/dist/commands/utility.js.map +1 -0
- package/dist/config.d.ts +50 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +103 -0
- package/dist/config.js.map +1 -0
- package/dist/download.d.ts +38 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +98 -0
- package/dist/download.js.map +1 -0
- package/dist/errors.d.ts +41 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +62 -0
- package/dist/errors.js.map +1 -0
- package/dist/flags.d.ts +41 -0
- package/dist/flags.d.ts.map +1 -0
- package/dist/flags.js +40 -0
- package/dist/flags.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/output.d.ts +44 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +125 -0
- package/dist/output.js.map +1 -0
- package/package.json +44 -0
package/dist/flags.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Commander.js option adder functions.
|
|
3
|
+
*
|
|
4
|
+
* Each addXxxFlags(cmd) function attaches standard option groups to a
|
|
5
|
+
* Command object. This avoids copy-pasting option definitions across
|
|
6
|
+
* all command files.
|
|
7
|
+
*
|
|
8
|
+
* Pattern: addGlobalFlags(cmd), addGenerationFlags(cmd), etc.
|
|
9
|
+
*/
|
|
10
|
+
import { Option } from 'commander';
|
|
11
|
+
/** Global flags available on every command (contract.yaml global_flags). */
|
|
12
|
+
export function addGlobalFlags(cmd) {
|
|
13
|
+
// --api-url is hidden from help per contract spec (used by tests/integration only).
|
|
14
|
+
const apiUrlOpt = new Option('--api-url <url>', 'Override API base URL').hideHelp();
|
|
15
|
+
return cmd
|
|
16
|
+
.option('--json', 'Force JSON output regardless of TTY detection', false)
|
|
17
|
+
.option('--human', 'Force human-readable output regardless of TTY detection', false)
|
|
18
|
+
.option('--api-key <key>', 'Override API key for this call')
|
|
19
|
+
.addOption(apiUrlOpt)
|
|
20
|
+
.option('-q, --quiet', 'Suppress informational output on stderr', false);
|
|
21
|
+
}
|
|
22
|
+
/** Generation command flags (model, size, output, format, etc.). */
|
|
23
|
+
export function addGenerationFlags(cmd) {
|
|
24
|
+
return cmd
|
|
25
|
+
.option('-m, --model <model>', 'Model name or alias')
|
|
26
|
+
.option('-s, --size <ratio>', 'Aspect ratio (e.g. 16:9, 1:1)')
|
|
27
|
+
.option('--image-size <size>', 'Resolution: 1K, 2K, 4K')
|
|
28
|
+
.option('-o, --output <path>', 'Output file path')
|
|
29
|
+
.option('-d, --output-dir <dir>', 'Output directory (auto-named file)')
|
|
30
|
+
.option('-f, --format <fmt>', 'Output format: png, jpg, webp', 'png')
|
|
31
|
+
.option('--quality <n>', 'JPEG/WebP quality 0-100', '85')
|
|
32
|
+
.option('--strictness <level>', 'Content classification strictness: normal, liberal');
|
|
33
|
+
}
|
|
34
|
+
/** Output path flags for processing commands. */
|
|
35
|
+
export function addOutputPathFlags(cmd) {
|
|
36
|
+
return cmd
|
|
37
|
+
.option('-o, --output <path>', 'Output file path')
|
|
38
|
+
.option('-d, --output-dir <dir>', 'Output directory');
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.js","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAW,MAAM,EAAE,MAAM,WAAW,CAAC;AAE5C,4EAA4E;AAC5E,MAAM,UAAU,cAAc,CAAC,GAAY;IACzC,oFAAoF;IACpF,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,CAAC,QAAQ,EAAE,CAAC;IACpF,OAAO,GAAG;SACP,MAAM,CAAC,QAAQ,EAAE,+CAA+C,EAAE,KAAK,CAAC;SACxE,MAAM,CAAC,SAAS,EAAE,yDAAyD,EAAE,KAAK,CAAC;SACnF,MAAM,CAAC,iBAAiB,EAAE,gCAAgC,CAAC;SAC3D,SAAS,CAAC,SAAS,CAAC;SACpB,MAAM,CAAC,aAAa,EAAE,yCAAyC,EAAE,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC7C,OAAO,GAAG;SACP,MAAM,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;SACpD,MAAM,CAAC,oBAAoB,EAAE,+BAA+B,CAAC;SAC7D,MAAM,CAAC,qBAAqB,EAAE,wBAAwB,CAAC;SACvD,MAAM,CAAC,qBAAqB,EAAE,kBAAkB,CAAC;SACjD,MAAM,CAAC,wBAAwB,EAAE,oCAAoC,CAAC;SACtE,MAAM,CAAC,oBAAoB,EAAE,+BAA+B,EAAE,KAAK,CAAC;SACpE,MAAM,CAAC,eAAe,EAAE,yBAAyB,EAAE,IAAI,CAAC;SACxD,MAAM,CAAC,sBAAsB,EAAE,oDAAoD,CAAC,CAAC;AAC1F,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC7C,OAAO,GAAG;SACP,MAAM,CAAC,qBAAqB,EAAE,kBAAkB,CAAC;SACjD,MAAM,CAAC,wBAAwB,EAAE,kBAAkB,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Depicta CLI — entry point.
|
|
3
|
+
*
|
|
4
|
+
* Sets up the Commander program, registers all subcommands,
|
|
5
|
+
* and provides a global error handler that maps DepictaError
|
|
6
|
+
* exit codes to process.exit() calls.
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import { DepictaError } from './errors.js';
|
|
10
|
+
import { detectMode, printError } from './output.js';
|
|
11
|
+
import { registerAuthCommands } from './commands/auth.js';
|
|
12
|
+
import { registerDocsCommand } from './commands/docs.js';
|
|
13
|
+
import { registerGenerateCommands } from './commands/generate.js';
|
|
14
|
+
import { registerProcessCommands } from './commands/process.js';
|
|
15
|
+
import { registerStoryCommands } from './commands/story.js';
|
|
16
|
+
import { registerGuidelinesCommands } from './commands/guidelines.js';
|
|
17
|
+
import { registerJobsCommands } from './commands/jobs.js';
|
|
18
|
+
import { registerUtilityCommands } from './commands/utility.js';
|
|
19
|
+
/** Package version — kept in sync with package.json at build time. */
|
|
20
|
+
const VERSION = '0.9.0';
|
|
21
|
+
/** Build and return the top-level Commander program. */
|
|
22
|
+
function buildProgram() {
|
|
23
|
+
const program = new Command();
|
|
24
|
+
program
|
|
25
|
+
.name('depicta')
|
|
26
|
+
.description('Depicta CLI — generate and process images with AI')
|
|
27
|
+
.version(VERSION, '-V, --version', 'Output version number')
|
|
28
|
+
.helpOption('-h, --help', 'Display help')
|
|
29
|
+
// Commander exits on unknown options by default — allow pass-through for subcommands.
|
|
30
|
+
.allowUnknownOption(false);
|
|
31
|
+
// Register command groups and top-level commands.
|
|
32
|
+
registerAuthCommands(program);
|
|
33
|
+
registerDocsCommand(program);
|
|
34
|
+
registerGenerateCommands(program);
|
|
35
|
+
registerProcessCommands(program);
|
|
36
|
+
registerStoryCommands(program);
|
|
37
|
+
registerGuidelinesCommands(program);
|
|
38
|
+
registerJobsCommands(program);
|
|
39
|
+
registerUtilityCommands(program);
|
|
40
|
+
return program;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Main entry point.
|
|
44
|
+
* Runs the CLI and handles errors globally.
|
|
45
|
+
*/
|
|
46
|
+
async function main() {
|
|
47
|
+
const program = buildProgram();
|
|
48
|
+
try {
|
|
49
|
+
// Commander is async-compatible — await the parsed action.
|
|
50
|
+
await program.parseAsync(process.argv);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
// Detect output mode from global flags (already parsed by Commander).
|
|
54
|
+
const opts = program.opts();
|
|
55
|
+
const mode = detectMode({ forceJson: opts.json, forceHuman: opts.human });
|
|
56
|
+
if (err instanceof DepictaError) {
|
|
57
|
+
printError(err.toDict(), mode);
|
|
58
|
+
process.exit(err.exitCode);
|
|
59
|
+
}
|
|
60
|
+
if (err instanceof Error) {
|
|
61
|
+
// Check for network errors — suggest job recovery.
|
|
62
|
+
const msg = err.message.toLowerCase();
|
|
63
|
+
if (msg.includes('connect') ||
|
|
64
|
+
msg.includes('timeout') ||
|
|
65
|
+
msg.includes('network') ||
|
|
66
|
+
msg.includes('abort')) {
|
|
67
|
+
process.stderr.write('Generation may have completed. Check recent jobs with: depicta jobs list\n');
|
|
68
|
+
}
|
|
69
|
+
printError({ error: 'general_error', message: err.message }, mode);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
printError({ error: 'general_error', message: String(err) }, mode);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
main().catch((err) => {
|
|
77
|
+
process.stderr.write('Fatal: ' + String(err) + '\n');
|
|
78
|
+
process.exit(1);
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,C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|
+
* human: stdout = file path, stderr = chalk display
|
|
6
|
+
* json: stdout = full JSON object, stderr = JSON errors only
|
|
7
|
+
* pipe: stdout = file path, stderr = nothing unless error
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT: stderr receives all display output so that stdout remains
|
|
10
|
+
* pipeable (file path or JSON) regardless of mode.
|
|
11
|
+
*/
|
|
12
|
+
/** The three CLI output modes. */
|
|
13
|
+
export type OutputMode = 'human' | 'json' | 'pipe';
|
|
14
|
+
/**
|
|
15
|
+
* Determine output mode from flags and TTY state.
|
|
16
|
+
* --json takes priority; --human is next; then TTY detection.
|
|
17
|
+
*/
|
|
18
|
+
export declare function detectMode(opts: {
|
|
19
|
+
forceJson?: boolean;
|
|
20
|
+
forceHuman?: boolean;
|
|
21
|
+
}): OutputMode;
|
|
22
|
+
/** Write to stderr. Used for all display output (human mode). */
|
|
23
|
+
export declare function writeStderr(msg: string): void;
|
|
24
|
+
/** Print the shell history warning when --api-key flag is used. */
|
|
25
|
+
export declare function warnApiKeyFlag(_mode: OutputMode, quiet: boolean): void;
|
|
26
|
+
/** Print an error to stderr in the appropriate format. */
|
|
27
|
+
export declare function printError(error: {
|
|
28
|
+
error: string;
|
|
29
|
+
message: string;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}, mode: OutputMode): void;
|
|
32
|
+
/** Print a generation result in the appropriate output mode. */
|
|
33
|
+
export declare function printGeneration(filePath: string, data: {
|
|
34
|
+
cost_eur?: string;
|
|
35
|
+
balance_eur?: string;
|
|
36
|
+
image_hash?: string;
|
|
37
|
+
model?: string;
|
|
38
|
+
ai_generated?: boolean;
|
|
39
|
+
}, mode: OutputMode, quiet: boolean): void;
|
|
40
|
+
/** Print a processing result (file path only or JSON). */
|
|
41
|
+
export declare function printProcessing(filePath: string, mode: OutputMode, quiet: boolean): void;
|
|
42
|
+
/** Color-coded balance display for human mode. */
|
|
43
|
+
export declare function printBalance(balanceEur: string, heldEur: string, mode: OutputMode, quiet: boolean): void;
|
|
44
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D;AAClD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,OAAO,GACb,IAAI,CAmBN"}
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output formatting — TTY detection, three output modes, chalk display.
|
|
3
|
+
*
|
|
4
|
+
* Three modes (contract.yaml):
|
|
5
|
+
* human: stdout = file path, stderr = chalk display
|
|
6
|
+
* json: stdout = full JSON object, stderr = JSON errors only
|
|
7
|
+
* pipe: stdout = file path, stderr = nothing unless error
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT: stderr receives all display output so that stdout remains
|
|
10
|
+
* pipeable (file path or JSON) regardless of mode.
|
|
11
|
+
*/
|
|
12
|
+
import chalk from 'chalk';
|
|
13
|
+
/**
|
|
14
|
+
* Determine output mode from flags and TTY state.
|
|
15
|
+
* --json takes priority; --human is next; then TTY detection.
|
|
16
|
+
*/
|
|
17
|
+
export function detectMode(opts) {
|
|
18
|
+
if (opts.forceJson)
|
|
19
|
+
return 'json';
|
|
20
|
+
if (opts.forceHuman)
|
|
21
|
+
return 'human';
|
|
22
|
+
if (process.stdout.isTTY)
|
|
23
|
+
return 'human';
|
|
24
|
+
return 'pipe';
|
|
25
|
+
}
|
|
26
|
+
/** Write to stderr. Used for all display output (human mode). */
|
|
27
|
+
export function writeStderr(msg) {
|
|
28
|
+
process.stderr.write(msg + '\n');
|
|
29
|
+
}
|
|
30
|
+
/** Print the shell history warning when --api-key flag is used. */
|
|
31
|
+
export function warnApiKeyFlag(_mode, quiet) {
|
|
32
|
+
if (quiet)
|
|
33
|
+
return;
|
|
34
|
+
const msg = 'Warning: passing API keys via command line may expose them in shell history. Prefer DEPICTA_API_KEY env var.';
|
|
35
|
+
// Always goes to stderr regardless of mode.
|
|
36
|
+
process.stderr.write(msg + '\n');
|
|
37
|
+
}
|
|
38
|
+
/** Print an error to stderr in the appropriate format. */
|
|
39
|
+
export function printError(error, mode) {
|
|
40
|
+
if (mode === 'json' || mode === 'pipe') {
|
|
41
|
+
// Machine-readable JSON error to stderr.
|
|
42
|
+
process.stderr.write(JSON.stringify(error) + '\n');
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// Human-readable chalk error to stderr.
|
|
46
|
+
process.stderr.write(chalk.red('Error: ') + error.message + '\n');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Print a generation result in the appropriate output mode. */
|
|
50
|
+
export function printGeneration(filePath, data, mode, quiet) {
|
|
51
|
+
if (mode === 'json') {
|
|
52
|
+
// Full JSON to stdout — this is the programmatic output.
|
|
53
|
+
const result = {
|
|
54
|
+
file: filePath,
|
|
55
|
+
cost_eur: data.cost_eur ?? '0',
|
|
56
|
+
balance_eur: data.balance_eur ?? '0',
|
|
57
|
+
image_hash: data.image_hash ?? '',
|
|
58
|
+
model: data.model ?? '',
|
|
59
|
+
ai_generated: true,
|
|
60
|
+
};
|
|
61
|
+
process.stdout.write(JSON.stringify(result) + '\n');
|
|
62
|
+
}
|
|
63
|
+
else if (mode === 'human') {
|
|
64
|
+
if (!quiet) {
|
|
65
|
+
// Display output to stderr.
|
|
66
|
+
process.stderr.write(chalk.green('✓') + ' Saved to ' + filePath + '\n');
|
|
67
|
+
if (data.cost_eur !== undefined) {
|
|
68
|
+
process.stderr.write(' Cost: EUR ' + data.cost_eur + '\n');
|
|
69
|
+
}
|
|
70
|
+
if (data.balance_eur !== undefined) {
|
|
71
|
+
const bal = parseFloat(data.balance_eur);
|
|
72
|
+
const colored = bal > 5
|
|
73
|
+
? chalk.green('EUR ' + data.balance_eur)
|
|
74
|
+
: bal > 1
|
|
75
|
+
? chalk.yellow('EUR ' + data.balance_eur)
|
|
76
|
+
: chalk.red('EUR ' + data.balance_eur);
|
|
77
|
+
process.stderr.write(' Balance: ' + colored + '\n');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// File path always goes to stdout (pipeable).
|
|
81
|
+
process.stdout.write(filePath + '\n');
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// Pipe mode — file path only to stdout.
|
|
85
|
+
process.stdout.write(filePath + '\n');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Print a processing result (file path only or JSON). */
|
|
89
|
+
export function printProcessing(filePath, mode, quiet) {
|
|
90
|
+
if (mode === 'json') {
|
|
91
|
+
process.stdout.write(JSON.stringify({ file: filePath }) + '\n');
|
|
92
|
+
}
|
|
93
|
+
else if (mode === 'human') {
|
|
94
|
+
if (!quiet) {
|
|
95
|
+
process.stderr.write(chalk.green('✓') + ' Saved to ' + filePath + '\n');
|
|
96
|
+
}
|
|
97
|
+
process.stdout.write(filePath + '\n');
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
process.stdout.write(filePath + '\n');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Color-coded balance display for human mode. */
|
|
104
|
+
export function printBalance(balanceEur, heldEur, mode, quiet) {
|
|
105
|
+
if (mode === 'json') {
|
|
106
|
+
process.stdout.write(JSON.stringify({ balance_eur: balanceEur, held_eur: heldEur }) + '\n');
|
|
107
|
+
}
|
|
108
|
+
else if (mode === 'human' && !quiet) {
|
|
109
|
+
const bal = parseFloat(balanceEur);
|
|
110
|
+
const colored = bal > 5
|
|
111
|
+
? chalk.green('EUR ' + balanceEur)
|
|
112
|
+
: bal > 1
|
|
113
|
+
? chalk.yellow('EUR ' + balanceEur)
|
|
114
|
+
: chalk.red('EUR ' + balanceEur);
|
|
115
|
+
process.stderr.write(' Balance: ' + colored + '\n');
|
|
116
|
+
process.stderr.write(' Held: EUR ' + heldEur + '\n');
|
|
117
|
+
const available = bal - parseFloat(heldEur);
|
|
118
|
+
process.stderr.write(' Available: EUR ' + available.toFixed(6) + '\n');
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// Pipe mode — print JSON to stdout.
|
|
122
|
+
process.stdout.write(JSON.stringify({ balance_eur: balanceEur, held_eur: heldEur }) + '\n');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,IAG1B;IACC,IAAI,IAAI,CAAC,SAAS;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,IAAI,CAAC,UAAU;QAAE,OAAO,OAAO,CAAC;IACpC,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK;QAAE,OAAO,OAAO,CAAC;IACzC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;AACnC,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,cAAc,CAAC,KAAiB,EAAE,KAAc;IAC9D,IAAI,KAAK;QAAE,OAAO;IAClB,MAAM,GAAG,GACP,8GAA8G,CAAC;IACjH,4CAA4C;IAC5C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;AACnC,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,UAAU,CACxB,KAAiE,EACjE,IAAgB;IAEhB,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACvC,yCAAyC;QACzC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IACrD,CAAC;SAAM,CAAC;QACN,wCAAwC;QACxC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GA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C;IAC9F,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "depicta",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Depicta CLI — generate and process images with AI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"depicta": "./bin/depicta.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"build:watch": "tsc --watch",
|
|
12
|
+
"test": "vitest run",
|
|
13
|
+
"test:watch": "vitest",
|
|
14
|
+
"lint": "eslint src tests",
|
|
15
|
+
"typecheck": "tsc --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"chalk": "^5.3.0",
|
|
19
|
+
"cli-table3": "^0.6.5",
|
|
20
|
+
"commander": "^12.1.0",
|
|
21
|
+
"env-paths": "^3.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^20.0.0",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
26
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
27
|
+
"eslint": "^8.57.0",
|
|
28
|
+
"typescript": "^5.4.0",
|
|
29
|
+
"vitest": "^1.5.0"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"bin/",
|
|
36
|
+
"dist/"
|
|
37
|
+
],
|
|
38
|
+
"keywords": ["depicta", "ai", "image", "cli"],
|
|
39
|
+
"license": "UNLICENSED",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/30ohm/depicta-cli-node.git"
|
|
43
|
+
}
|
|
44
|
+
}
|