Skip to content

Commit 8a93f35

Browse files
committed
Build npm
1 parent eed2648 commit 8a93f35

File tree

3 files changed

+12721
-84
lines changed

3 files changed

+12721
-84
lines changed

bin/phpjs.js

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -44,54 +44,21 @@ cli.parse({
4444
abort : ['a', 'Abort on first failure']
4545
});
4646

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-
6547
cli.buildnpm = function(args, options) {
6648
var self = this;
6749
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');
6855
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';
9259
buf += '};\n';
93-
94-
fs.writeFileSync(__root + '/build/npm.js', buf);
60+
console.log(buf);
61+
fs.appendFileSync(__root + '/build/npm.js', buf);
9562
});
9663
};
9764

@@ -137,18 +104,18 @@ cli.test = function(args, options) {
137104
return cli.fatal(err);
138105
}
139106

140-
if (params['headKeys']['test'] && params['headKeys']['test'][0] === 'skip') {
107+
if (params.headKeys.test && params.headKeys.test[0] === 'skip') {
141108
self.skip_cnt++;
142-
return cli.info('--> ' + params['name'] + ' skipped as instructed. ');
109+
return cli.info('--> ' + params.name + ' skipped as instructed. ');
143110
}
144111

145112
PhpjsUtil.test(params, function(err, test, params) {
146113
if (!err) {
147114
self.pass_cnt++;
148-
cli.debug('--> ' + params['name'] + '#' + (+test['number'] + 1) + ' passed. ');
115+
cli.debug('--> ' + params.name + '#' + (+test.number + 1) + ' passed. ');
149116
} else {
150117
self.fail_cnt++;
151-
cli.error('--> ' + params['name'] + '#' + (+test['number'] + 1) + ' failed. ');
118+
cli.error('--> ' + params.name + '#' + (+test.number + 1) + ' failed. ');
152119
cli.error(err);
153120
if (options.abort) {
154121
cli.fatal('Aborting on first failure as instructed. ');
@@ -160,6 +127,6 @@ cli.test = function(args, options) {
160127
};
161128

162129
cli.main(function(args, options) {
163-
cli[options['action']](args, options);
130+
cli[options.action](args, options);
164131
});
165132

0 commit comments

Comments
 (0)