Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const downloadPhpAndNameSpace = require( './util/downloadPhpAndNameSpace');
/**
* Copy the assets loader files
*
* @param {string} rootDir Root Directory for plugin
* @param {string} namespace Plugin namespace
*/
function clientAssetLoader(rootDir,namespace){
const scripts = 'https://raw.githubusercontent.com/CalderaWP/calderawp-wordpress-plugin/master/react-wp-scripts.php';
const scriptsLocal = rootDir + '/' + scripts.split('/').pop();
const client = 'https://raw.githubusercontent.com/CalderaWP/calderawp-wordpress-plugin/master/php/Client.php';
const clientLocal = rootDir + '/' + client.split('/').pop();
downloadPhpAndNameSpace( client, clientLocal, namespace);
downloadPhpAndNameSpace( scripts, scriptsLocal, namespace);
};
module.exports = clientAssetLoader;
var https = require('https');
var fs = require('fs');
/**
* Copy remote file to local file
*
* @see https://stackoverflow.com/a/11944984/1469799
*
* @param {String} remoteUrl Remote URL to copy
* @param {String} destinationPath Local path to store file in
* @param {Function} callbackFunction Function to run after success or fail
*/
download (remoteUrl, destinationPath, callbackFunction) {
const file = fs.createWriteStream(destinationPath);
const request = https.get(remoteUrl, function(response) {
response.pipe(file);
file.on('finish', function() {
file.close(callbackFunction);
});
}).on('error', function(err) {
fs.unlink(destinationPath);
if (callbackFunction) callbackFunction(err.message);
});
};
module.exports = download;
const download = require( './download' );
const replace = require( 'replace-in-files' );
const path = require( 'path' );
/**
* Download a file and change its namespace
*
*
* @param {string} file Remote file to copy
* @param {string } destPath Path to write file to
* @param {string} nameSpace Namespace to use for new file
*/
function downloadPhpAndNameSpace(file,destPath,nameSpace){
download(file,destPath, () => {
replace({
from: "/calderawp\\WordPressPlugin/g",
to: nameSpace,
files: [destPath]
});
});
}
module.exports = downloadPhpAndNameSpace;
const program = require('commander');
const getGitSubDir = require('./lib/getGitSubDir');
program
.version('0.1.0')
program
.command('client-assets [rootDir] [namespace] ')
.description('Setup WordPress plugin in')
.action( function(namespace,rootDir){
clientAssetLoader(rootDir,namespace);
});
program.parse(process.argv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.