Created
October 29, 2018 19:00
-
-
Save Shelob9/2381893cef0db9ff85f4707df7d013c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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