File tree Expand file tree Collapse file tree 6 files changed +61
-9
lines changed Expand file tree Collapse file tree 6 files changed +61
-9
lines changed Original file line number Diff line number Diff line change 22var chalk = require ( 'chalk' ) ;
33function filePath ( filePath ) {
44 if ( ! filePath ) {
5- console . log ( chalk . red ( "\n Pass in a path to your .md file\n For example: coderoad build ./src/tutorial.md\n " ) ) ;
5+ console . log ( chalk . red ( "\n Pass in a path to your .md file\n > coderoad build \" ./src/tutorial.md\" \n " ) ) ;
66 process . exit ( 1 ) ;
77 }
88}
Original file line number Diff line number Diff line change 22var chalk = require ( 'chalk' ) ;
33var validateNpm = require ( "validate-npm-package-name" ) ;
44var process = require ( 'process' ) ;
5+ var _ = require ( 'lodash' ) ;
56function validatePackageName ( name ) {
67 var validated = validateNpm ( name ) ;
78 if ( ! validated . validForNewPackages || ! validated . validForOldPackages ) {
@@ -16,7 +17,7 @@ function validatePackageName(name) {
1617 } ) ;
1718 }
1819 if ( ! validated . errors && ! validated . warnings ) {
19- console . log ( chalk . red ( "\n Invalid package name.\n Try using kebab-case (for example: \"my-package- name\") \n " ) ) ;
20+ console . log ( chalk . red ( "\n Invalid package name. Try using kebab-case. \n > coderoad create " + _ . kebabCase ( name ) + " \n ") ) ;
2021 }
2122 process . exit ( 1 ) ;
2223 }
Original file line number Diff line number Diff line change 11"use strict" ;
22var chalk = require ( 'chalk' ) ;
3+ var validate_1 = require ( './validate' ) ;
34function publish ( version ) {
5+ validate_1 . default ( version ) ;
46 console . log ( "Publishing package version \"" + version + "\"..." ) ;
57 console . log ( chalk . red ( 'Publish feature not implemented yet.' ) ) ;
68}
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+ var fs = require ( 'fs' ) ;
3+ var process = require ( 'process' ) ;
4+ var chalk = require ( 'chalk' ) ;
5+ function fileExists ( path ) {
6+ try {
7+ fs . accessSync ( path , fs . R_OK | fs . W_OK ) ;
8+ }
9+ catch ( e ) {
10+ if ( e ) {
11+ console . log ( e ) ;
12+ return false ;
13+ }
14+ }
15+ return true ;
16+ }
17+ function versionIsGreaterThanCurrent ( version ) {
18+ if ( ! fileExists ( 'package.json' ) ) {
19+ console . log ( chalk . yellow ( "\n No available package.json file.Create one.\n > npm init\n " ) ) ;
20+ process . exit ( 1 ) ;
21+ }
22+ var currentVersion = fs . readFileSync ( 'package.json' , 'utf8' ) . version ;
23+ if ( parseInt ( version ) <= parseInt ( currentVersion ) ) {
24+ var incrementedVersion = parseInt ( currentVersion ) + 0.0 ;
25+ .1 ;
26+ console . log ( chalk . yellow ( "\n Published version is not larger than current version.\n Current: \"" + currentVersion + "\"\n > coderoad publish \"" + incrementedVersion + "\"\n " ) ) ;
27+ process . exit ( 1 ) ;
28+ }
29+ }
30+ var semverRegex = / \b ^ (?: 0 | [ 1 - 9 ] [ 0 - 9 ] * ) \. (?: 0 | [ 1 - 9 ] [ 0 - 9 ] * ) \. (?: 0 | [ 1 - 9 ] [ 0 - 9 ] * ) $ \b / i;
31+ function isValidVersion ( version ) {
32+ if ( ! version . match ( semverRegex ) ) {
33+ console . log ( chalk . yellow ( "\n Not a valid semver version\n > coderoad publish \"0.1.0\"\n " ) ) ;
34+ process . exit ( 1 ) ;
35+ }
36+ }
37+ function validateVersion ( version ) {
38+ isValidVersion ( version ) ;
39+ versionIsGreaterThanCurrent ( version ) ;
40+ }
41+ Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
42+ exports . default = validateVersion ;
Original file line number Diff line number Diff line change 11"use strict" ;
2- var process = require ( 'process' ) ;
32var chalk = require ( 'chalk' ) ;
3+ var validate_1 = require ( './validate' ) ;
44function search ( query ) {
5- if ( query === 'undefined' ) {
6- console . log ( chalk . yellow ( "\n Please provide a search query\n Example: coderoad search react\n " ) ) ;
7- process . exit ( 1 ) ;
8- }
9- console . log ( "Searching for \"" + query + "\"..." ) ;
10- console . log ( chalk . red ( 'Search feature not implemented yet.' ) ) ;
5+ validate_1 . validateQuery ( query ) ;
6+ console . log ( "Searching for \"coderoad-" + query + "\"..." ) ;
7+ console . log ( chalk . red ( 'Search feature not fully implemented yet.' ) ) ;
118}
129Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
1310exports . default = search ;
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+ var process = require ( 'process' ) ;
3+ var chalk = require ( 'chalk' ) ;
4+ function validateQuery ( query ) {
5+ if ( query === 'undefined' ) {
6+ console . log ( chalk . yellow ( "\n Please provide a search query\n > coderoad search \"query\"\n " ) ) ;
7+ process . exit ( 1 ) ;
8+ }
9+ }
10+ exports . validateQuery = validateQuery ;
You can’t perform that action at this time.
0 commit comments