Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,5 @@ jobs:
run: npm ci

- name: Run security audit
run: npm audit --audit-level high

- name: Check for vulnerabilities
run: npm audit --audit-level moderate
# Fails on moderate+; audit-ci.jsonc allowlists advisories that have no fixed release.
run: npx --yes audit-ci@7.1.0 --config audit-ci.jsonc
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.0] - 2026-10-11

### Added
- `generate --json`: progress as JSON lines (`step`, `log`, `result`). Never prompts; every prompt site fails with an error code instead. SIGTERM/SIGINT report `CANCELLED` and exit 130.
- `generate --host <ip>`: use a specific device without changing the saved one. Cannot be combined with `--discover`.
- `inspect <dir> [--json]`: manifest, build folder and VSCode tasks of a Roku app folder.
- Projects can store `defaultBuildTask`, used by `--json` runs when no build flag is given.

### Changed
- The config file (`~/.roku-pkg/config.json`) is now written readable only by its owner (0600). It holds sign keys and the device password.

## [1.0.0] - 2024-01-XX

### Added
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,33 @@ roku-pkg generate MyApp
roku-pkg generate # Select from list
```

### Machine-readable output (`--json`)

`generate --json` prints one JSON object per line and never prompts, so other tools (and Roku Dev Studio's Packager) can drive it:

```bash
roku-pkg generate CNBC --json --host 192.168.0.13 --password "$ROKU_DEV_PASSWORD" --use-existing-build
```

```
{"type":"step","step":"home","status":"start"}
{"type":"step","step":"home","status":"done","ms":2010}
{"type":"step","step":"build","status":"skip","detail":"used existing build"}
...
{"type":"result","ok":true,"packagePath":"/Users/me/builds/CNBC.pkg","sizeBytes":19293184,"version":"4.12.0"}
```

Steps are `home`, `build`, `validate`, `rekey`, `deploy`, `sign` and `save`. A failed run ends with
`{"type":"result","ok":false,"step":"rekey","code":"REKEY_FAILED","message":"...","hint":"..."}`.
Error codes: `PROJECT_NOT_FOUND`, `DEVICE_UNREACHABLE`, `AUTH_FAILED`, `NEEDS_BUILD_CHOICE`, `TASK_NOT_FOUND`,
`BUILD_FAILED`, `BUILD_TIMEOUT`, `INVALID_BUILD`, `SIGNED_PKG_MISSING`, `REKEY_FAILED`, `DEPLOY_FAILED`,
`DEPLOY_TIMEOUT`, `SIGN_FAILED`, `CANCELLED`, `UNKNOWN`. Exit code is 0 on success, 1 on failure, 130 when cancelled.

With no build flag, `--json` uses the project's `defaultBuildTask`; if it has none and VSCode tasks exist, it fails with `NEEDS_BUILD_CHOICE`.

### `roku-pkg inspect <dir> [--json]`
Shows what roku-pkg detects in an app folder: manifest title and version, the build folder (and where it came from), and the VSCode tasks.

## Project Structure Requirements

Your Roku app must follow the standard structure:
Expand Down
12 changes: 12 additions & 0 deletions audit-ci.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://github.com/IBM/audit-ci/raw/main/docs/schema.json",
// Fail on moderate and above, except advisories with no patched release.
"moderate": true,
"allowlist": [
// braces <=3.0.3 stack-exhaustion DoS; 3.0.3 is the latest release. Pulled in via
// micromatch (roku-deploy, jest). We only expand our own glob patterns, never user input.
"GHSA-vfj7-8cjw-p6xm",
// sprintf-js <=1.1.3 DoS; 1.1.3 is the latest release. Dev-only (argparse via test tooling).
"GHSA-hp3w-g68c-fv3c"
]
}
2,567 changes: 1,129 additions & 1,438 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "roku-pkg-cli",
"version": "1.1.5",
"version": "1.2.0",
"description": "A comprehensive CLI tool for managing multiple Roku projects with automated device discovery, build integration, and package generation. Perfect for CI/CD pipelines with full automation support.",
"main": "dist/index.js",
"bin": {
Expand Down Expand Up @@ -68,6 +68,7 @@
"@types/jest": "^29.5.14",
"@types/node": "^22.12.1",
"jest": "^29.7.0",
"jest-util": "^29.7.0",
"ts-jest": "^29.2.5",
"tsx": "^4.19.2",
"typescript": "^5.7.3"
Expand Down
37 changes: 37 additions & 0 deletions src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { getBuildDirectory, extractBuildConfig, readBSConfig } from '../utils/vs
import { getBuildTasks, executeTask, getAllTasks } from '../utils/vscode-tasks';
import { DiscoveredDevice, RokuDevice } from '../types';
import axios from 'axios';
import { createEmitter, captureConsole } from '../lib/events';
import { runGenerateJson } from '../lib/generate-json';

/**
* Wait for build output to be ready by checking for required files
Expand Down Expand Up @@ -57,7 +59,41 @@ export function generateCommand(program: Command) {
.option('--discover', 'Discover and select a Roku device before processing')
.option('--first-device', 'Automatically use the first discovered device (requires --discover)')
.option('--password <password>', 'Provide the developer password (avoids interactive prompt)')
.option('--host <ip>', 'Use the Roku at this IP instead of the configured device')
.option('--json', 'Print progress as JSON lines (one event per line) and never prompt')
.action(async (projectName?: string, options?: any) => {
if (options?.json) {
const emitter = createEmitter((line) => process.stdout.write(line));
if (options.host && options.discover) {
emitter.emit({ type: 'result', ok: false, code: 'UNKNOWN', message: '--host cannot be combined with --discover' });
process.stdout.write('', () => process.exit(1));
return;
}
const restore = captureConsole(emitter);
const controller = new AbortController();
const cancel = () => controller.abort();
process.once('SIGTERM', cancel);
process.once('SIGINT', cancel);
const code = await runGenerateJson({
project: projectName,
host: options.host,
password: options.password,
buildTask: options.buildTask,
useExistingBuild: options.useExistingBuild,
skipBuild: options.skipBuild,
skipRekey: options.skipRekey,
packageOnly: options.packageOnly,
signal: controller.signal,
}, emitter);
restore();
// Exit only after stdout drains: a pipe can still hold the final result line.
process.stdout.write('', () => process.exit(code));
return;
}
if (options?.host && options?.discover) {
console.log(chalk.red('\nError: --host cannot be combined with --discover\n'));
return;
}
// Validate flag combinations
if (options?.firstDevice && !options?.discover) {
console.log(chalk.red('\nError: --first-device can only be used with --discover\n'));
Expand Down Expand Up @@ -92,6 +128,7 @@ export function generateCommand(program: Command) {
}

let device = configManager.getRokuDevice();
if (options?.host) device = { ...device, ip: options.host, password: options?.password ?? device.password };

// If discover option is provided, run device discovery first
if (options?.discover) {
Expand Down
20 changes: 20 additions & 0 deletions src/commands/inspect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Command } from 'commander';
import * as path from 'path';
import { inspectProject } from '../lib/inspect';

export function inspectCommand(program: Command): void {
program
.command('inspect <dir>')
.description('Show what roku-pkg detects in a Roku app folder (manifest, build folder, VSCode tasks)')
.option('--json', 'Print one JSON object')
.action((dir: string, options: { json?: boolean }) => {
const result = inspectProject(path.resolve(dir.replace(/^~(?=$|\/)/, process.env.HOME ?? '~')));
if (options.json) {
process.stdout.write(JSON.stringify(result) + '\n');
return;
}
console.log(`Manifest: ${result.manifest ? `${result.manifest.title ?? '?'} ${result.manifest.version ?? ''}` : 'not found'}`);
console.log(`Build folder: ${result.buildDir} (${result.buildDirSource}${result.buildExists ? '' : ', not built'})`);
console.log(`Tasks: ${result.tasks.map((t) => t.label).join(', ') || 'none'}`);
});
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { discoverCommand } from './commands/discover';
import { generateCommand } from './commands/generate';
import { editCommand } from './commands/edit';
import { removeCommand } from './commands/remove';
import { inspectCommand } from './commands/inspect';

const program = new Command();

Expand All @@ -30,6 +31,7 @@ discoverCommand(program);
generateCommand(program);
editCommand(program);
removeCommand(program);
inspectCommand(program);

program.parse(process.argv);

Expand Down
7 changes: 3 additions & 4 deletions src/lib/config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ export class ConfigManager {
}

private saveConfig(): void {
fs.writeFileSync(
this.configPath,
JSON.stringify(this.config, null, 2)
);
// Holds sign keys and the device password: owner-only.
fs.writeFileSync(this.configPath, JSON.stringify(this.config, null, 2), { mode: 0o600 });
fs.chmodSync(this.configPath, 0o600);
}

getConfig(): Config {
Expand Down
50 changes: 50 additions & 0 deletions src/lib/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { format } from 'util';

export type Step = 'home' | 'build' | 'validate' | 'rekey' | 'deploy' | 'sign' | 'save';
export type ErrorCode =
| 'PROJECT_NOT_FOUND' | 'DEVICE_UNREACHABLE' | 'AUTH_FAILED' | 'NEEDS_BUILD_CHOICE'
| 'TASK_NOT_FOUND' | 'BUILD_FAILED' | 'BUILD_TIMEOUT' | 'INVALID_BUILD' | 'SIGNED_PKG_MISSING'
| 'REKEY_FAILED' | 'DEPLOY_FAILED' | 'DEPLOY_TIMEOUT' | 'SIGN_FAILED' | 'CANCELLED' | 'UNKNOWN';
export type StepStatus = 'start' | 'done' | 'skip' | 'fail';
export type PkgEvent =
| { type: 'step'; step: Step; status: StepStatus; ms?: number; detail?: string }
| { type: 'log'; level: 'info' | 'warn' | 'error'; text: string }
| { type: 'result'; ok: true; packagePath: string; sizeBytes: number; version?: string }
| { type: 'result'; ok: false; step?: Step; code: ErrorCode; message: string; hint?: string };

export class GenerateError extends Error {
code: ErrorCode;
step?: Step;
hint?: string;
constructor(code: ErrorCode, message: string, opts: { step?: Step; hint?: string } = {}) {
super(message);
this.code = code;
this.step = opts.step;
this.hint = opts.hint;
}
}

export interface Emitter {
emit(e: PkgEvent): void;
step(step: Step, status: StepStatus, extra?: { ms?: number; detail?: string }): void;
log(level: 'info' | 'warn' | 'error', text: string): void;
}

export function createEmitter(write: (line: string) => void): Emitter {
const emit = (e: PkgEvent) => write(JSON.stringify(e) + '\n');
return {
emit,
step: (step, status, extra = {}) => emit({ type: 'step', step, status, ...extra }),
log: (level, text) => emit({ type: 'log', level, text }),
};
}

/** In --json mode stdout carries only events: route stray console output (ours and roku-deploy's) into log events. */
export function captureConsole(emitter: Emitter): () => void {
const saved = { log: console.log, info: console.info, warn: console.warn, error: console.error };
console.log = (...a: unknown[]) => emitter.log('info', format(...a));
console.info = (...a: unknown[]) => emitter.log('info', format(...a));
console.warn = (...a: unknown[]) => emitter.log('warn', format(...a));
console.error = (...a: unknown[]) => emitter.log('error', format(...a));
return () => { Object.assign(console, saved); };
}
Loading
Loading