-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
28 lines (26 loc) · 774 Bytes
/
Copy pathutils.js
File metadata and controls
28 lines (26 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const chalk = require('chalk')
const validateProjectName = require('validate-npm-package-name')
function checkAppNameCanBeUsed(appName) {
const validationResult = validateProjectName(appName);
if(!validationResult.validForNewPackages) {
console.error(
`Could not create a project called ${chalk.red(
`"${appName}"`
)} because of npm naming restrictions:`
);
printValidationResults(validationResult.errors);
printValidationResults(validationResult.warnings);
process.exit(1);
}
}
function printValidationResults(results) {
if(typeof results !== 'undefined') {
results.forEach(error => {
console.error(chalk.red(` * ${error}`));
});
}
}
module.exports = {
checkAppNameCanBeUsed,
printValidationResults
}