electron-forge
Version:
A complete tool for building modern Electron applications
146 lines (126 loc) • 7.19 kB
HTML
<html>
<head>
<meta charset="utf-8">
<base data-ice="baseUrl" href="../../">
<title data-ice="title">api/lint.js | API Document</title>
<link type="text/css" rel="stylesheet" href="css/style.css">
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
<script src="script/prettify/prettify.js"></script>
<script src="script/manual.js"></script>
</head>
<body class="layout-container" data-ice="rootContainer">
<header>
<a href="./">Home</a>
<a href="identifiers.html">Reference</a>
<a href="source.html">Source</a>
<a data-ice="repoURL" href="https://github.com/electron-userland/electron-forge" class="repo-url-github">Repository</a>
<div class="search-box">
<span>
<img src="./image/search.png">
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
</span>
<ul class="search-result"></ul>
</div>
</header>
<nav class="navigation" data-ice="nav"><div>
<ul>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-import">import</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-init">init</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-install">install</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-lint">lint</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-make">make</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-package">package</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-publish">publish</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-start">start</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ImportOptions">ImportOptions</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-InitOptions">InitOptions</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-InstallOptions">InstallOptions</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-LintOptions">LintOptions</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-MakeOptions">MakeOptions</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-PackageOptions">PackageOptions</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-PublishOptions">PublishOptions</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-StartOptions">StartOptions</a></span></span></li>
</ul>
</div>
</nav>
<div class="content" data-ice="content"><h1 data-ice="title">api/lint.js</h1>
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import 'colors';
import debug from 'debug';
import { spawn as yarnOrNPMSpawn } from 'yarn-or-npm';
import asyncOra from '../util/ora-handler';
import resolveDir from '../util/resolve-dir';
const d = debug('electron-forge:lint');
/**
* @typedef {Object} LintOptions
* @property {string} [dir=process.cwd()] The path to the module to import
* @property {boolean} [interactive=false] Whether to use sensible defaults or prompt the user visually
*/
/**
* Lint a local Electron application.
*
* The promise will be rejected with the stdout+stderr of the linting process if linting fails or
* will be resolved if it succeeds.
*
* @param {LintOptions} providedOptions - Options for the Lint method
* @return {Promise<null, string>} Will resolve when the lint process is complete
*/
export default async (providedOptions = {}) => {
// eslint-disable-next-line prefer-const, no-unused-vars
let { dir, interactive } = Object.assign({
dir: process.cwd(),
interactive: false,
}, providedOptions);
asyncOra.interactive = interactive;
let success = true;
let result = null;
await asyncOra('Linting Application', async (lintSpinner) => {
dir = await resolveDir(dir);
if (!dir) {
// eslint-disable-next-line no-throw-literal
throw 'Failed to locate lintable Electron application';
}
d('executing "run lint -- --color" in dir:', dir);
const child = yarnOrNPMSpawn(['run', 'lint', '--', '--color'], {
stdio: process.platform === 'win32' ? 'inherit' : 'pipe',
cwd: dir,
});
const output = [];
if (process.platform !== 'win32') {
child.stdout.on('data', data => output.push(data.toString()));
child.stderr.on('data', data => output.push(data.toString().red));
}
await new Promise((resolve) => {
child.on('exit', (code) => {
if (code !== 0) {
success = false;
lintSpinner.fail();
if (interactive) {
output.forEach(data => process.stdout.write(data));
process.exit(code);
} else {
result = output.join('');
}
}
resolve();
});
});
});
if (!success) {
throw result;
}
};
</code></pre>
</div>
<footer class="footer">
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(0.5.2)</span><img src="./image/esdoc-logo-mini-black.png"></a>
</footer>
<script src="script/search_index.js"></script>
<script src="script/search.js"></script>
<script src="script/pretty-print.js"></script>
<script src="script/inherited-summary.js"></script>
<script src="script/test-summary.js"></script>
<script src="script/inner-link.js"></script>
<script src="script/patch-for-local.js"></script>
</body>
</html>