Skip to content

Commit 8087651

Browse files
committed
ref Nodeclipse#91 Nodeclispe CLI 0.4.0;
1 parent bce1e6a commit 8087651

File tree

5 files changed

+107
-28
lines changed

5 files changed

+107
-28
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/.project_
1+
npm-debug.log

org.nodeclipse.ui/templates/README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22

3-
# Nodeclipse CLI #91
3+
# Nodeclipse CLI
4+
5+
#91
46

57
## Node.js Development with Eclipse or Enide Studio
68

@@ -28,6 +30,7 @@ Check <http://www.nodeclipse.org/> on how to get Nodeclipse or Enide Studio
2830
Templates are just folders in this project sources:
2931
hello-world The famous hello world HTTP server in 6 lines
3032
hello-coffee The same server written in CoffeeScript
33+
hello-typescript The same server written in TypeScript
3134

3235
## Other commands (TODO)
3336

@@ -44,7 +47,9 @@ Examples:
4447

4548
nodeclipse --create project2
4649

47-
nodeclipse --create project2 --use hello-coffee
50+
nodeclipse --create project3 --use hello-coffee
51+
52+
nodeclipse -c project4 -u hello-coffee
4853

4954
## Eclipse Workspace and Project
5055

org.nodeclipse.ui/templates/copier.js

+89-23
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,95 @@
11

22
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')
611
.argv;
712
require('shelljs/global');
813
var fs= require('fs');
914
var path= require('path');
1015

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+
1126
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();
1733
});
1834

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);
2939

3040
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);
3281
return;
3382
}
3483
if (version){
3584
console.log("Nodeclipse CLI 0.3.0"); // BUG #71
3685
return;
3786
}
87+
if (projectFileExists) {
88+
console.log(".project file already exists!");
89+
return;
90+
}
91+
92+
//copyFromTemplates
3893
if (create){
3994
if (create.toString().length===0){
4095
console.error("Folder/project name is required for creation!");
@@ -43,13 +98,22 @@ var copyFromTemplates = function () {
4398
}
4499
mkdir(create);
45100
cd(create);
101+
if (verbose) console.log("Created project/folder: " + create);
46102
}
103+
47104
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+
49113
if (use){
50114
//cp(__dirname+use+'/*','.');
51115
var fromfolder = path.join(templatesfolder, use, '/*')
52-
console.log( fromfolder );
116+
if (verbose) console.log("Copying from "+ fromfolder );
53117
cp( fromfolder, '.' )
54118
}
55119

@@ -67,10 +131,12 @@ var copyFromTemplates = function () {
67131
fs.writeFile(destfile, str, function(err) {
68132
if (err)
69133
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);
71137
});
72138

73-
console.log(str); // ''.toString()
139+
if (debug) console.log(str); // ''.toString()
74140

75141
inviteToSiteAsTheLastLine();
76142
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare function require(name:string);
2+
var http = require('http');
3+
http.createServer(function handler(req, res) {
4+
res.writeHead(200, {'Content-Type': 'text/plain'});
5+
res.end('Hello TypeScript\n');
6+
}).listen(1337, '127.0.0.1');
7+
console.log('Server running at http://127.0.0.1:1337/');

org.nodeclipse.ui/templates/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodeclipse",
3-
"version": "0.3.0.DEV",
3+
"version": "0.4.0",
44
"description": "nodeclipse CLI - prepare Node.js project to be imported into Eclipse (Nodeclipse)",
55
"main": "copier.js",
66
"scripts": {
@@ -20,7 +20,8 @@
2020
"nodeclipse",
2121
"import",
2222
"node.js",
23-
"debug"
23+
"debug",
24+
"template"
2425
],
2526
"author": "Paul Verest",
2627
"license": "MIT",

0 commit comments

Comments
 (0)