roku-pkg-cli
Version:
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.
178 lines (177 loc) • 6.79 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.readVSCodeConfig = readVSCodeConfig;
exports.readBSConfig = readBSConfig;
exports.extractBuildConfig = extractBuildConfig;
exports.getBuildDirectory = getBuildDirectory;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
/**
* Read and parse VSCode launch.json configuration
*/
function readVSCodeConfig(projectRootDir) {
const launchJsonPath = path.join(projectRootDir, '.vscode', 'launch.json');
if (!fs.existsSync(launchJsonPath)) {
return null;
}
try {
// Read the file content
const content = fs.readFileSync(launchJsonPath, 'utf8');
// Remove comments and trailing commas (more aggressive cleaning)
let jsonContent = content
.replace(/\/\*[\s\S]*?\*\//g, '') // Remove block comments
.replace(/\/\/.*$/gm, ''); // Remove line comments
// Remove trailing commas before ] or }
jsonContent = jsonContent
.replace(/,\s*\]/g, ']') // Remove trailing comma before ]
.replace(/,\s*\}/g, '}'); // Remove trailing comma before }
// Parse JSON
const config = JSON.parse(jsonContent);
return config;
}
catch (error) {
console.error('Error parsing launch.json:', error);
return null;
}
}
/**
* Read and parse bsconfig.json configuration
*/
function readBSConfig(projectRootDir) {
const bsconfigPath = path.join(projectRootDir, 'bsconfig.json');
if (!fs.existsSync(bsconfigPath)) {
return null;
}
try {
// Read the file content
const content = fs.readFileSync(bsconfigPath, 'utf8');
// Remove comments and trailing commas (more aggressive cleaning)
let jsonContent = content
.replace(/\/\*[\s\S]*?\*\//g, '') // Remove block comments
.replace(/\/\/.*$/gm, ''); // Remove line comments
// Remove trailing commas before ] or }
jsonContent = jsonContent
.replace(/,\s*\]/g, ']') // Remove trailing comma before ]
.replace(/,\s*\}/g, '}'); // Remove trailing comma before }
// Parse JSON
const config = JSON.parse(jsonContent);
return config;
}
catch (error) {
console.error('Error parsing bsconfig.json:', error);
console.error('File path:', bsconfigPath);
return null;
}
}
/**
* Extract build configuration from VSCode launch.json
*/
function extractBuildConfig(projectRootDir) {
const vsCodeConfig = readVSCodeConfig(projectRootDir);
if (!vsCodeConfig || !vsCodeConfig.configurations) {
return null;
}
// Find the first BrightScript configuration
const brsConfig = vsCodeConfig.configurations.find(config => config.type === 'brightscript' || config.type === 'roku');
if (!brsConfig) {
return null;
}
// Extract build configuration
const buildConfig = {
rootDir: brsConfig.rootDir || projectRootDir,
outDir: brsConfig.outDir,
stagingFolderPath: brsConfig.stagingFolderPath,
files: brsConfig.files,
sourceDirs: brsConfig.sourceDirs
};
// Resolve paths relative to project root
if (buildConfig.rootDir && !path.isAbsolute(buildConfig.rootDir)) {
buildConfig.rootDir = path.join(projectRootDir, buildConfig.rootDir);
}
if (buildConfig.outDir && !path.isAbsolute(buildConfig.outDir)) {
buildConfig.outDir = path.join(projectRootDir, buildConfig.outDir);
}
if (buildConfig.stagingFolderPath && !path.isAbsolute(buildConfig.stagingFolderPath)) {
buildConfig.stagingFolderPath = path.join(projectRootDir, buildConfig.stagingFolderPath);
}
return buildConfig;
}
/**
* Get the effective build directory from VSCode config or fallback
*/
function getBuildDirectory(projectRootDir) {
// First check VSCode launch.json
const buildConfig = extractBuildConfig(projectRootDir);
if (buildConfig) {
// Priority order: stagingFolderPath > outDir > rootDir
if (buildConfig.stagingFolderPath && fs.existsSync(buildConfig.stagingFolderPath)) {
return buildConfig.stagingFolderPath;
}
if (buildConfig.outDir && fs.existsSync(buildConfig.outDir)) {
return buildConfig.outDir;
}
}
// Check bsconfig.json
const bsConfig = readBSConfig(projectRootDir);
if (bsConfig) {
if (bsConfig.stagingDir) {
const stagingPath = path.isAbsolute(bsConfig.stagingDir)
? bsConfig.stagingDir
: path.join(projectRootDir, bsConfig.stagingDir);
if (fs.existsSync(stagingPath)) {
return stagingPath;
}
}
if (bsConfig.outDir) {
const outPath = path.isAbsolute(bsConfig.outDir)
? bsConfig.outDir
: path.join(projectRootDir, bsConfig.outDir);
if (fs.existsSync(outPath)) {
return outPath;
}
}
}
// Fallback to common build directories
const commonBuildDirs = ['.build', 'dist', 'build', 'out', '.out'];
for (const dir of commonBuildDirs) {
const buildPath = path.join(projectRootDir, dir);
if (fs.existsSync(buildPath)) {
return buildPath;
}
}
// Final fallback to project root
return projectRootDir;
}