Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return false;
}
// This is for the `_` property. If there are sites, we don't show help neither
if (Array.isArray(value) && value.length > 0) {
return false;
}
return result && true;
}, true);
if (!showHelp) {
return Promise.resolve(false);
}
logger.log(options.generateHelp());
return Promise.resolve(true);
};
await removeLanguageFile();
// We save the result with the friendly target name
const name = target.replace(/:\/\//g, '-')
.replace(/:/g, '-')
.replace(/\./g, '-')
.replace(/\//g, '-')
.replace(/[?=]/g, '-query-')
.replace(/-$/, '');
const destDir = options.output || path.join(cwd(), 'hint-report');
const destination = path.join(destDir, `${name}.html`);
await fs.outputFile(destination, html);
logger.log(getMessageFormatter('youCanView', language, destination));
}
return result;
} catch (err) {
logger.error(err);
throw err;
}
}
}
const isConfigured = (hintOptions: any) => {
const cloudinaryUrl = process.env.CLOUDINARY_URL; // eslint-disable-line no-process-env
const { apiKey, apiSecret, cloudName, threshold } = hintOptions;
if (threshold) {
sizeThreshold = threshold;
}
if (cloudinaryUrl) {
return true;
}
if (!apiKey || !apiSecret || !cloudName) {
logger.error(getMessage('noConfigFound', context.language));
return false;
}
cloudinary.v2.config({
api_key: apiKey,
api_secret: apiSecret,
cloud_name: cloudName
});
return true;
};
/* eslint-enable camelcase */
logger.log(`1. Run 'yarn' to install the dependencies.
2. Go to the folder 'packages/hint-${hintPackage.normalizedName}'.
3. Run 'yarn build' to build the project.
4. Go to the folder 'packages/hint'.
5. Add your hint to '.hintrc'.
6. Run 'yarn hint https://YourUrl' to analyze your site.`);
} else {
logger.log(`1. Go to the folder 'hint-${hintPackage.normalizedName}'.
2. Run 'npm run init' to install all the dependencies and build the project.
3. Run 'npm run hint -- https://YourUrl' to analyze you site.`);
}
return true;
} catch (e) {
/* istanbul ignore next */{ // eslint-disable-line no-lone-blocks
logger.error('Error trying to create new hint');
logger.error(e);
return false;
}
}
};
return total;
}
/* istanbul ignore if */
if (value[0] === '/') {
total.push(value.substr(1));
} else {
total.push(value);
}
return total;
}, []);
return result;
} catch (err) {
logger.error(getMessage('errorReading', this.engine.language));
return [];
}
}
try {
// We save the file with the friendly target name
const name = target.replace(/:\/\//g, '-')
.replace(/:/g, '-')
.replace(/\./g, '-')
.replace(/\//g, '-')
.replace(/-$/, '');
const fileName = options.output || path.resolve(cwd(), `${name}.xlsx`);
await workbook.xlsx.writeFile(fileName);
} catch (e) {
/* istanbul ignore next */
{ // eslint-disable-line
logger.error(getMessage('errorSaving', language));
if (e.message.includes('EBUSY')) {
logger.error(getMessage('maybeIsOpened', language));
}
}
}
}
}
return 1;
}
let handled = false;
notifyIfNeeded();
while (cliActions.length > 0 && !handled) {
const action = cliActions.shift()!; // Can assume not-undefined as previous line already checks the length.
/* istanbul ignore next */
try {
handled = await action(currentOptions);
} catch (e) {
logger.error(e);
return 1;
}
}
return handled ? 0 : 1;
};
export const execute = async (args: string | string[] | Object): Promise => {
let currentOptions: CLIOptions;
try {
currentOptions = options.parse(args);
} catch (e) {
logger.error(e.message);
return 1;
}
let handled = false;
notifyIfNeeded();
while (cliActions.length > 0 && !handled) {
const action = cliActions.shift()!; // Can assume not-undefined as previous line already checks the length.
/* istanbul ignore next */
try {
handled = await action(currentOptions);
} catch (e) {
logger.error(e);
return;
}
// Update finalHref to point to the final URL.
this.finalHref = this._targetNetworkData.response.url;
debug(`HTML for ${this.finalHref} downloaded`);
const fetchEnd: FetchEnd = {
element: null,
request: this._targetNetworkData.request,
resource: this.finalHref,
response: this._targetNetworkData.response
};
const { charset, mediaType } = getContentTypeData(fetchEnd.element, fetchEnd.resource, fetchEnd.response.headers, fetchEnd.response.body.rawContent);
fetchEnd.response.mediaType = mediaType!;
fetchEnd.response.charset = charset!;
// Event is also emitted when status code in response is not 200.
await this.server.emitAsync(`fetch::end::${getType(mediaType!)}` as 'fetch::end::*', fetchEnd);
/*
* If the target is not an HTML we don't need to
* traverse it.
*/
/* istanbul ignore if */
if (!isHTMLDocument(this.finalHref, this.headers)) {
await this.server.emitAsync('scan::end', { resource: this.finalHref });
resolve();
const [content, rawContent] = await Promise.all([
response.text(),
response.buffer()
])
.catch((e) => {
return ['', Buffer.alloc(0)];
});
const body = {
content,
rawContent: rawContent /* istanbul ignore next */ || Buffer.alloc(0),
rawResponse: getRawResponse(response, fetchContent)
};
const responseHeaders = normalizeHeaders(response.headers() as any) as HttpHeaders;
const { charset, mediaType } = getContentTypeData(element, originalUrl, responseHeaders, body.rawContent);
const networkResponse = {
body,
charset: charset!,
headers: responseHeaders,
hops,
mediaType: mediaType!,
statusCode: response.status(),
url: response.url()
};
const data = {
element,
request: networkRequest,
resource: resourceUrl,
response: networkResponse