Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createSummary(sortedResources, target);
_.forEach(sortedResources, (resourceName) => {
processResource(resources[resourceName], resourceName);
});
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));
}
}
}
}
}
},
result,
scripts,
styles: await getStylesContent(stylesList),
utils
});
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 packageName = `${scope}${unscopedNameParts[0]}`;
const resourceName = isSource ?
name : unscopedNameParts[1] || packageName;
const key = isPackage || isSource ?
name :
`${type}-${name}`;
// When we check the version we ignore if there was a previous version loaded
if (resources.has(key) && !verifyVersion) {
return resources.get(key);
}
const configPathsToResources = generateConfigPathsToResources(configurations, packageName, type);
const currentProcessDir = cwd();
/*
* We can't use the key for the Official packages neither for the Third party ones because
* in case that we have a multi-hints packages, the key for the cache has to contain
* the key for the specific hint, but we need to load the package that contains the hint.
* i.e.
* if we want to load the hint `hint-typescript-config/is-valid` the key for the cache
* has to be `hint-typescript-config/is-valid`.
* But we need to load the package `hint-typescript-config`.
*/
let sources: string[];
if (isSource) {
sources = [path.resolve(currentProcessDir, name)]; // If the name is direct path to the source we should only check that.
} else if (isPackage) {
sources = [packageName].concat(configPathsToResources); // If the name is a full package name we should only check that, but look for it in config paths as well.
export const installPackages = async (packages: string[]): Promise => {
/** Whether or not the package should be installed as devDependencies. */
let isDev = false;
/** Current working directory. */
const currentWorkingDir = cwd();
/** Whether or not the process is running in windows */
const isWindows = process.platform === 'win32';
if (packages.length === 0) {
return Promise.resolve(true);
}
const hintLocalPath = path.join(currentWorkingDir, 'node_modules', 'hint', 'package.json');
// Check if hint is installed locally.
const global: boolean = !fs.existsSync(hintLocalPath); // eslint-disable-line no-sync
/** package manager to install the packages. */
const packageManagerChoice = (!global && await hasYarnLock(currentWorkingDir)) ? 'yarn' : 'npm';
if (!global) {
public static getUserConfig(filePath?: string): UserConfig | null {
const isDirectory = !isFile(filePath);
const configPath = isDirectory ? Configuration.getFilenameForDirectory(filePath || cwd()) : filePath;
if (!configPath) {
return null;
}
try {
const resolvedPath = path.resolve(isDirectory ? (filePath || cwd()) : cwd(), configPath);
return Configuration.loadConfigFile(resolvedPath);
} catch {
return null;
}
}
message: 'Do you want to use a predefined configuration or create your own based on your installed packages?',
name: 'configType',
type: 'list'
}];
const initialAnswer: inquirer.Answers = await inquirer.prompt(initialQuestion);
const result = initialAnswer.configType === 'predefined' ?
await extendConfig() :
await customConfig();
if (!result) {
return false;
}
const filePath: string = path.join(cwd(), '.hintrc');
await promisify(fs.writeFile)(filePath, JSON.stringify(result.config, null, 4), 'utf8');
if (Array.isArray(result.packages) && result.packages.length > 0) {
const isInstalled = getInstalledResources(ResourceType.configuration).includes(getConfigurationName(result.packages[0]));
if (isInstalled) {
return true;
}
await installPackages(result.packages);
}
trackEvent('new-hintrc', result.config);
await sendPendingData();
if (this.official) {
/**
* If we are creating an official package it should be under `/packages/`
* but it is very common to run it from the root of the project so we
* take into account that scenario and add the folder if needed.
*/
const root = cwd();
const packagesPath = root.endsWith('packages') ?
'' :
'packages';
this.destination = join(root, packagesPath, `hint-${this.normalizedName}`);
} else {
this.destination = join(cwd(), `hint-${this.normalizedName}`);
}
}
}