autofile-fill
Version:
auto fill file
68 lines (50 loc) • 1.85 kB
JavaScript
var fs = require('fs')
var arguments = process.argv.splice(2);
var curr_path = process.env.PWD
var file_name = arguments[0];
var file_type = arguments[1];
if (!file_type) {
file_type = 'cpp'
}
console.log(arguments[1])
var func = {};
func.cpp = function(){
var content_h = "";
content_h += '// \n// ' + file_name + '.h \n' + '// \n';
content_h += "#ifndef __" + (file_name).toUpperCase() + "__ \n";
content_h += "#define __" + (file_name).toUpperCase() + "__ \n";
content_h += "\n";
content_h += '#include \"cocos2d.h\" \n'
content_h += 'USING_NS_CC; \n \n'
content_h += 'class ' +file_name+ ' : public cocos2d::Node \n'
content_h += '{ \n'
content_h += 'public: \n'
// content_h += ' ' +file_name+ '(); \n'
// content_h += ' ~' +file_name+ '(); \n'
// content_h += ' static cocos2d::Scene* createScene(); \n'
content_h += ' virtual bool init(); \n'
content_h += ' CREATE_FUNC(' +file_name+ '); \n'
content_h += '}; \n'
content_h += "#endif \n";
var fd = fs.openSync(curr_path + '/' + file_name + '.h', 'w');
fs.writeSync(fd, content_h);
fs.closeSync(fd);
var content_cpp = "";
content_cpp += '// \n// ' + file_name + '.cpp \n' + '// \n';
content_cpp += "#include \"" + file_name + ".h\" \n"
content_cpp += '#include "ui/CocosGUI.h" \n\n'
content_cpp += 'bool ' +file_name+ '::init() \n'
content_cpp += '{ \n'
content_cpp += ' if (!Node::init()) \n'
content_cpp += ' { \n'
content_cpp += ' return false; \n'
content_cpp += ' } \n'
content_cpp += ' return true \n'
content_cpp += '} \n'
fd = fs.openSync(curr_path + '/' + file_name + '.cpp', 'w');
fs.writeSync(fd, content_cpp);
fs.closeSync(fd);
console.log("success")
}
func.cpp()