File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,10 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
1010### Added
1111
12- - Interactive option. Use the flag ` --interactive ` to use this mode.
12+ - Interactive option. Use the flag ` --interactive ` to use this mode
1313- Comments :)
1414- Cleanup on global error
1515- Option for Author Name
16+ - Validation of application name according to NPM conventions
1617
1718### Changed
1819
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ Want support for an additional language? Feel free to open a [new issue](https:/
6868- [ ora] ( https://github.com/sindresorhus/ora ) - Elegant terminal spinner.
6969- [ pickitt] ( https://pickitt.netlify.com/ ) - When you need a computer to just pick it, reach for Pickitt!
7070- [ TypeScript] ( https://www.typescriptlang.org/ ) - A typed superset of JavaScript that compiles to plain JavaScript.
71+ - [ validate-npm-package-name] ( https://github.com/npm/validate-npm-package-name ) - Is the given string an acceptable npm package name?
7172
7273## ✍️ Authors <a name = " authors " ></a >
7374
Original file line number Diff line number Diff line change 3838 "@types/fs-extra" : " ^9.0.1" ,
3939 "@types/inquirer" : " ^6.5.0" ,
4040 "@types/node" : " ^14.0.5" ,
41+ "@types/validate-npm-package-name" : " ^3.0.0" ,
4142 "@types/yargs" : " ^15.0.5" ,
4243 "copyfiles" : " ^2.2.0" ,
4344 "typescript" : " ^3.9.3"
5253 "fs-extra" : " ^9.0.0" ,
5354 "inquirer" : " ^7.1.0" ,
5455 "ora" : " ^4.0.4" ,
55- "pickitt" : " ^3.2.0"
56+ "pickitt" : " ^3.2.0" ,
57+ "validate-npm-package-name" : " ^3.0.0"
5658 }
5759}
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ import {
2222 replaceTemplateValues ,
2323} from "./init" ;
2424import { handleIncorrectApplicationName } from "./program" ;
25- import { cleanupError } from "./util" ;
25+ import { cleanupError , validateApplicationName } from "./util" ;
2626
2727/**
2828 * Main CLI Program
@@ -70,12 +70,9 @@ const main = async (): Promise<void> => {
7070 } )
7171 . parse ( process . argv ) ;
7272
73- // TODO - Catch names like "my.app.name" or "my app name"
74-
7573 // * Application Name must exist, and not consist of illegal characters
76- if ( applicationName === "." || ! applicationName ) {
77- return handleIncorrectApplicationName ( program ) ;
78- }
74+ validateApplicationName ( applicationName ) ;
75+ if ( ! applicationName ) return ;
7976
8077 if ( program . interactive ) {
8178 // * Interactive walk-thru
Original file line number Diff line number Diff line change 1+ import chalk from "chalk" ;
12import { spawn } from "child_process" ;
23import fs from "fs-extra" ;
34import path from "path" ;
5+ import validateProjectName from "validate-npm-package-name" ;
46
57/**
68 * Executes a command in a spawned process.
@@ -74,3 +76,29 @@ export const valueReplacer = (
7476 return ;
7577 } ) ;
7678} ;
79+
80+ /**
81+ * Validates the application name according to NPM naming conventions.
82+ * @param applicationName Name of application.
83+ */
84+ export const validateApplicationName = ( applicationName : any ) => {
85+ const validation = validateProjectName ( applicationName ) ;
86+ if ( ! validation . validForNewPackages ) {
87+ console . error (
88+ `Cannot create an application named ${ chalk . red (
89+ `"${ applicationName } "`
90+ ) } because of npm naming restrictions:`
91+ ) ;
92+ console . log ( "" ) ;
93+
94+ [ ...( validation . errors || [ ] ) , ...( validation . warnings || [ ] ) ] . forEach (
95+ ( error ) => {
96+ console . error ( chalk . red ( ` * ${ error } ` ) ) ;
97+ }
98+ ) ;
99+
100+ console . log ( "" ) ;
101+ console . error ( "Please choose a different application name." ) ;
102+ process . exit ( 1 ) ;
103+ }
104+ } ;
You can’t perform that action at this time.
0 commit comments