Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getConnections = (): NetworkConfig[] => {
const configContent = readFile(`${__dirname}/connections.ini`);
const configsText = configContent
.replace(/#.*?\n/g, '') // remove comments
.replace(/\r\n/g, '\n') // remove \r in case the file has a Windows EOL
.split(`\n\n`);
const configs = configsText.map(parseConnection);
return configs;
};
return (window: DOMWindow) => {
const mutationObserverPolyfill = readFile(require.resolve('mutationobserver-shim'));
const customElementsPolyfill = readFile(path.join(__dirname, 'polyfills', 'custom-elements.min.js'));
const mutationScript: vm.Script = new vm.Script(mutationObserverPolyfill);
const customElementsScript: vm.Script = new vm.Script(customElementsPolyfill);
mutationScript.runInContext(jsdomutils.implForWrapper(window.document)._global);
customElementsScript.runInContext(jsdomutils.implForWrapper(window.document)._global);
window.document.domain = new URL(finalHref).host;
/* istanbul ignore next */
window.matchMedia = () => {
return { addListener() { } } as any;
};
Object.defineProperty(window.HTMLHtmlElement.prototype, 'clientWidth', { value: 1024 });
export const isOfficial = async (): Promise => {
try {
const pkg = JSON.parse(await readFile(join(findPackageRoot(process.cwd()), 'package.json')));
return pkg.name === '@hint/monorepo';
} catch (e) {
// No `package.json` was found, so it's not official
return false;
}
};
const ids: string[] = resourcesFiles.reduce((list: string[], resourceFile: string) => {
const resource = requirePackage(path.dirname(resourceFile));
const packageName = JSON.parse(readFile(resourceFile)).name;
const resourceName = packageName.substr(packageName.lastIndexOf('/') + 1).replace(`${type}-`, '');
/* istanbul ignore else */
if (!hasMultipleResources(resource, type)) {
list.push(resourceName);
} else {
const hints = Object.entries(resource);
if (hints.length === 1 && resource[resourceName]) {
list.push(resourceName);
} else {
for (const [key] of hints) {
list.push(`${resourceName}/${key}`);
}
}
}
return (window: DOMWindow) => {
const mutationObserverPolyfill = readFile(require.resolve('mutationobserver-shim'));
const customElementsPolyfill = readFile(path.join(__dirname, 'polyfills', 'custom-elements.min.js'));
const mutationScript: vm.Script = new vm.Script(mutationObserverPolyfill);
const customElementsScript: vm.Script = new vm.Script(customElementsPolyfill);
mutationScript.runInContext(jsdomutils.implForWrapper(window.document)._global);
customElementsScript.runInContext(jsdomutils.implForWrapper(window.document)._global);
window.document.domain = new URL(finalHref).host;
/* istanbul ignore next */
window.matchMedia = () => {
return { addListener() { } } as any;
};
Object.defineProperty(window.HTMLHtmlElement.prototype, 'clientWidth', { value: 1024 });
Object.defineProperty(window.HTMLHtmlElement.prototype, 'clientHeight', { value: 768 });
this.destination = join(cwd(), `hint-${this.normalizedName}`);
}
}
}
/*
* ------------------------------------------------------------------------------
* Constants and Private functions.
* ------------------------------------------------------------------------------
*/
const mkdirpAsync = promisify(mkdirp) as (dir: string) => Promise;
/** Name of the package to use as a template. */
const TEMPLATE_PATH = './templates';
const SHARED_TEMPLATE_PATH = './shared-templates';
const partialEventCode = readFile(join(__dirname, 'templates', 'partial-event-code.hbs'));
Handlebars.registerPartial('event-code', partialEventCode);
Handlebars.registerHelper('toCamelCase', toCamelCase);
/** List hint categories. */
const categories: any[] = [];
for (const [, value] of Object.entries(Category)) {
if (value !== 'other') {
categories.push({ name: value });
}
}
/** List of scopes */
const scopes: any[] = [];