1
1
2
2
var argv = require ( 'optimist' )
3
- . boolean ( 'h' ) . boolean ( 'help' )
4
- . boolean ( 'v' ) . boolean ( 'version' )
5
- . boolean ( 'V' ) . boolean ( 'verbose' )
3
+ . alias ( 'c' , 'create' ) . describe ( 'c' , 'create project folder and prepare it' )
4
+ . alias ( 'p' , 'prepare' ) . describe ( 'p' , 'prepare for import, i.e. add needed `.project` file (default action)' )
5
+ . string ( 'n' )
6
+ . alias ( 'n' , 'name' ) . describe ( 'h' , 'project name (default is folder name)' )
7
+ . boolean ( [ 'h' , 'v' , 'V' ] )
8
+ . alias ( 'h' , 'help' ) . describe ( 'h' , 'lists usage arguments' )
9
+ . alias ( 'v' , 'version' ) . describe ( 'v' , 'print nodeclipse CLI version' )
10
+ . alias ( 'V' , 'verbose' ) . describe ( 'V' , 'be verbose' )
6
11
. argv ;
7
12
require ( 'shelljs/global' ) ;
8
13
var fs = require ( 'fs' ) ;
9
14
var path = require ( 'path' ) ;
10
15
16
+ var help = argv . help || argv . h ;
17
+ var version = argv . version || argv . v ;
18
+ var create = argv . create || argv . c ;
19
+ var use = argv . use || argv . u || argv . template || argv . t ;
20
+ var name = argv . name || argv . n ; // could be create ||
21
+ var debug = true ;
22
+ var verbose = debug || argv . verbose || argv . V ;
23
+
24
+ var projectFileExists = false ;
25
+
11
26
fs . exists ( './.project' , function check ( exists ) {
12
- if ( exists ) {
13
- console . log ( ".project file already exists!" ) ;
14
- return ;
15
- }
16
- copyFromTemplates ( ) ;
27
+ projectFileExists = exists ;
28
+ // if (exists) {
29
+ // console.log(".project file already exists!");
30
+ // //return;
31
+ // }
32
+ processArguments ( ) ;
17
33
} ) ;
18
34
19
- var copyFromTemplates = function ( ) {
20
- console . log ( require . main . filename ) ; // = __filename
21
-
22
- console . log ( 'Passed parameters: name=%s, verbose=%s' , argv . name , argv . verbose ) ;
23
- var help = argv . help || argv . h ;
24
- var version = argv . version || argv . v ;
25
- var create = argv . create || argv . c ;
26
- var use = argv . use || argv . u || argv . template || argv . t ;
27
- var name = argv . name || argv . n ; // could be create ||
28
- var verbose = true || argv . verbose || argv . V ;
35
+ var processArguments = function ( ) {
36
+ //if (debug) console.log(require.main.filename); // = __filename
37
+ //if (debug) console.dir(argv);
38
+ //console.log('Passed parameters: name=%s, verbose=%s', argv.name, argv.verbose);
29
39
30
40
if ( help ) {
31
- console . log ( "Check README" ) ;
41
+ console . log ( "Check README" ) ;
42
+
43
+ // the following code snippet from optimist README.md has error below
44
+
45
+ // var s = fs.createReadStream(argv.file);
46
+ //
47
+ // var lines = 0;
48
+ // s.on('data', function (buf) {
49
+ // lines += buf.toString().match(/\n/g).length;
50
+ // });
51
+ // s.on('end', function () {
52
+ // console.log(lines);
53
+ // });
54
+
55
+ // fs.js:404
56
+ // binding.open(pathModule._makeLong(path),
57
+ // ^
58
+ // TypeError: path must be a string
59
+ // at Object.fs.open (fs.js:404:11)
60
+
61
+
62
+ var helpstr =
63
+ " Usage: nodeclipse [arguments] \n\
64
+ \n\
65
+ Arguments: \n\
66
+ -c, --create <name> create project folder and prepare it \n\
67
+ -u, --use <template> create project folder (using specified template folder) and prepare it \n\
68
+ -p, --prepare prepare for import, i.e. add needed `.project` file (default action)\n\
69
+ -n, --name [<name>] project name (default is folder name)\n\
70
+ -h, --help Check README\n\
71
+ -v, --version print nodeclipse CLI's version\n\
72
+ -V, --verbose be verbose\n\
73
+ \n\
74
+ Templates are just folders in this project sources:\n\
75
+ hello-world The famous hello world HTTP server in 6 lines\n\
76
+ hello-coffee The same server written in CoffeeScript\n\
77
+ hello-typescript The same server written in TypeScript\n\
78
+ " ;
79
+
80
+ console . log ( helpstr ) ;
32
81
return ;
33
82
}
34
83
if ( version ) {
35
84
console . log ( "Nodeclipse CLI 0.3.0" ) ; // BUG #71
36
85
return ;
37
86
}
87
+ if ( projectFileExists ) {
88
+ console . log ( ".project file already exists!" ) ;
89
+ return ;
90
+ }
91
+
92
+ //copyFromTemplates
38
93
if ( create ) {
39
94
if ( create . toString ( ) . length === 0 ) {
40
95
console . error ( "Folder/project name is required for creation!" ) ;
@@ -43,13 +98,22 @@ var copyFromTemplates = function () {
43
98
}
44
99
mkdir ( create ) ;
45
100
cd ( create ) ;
101
+ if ( verbose ) console . log ( "Created project/folder: " + create ) ;
46
102
}
103
+
47
104
var templatesfolder = __dirname ;
48
- if ( verbose ) console . log ( "Templates folder is: " + templatesfolder ) ;
105
+ if ( debug ) console . log ( "Templates folder is: " + templatesfolder ) ;
106
+
107
+ // common-templates //TODO not copying .files
108
+ var fromfolder = path . join ( templatesfolder , 'common-templates' , '/*' )
109
+ if ( verbose ) console . log ( "Copying from " + fromfolder ) ;
110
+ cp ( '-A' , fromfolder , '.' )
111
+
112
+
49
113
if ( use ) {
50
114
//cp(__dirname+use+'/*','.');
51
115
var fromfolder = path . join ( templatesfolder , use , '/*' )
52
- console . log ( fromfolder ) ;
116
+ if ( verbose ) console . log ( "Copying from " + fromfolder ) ;
53
117
cp ( fromfolder , '.' )
54
118
}
55
119
@@ -67,10 +131,12 @@ var copyFromTemplates = function () {
67
131
fs . writeFile ( destfile , str , function ( err ) {
68
132
if ( err )
69
133
throw err ;
70
- console . log ( 'The file "' + destfile + '" was created !' ) ;
134
+ if ( verbose ) console . log ( 'The file "' + destfile + '" was created !' ) ;
135
+ console . log ( 'In Eclipse/Enide select File -> Import... -> General / Existing Projects into Workspace' ) ;
136
+ console . log ( 'and enter current directory: ' + curfolder ) ;
71
137
} ) ;
72
138
73
- console . log ( str ) ; // ''.toString()
139
+ if ( debug ) console . log ( str ) ; // ''.toString()
74
140
75
141
inviteToSiteAsTheLastLine ( ) ;
76
142
}
0 commit comments