@@ -44,54 +44,21 @@ cli.parse({
44
44
abort : [ 'a' , 'Abort on first failure' ]
45
45
} ) ;
46
46
47
- // cli.pad = function(str, pad, chr, dir) {
48
- // if (!pad) pad = 20;
49
- // if (!chr) chr = ' ';
50
- // if (!dir) dir = 'left';
51
-
52
- // if ((str + '').length >= pad) {
53
- // return str;
54
- // }
55
-
56
- // if (dir === 'right') {
57
- // return String(str + Array(pad).join(chr)).slice(0, pad);
58
- // }
59
-
60
- // return String(Array(pad).join(chr) + str).slice(-pad);
61
- // };
62
-
63
- // var width = 120;
64
-
65
47
cli . buildnpm = function ( args , options ) {
66
48
var self = this ;
67
49
var globpath = __root + '/functions/' + options . category + '/' + options . name + '.js' ;
50
+ fs . writeFileSync ( __root + '/build/npm.js' , '// This file is generated by `make build`. \n' ) ;
51
+ fs . appendFileSync ( __root + '/build/npm.js' , '// Do NOT edit by hand. \n' ) ;
52
+ fs . appendFileSync ( __root + '/build/npm.js' , '// \n' ) ;
53
+ fs . appendFileSync ( __root + '/build/npm.js' , '// Make function changes in ./functions and \n' ) ;
54
+ fs . appendFileSync ( __root + '/build/npm.js' , '// generator changes in ./lib/phpjsutil.js \n' ) ;
68
55
self . glob ( globpath , function ( err , params ) {
69
- console . log ( params . signature ) ;
70
-
71
- var buf = '' ;
72
- buf += 'exports.decbin = function (number) {\n' ;
73
- buf += ' // Returns a string containing a binary representation of the number \n' ;
74
- buf += ' // \n' ;
75
- buf += ' // version: 1008.1718\n' ;
76
- buf += ' // discuss at: http://phpjs.org/functions/decbin\n' ;
77
- buf += ' // + original by: Enrique Gonzalez\n' ;
78
- buf += ' // + bugfixed by: Onno Marsman\n' ;
79
- buf += ' // + improved by: http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript\n' ;
80
- buf += ' // + input by: pilus\n' ;
81
- buf += ' // + input by: nord_ua\n' ;
82
- buf += ' // * example 1: \php.decbin(12);\n' ;
83
- buf += ' // * returns 1: \'1100\'\n' ;
84
- buf += ' // * example 2: \php.decbin(26);\n' ;
85
- buf += ' // * returns 2: \'11010\'\n' ;
86
- buf += ' // * example 3: \php.decbin(\'26\');\n' ;
87
- buf += ' // * returns 3: \'11010\'\n' ;
88
- buf += ' if (number < 0) {\n' ;
89
- buf += ' number = 0xFFFFFFFF + number + 1;\n' ;
90
- buf += ' }\n' ;
91
- buf += ' return parseInt(number, 10).toString(2);\n' ;
56
+ var buf = '\n' ;
57
+ buf += 'exports.' + params . func_name + ' = function (' + params . func_arguments . join ( ', ' ) + ') {\n' ;
58
+ buf += ' ' + params . body . split ( '\n' ) . join ( '\n ' ) . replace ( / ^ $ / g, '' ) + '\n' ;
92
59
buf += '};\n' ;
93
-
94
- fs . writeFileSync ( __root + '/build/npm.js' , buf ) ;
60
+ console . log ( buf ) ;
61
+ fs . appendFileSync ( __root + '/build/npm.js' , buf ) ;
95
62
} ) ;
96
63
} ;
97
64
@@ -137,18 +104,18 @@ cli.test = function(args, options) {
137
104
return cli . fatal ( err ) ;
138
105
}
139
106
140
- if ( params [ ' headKeys' ] [ ' test' ] && params [ ' headKeys' ] [ ' test' ] [ 0 ] === 'skip' ) {
107
+ if ( params . headKeys . test && params . headKeys . test [ 0 ] === 'skip' ) {
141
108
self . skip_cnt ++ ;
142
- return cli . info ( '--> ' + params [ ' name' ] + ' skipped as instructed. ' ) ;
109
+ return cli . info ( '--> ' + params . name + ' skipped as instructed. ' ) ;
143
110
}
144
111
145
112
PhpjsUtil . test ( params , function ( err , test , params ) {
146
113
if ( ! err ) {
147
114
self . pass_cnt ++ ;
148
- cli . debug ( '--> ' + params [ ' name' ] + '#' + ( + test [ ' number' ] + 1 ) + ' passed. ' ) ;
115
+ cli . debug ( '--> ' + params . name + '#' + ( + test . number + 1 ) + ' passed. ' ) ;
149
116
} else {
150
117
self . fail_cnt ++ ;
151
- cli . error ( '--> ' + params [ ' name' ] + '#' + ( + test [ ' number' ] + 1 ) + ' failed. ' ) ;
118
+ cli . error ( '--> ' + params . name + '#' + ( + test . number + 1 ) + ' failed. ' ) ;
152
119
cli . error ( err ) ;
153
120
if ( options . abort ) {
154
121
cli . fatal ( 'Aborting on first failure as instructed. ' ) ;
@@ -160,6 +127,6 @@ cli.test = function(args, options) {
160
127
} ;
161
128
162
129
cli . main ( function ( args , options ) {
163
- cli [ options [ ' action' ] ] ( args , options ) ;
130
+ cli [ options . action ] ( args , options ) ;
164
131
} ) ;
165
132
0 commit comments