UNPKG

wp-cpt

Version:

Node Module to generate Wordpress Custom Post Type

69 lines (60 loc) 1.72 kB
// This load / save / remove cpt var fs = require('fs-extra'), _ = require('underscore'); var _DEFAULT_PREFERENCE = require( __dirname + '/assets/cpt_default.json'); function WP_CPT(json) { this.preference = json ? json : _DEFAULT_PREFERENCE; } WP_CPT.prototype.compile = function() { 'use strict'; fs.readFile( __dirname + '/assets/templates/custom_post_types.php', 'utf8', (err,data) => { if (err) throw err; console.log('... Reading File ...'); var template = _.template(data); console.log('... Redering File ...'); var _rendered = template(this.preference); console.log('... Writting File ...'); var _dist_path_ = this.preference.paths.dist; fs.ensureDir( _dist_path_ , (err) => { if (err) throw err; fs.writeFile(this.preference.paths.dist + '/custom_post_types.php', _rendered, 'utf8', (err) => { if (err) throw err; console.log('... File Saved ...'); }); }); }); }; module.exports = WP_CPT; /*module.exports = { load: function(_filename_) { //@TO-DO: Load JSON }, save: function(_filename_) { //@TO-DO: Save JSON }, add: function(_singlular, plural, _slug, _text_domain, _args) { //@TO-DO: Add new CPT to JSON }, remove: function(_slug) { //@TO-DO: Remove CPT }, sayhi: function() { console.log('Hello, World'); }, saybye: function() { console.log('See you later'); }, compile: function() { _compile(); } }*/ // Command Line Compatible if ( !module.parent ) { if( process.argv[2] == 'compile' ) { console.log('Compiling Custom Post Type Files ... '); var wp_cpt = new WP_CPT(); wp_cpt.compile(); } else { console.log('No argument found'); } }