{"id":17020,"library":"inline-source-cli","title":"Inline Source CLI: HTML Resource Inliner","description":"The `inline-source-cli` package offers a dedicated command-line interface (CLI) for the `inline-source` library, a utility designed to embed external resources such as CSS stylesheets, JavaScript code, and image data directly into an HTML file. This functionality is crucial for scenarios requiring self-contained HTML documents, such as preparing email templates, optimizing static site assets for single-file deployment, or creating portable web components. The package is currently at stable version 2.0.0, with a release cadence that appears driven by dependency updates or minor feature enhancements like the addition of stdin support. Its primary advantage lies in providing a straightforward, opinionated command-line tool that abstracts away the programmatic complexity of resource inlining, making it easy to integrate into existing build scripts and CI/CD pipelines without writing custom JavaScript code. Developers can quickly achieve asset optimization and delivery benefits without deep diving into the underlying library's API, using standard shell commands.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/popeindustries/inline-source-cli","tags":["javascript","inline","source","cli","inliner"],"install":[{"cmd":"npm install inline-source-cli","lang":"bash","label":"npm"},{"cmd":"yarn add inline-source-cli","lang":"bash","label":"yarn"},{"cmd":"pnpm add inline-source-cli","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This CLI wraps the core functionality of the inline-source library.","package":"inline-source","optional":false}],"imports":[{"note":"This package is a command-line interface (CLI) and does not export programmatic symbols. Its primary interaction is via the `inline-source` executable. Programmatic use involves spawning a child process.","wrong":"import { runCli } from 'inline-source-cli';","symbol":"inline-source-cli executable","correct":"import { spawn } from 'child_process';\nspawn('inline-source', ['--root', './', 'file.html'], { stdio: 'inherit' });"},{"note":"For robust programmatic execution from Node.js, external libraries like 'execa' are commonly used. Directly requiring internal CLI files is unsupported and highly unstable.","wrong":"const inlineSourceCli = require('inline-source-cli/cli');","symbol":"Programmatic execution (using execa)","correct":"import { execa } from 'execa';\nawait execa('inline-source', ['--root', './', 'file.html']);"},{"note":"As a pure CLI wrapper, this package does not provide TypeScript type definitions for its own use. Type definitions for the underlying inlining options would come from the `inline-source` library directly.","wrong":"import type { InlineSourceOptions } from 'inline-source-cli';","symbol":"Type definitions","correct":"/* This CLI package does not export types for programmatic use. */"}],"quickstart":{"code":"import { spawn } from 'child_process';\nimport path from 'path';\nimport fs from 'fs';\n\n// Create a dummy HTML file and resources for demonstration\nconst buildDir = path.join(process.cwd(), 'build-cli-demo');\nif (!fs.existsSync(buildDir)) fs.mkdirSync(buildDir, { recursive: true });\n\nfs.writeFileSync(path.join(buildDir, 'style.css'), 'h1 { color: blue; }');\nfs.writeFileSync(path.join(buildDir, 'script.js'), 'console.log(\\'Script inlined!\\');');\nfs.writeFileSync(path.join(buildDir, 'index.html'), `<!DOCTYPE html>\\n<html>\\n<head>\\n    <link rel=\\\"stylesheet\\\" href=\\\"./style.css\\\">\\n</head>\\n<body>\\n    <h1>Hello, Inliner!</h1>\\n    <script src=\\\"./script.js\\\"></script>\\n</body>\\n</html>`);\n\nconsole.log('Created dummy files in:', buildDir);\n\n// Resolve the path to the inline-source CLI executable\nconst inlineSourceCliPath = path.resolve(process.cwd(), 'node_modules', '.bin', 'inline-source');\n\n// Execute the inline-source CLI tool\nconst child = spawn(inlineSourceCliPath, [\n  '--compress', 'false',\n  '--root', buildDir,\n  path.join(buildDir, 'index.html')\n], { stdio: 'pipe' });\n\nlet output = '';\nchild.stdout.on('data', (data) => {\n  output += data.toString();\n});\n\nchild.stderr.on('data', (data) => {\n  console.error(`stderr: ${data}`);\n});\n\nchild.on('close', (code) => {\n  if (code === 0) {\n    console.log('\\n--- Inlined HTML Output ---');\n    console.log(output);\n    fs.writeFileSync(path.join(buildDir, 'bundle.html'), output);\n    console.log('\\nOutput written to', path.join(buildDir, 'bundle.html'));\n  } else {\n    console.error(`CLI process exited with code ${code}`);\n  }\n  // Clean up dummy files\n  fs.unlinkSync(path.join(buildDir, 'index.html'));\n  fs.unlinkSync(path.join(buildDir, 'style.css'));\n  fs.unlinkSync(path.join(buildDir, 'script.js'));\n  fs.unlinkSync(path.join(buildDir, 'bundle.html'));\n  fs.rmdirSync(buildDir);\n  console.log('Cleaned up dummy files.');\n});","lang":"javascript","description":"Demonstrates how to programmatically execute `inline-source-cli` from a Node.js script, creating dummy files, running the inliner, and capturing its output."},"warnings":[{"fix":"Upgrade your Node.js runtime to version 8.3.0 or higher.","message":"Version 2.0.0 bumped the minimum required Node.js version to `8.3.0`. Older Node.js environments will not be supported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Consult the changelog of the `inline-source` package (e.g., `npm view inline-source versions`) for changes in its major versions.","message":"Breaking changes or new features in the underlying `inline-source` library may implicitly affect `inline-source-cli`'s behavior or output. Always review the changelog for `inline-source` when `inline-source-cli` receives dependency updates.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"Ensure the `--root` argument points to the correct base directory for resolving relative paths of your inlined resources (e.g., CSS, JS, images). It should be the directory where the source HTML and its dependencies reside.","message":"Incorrect `root` path configuration is a common source of errors, leading to resources not being found or inlined correctly.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Check the `stderr` output from the CLI for more specific error messages, often related to file paths, invalid options, or issues with the input HTML structure.","cause":"A generic error indicating the CLI process encountered an unhandled error or failed validation.","error":"Error: Command failed with exit code 1"},{"fix":"Verify that the input HTML file path is correct and that all referenced local assets exist relative to the `--root` directory or the HTML file's location.","cause":"The specified input HTML file or a linked resource (CSS, JS, image) could not be found at the given path.","error":"Error: ENOENT: no such file or directory, stat 'path/to/your/file.html'"},{"fix":"Consult the `inline-source --help` output or the package documentation for available command-line options and their correct syntax.","cause":"Attempting to use a CLI option that does not exist or is deprecated in the current `inline-source-cli` version.","error":"Error: Unknown option '--some-new-option'"}],"ecosystem":"npm","meta_description":null}