Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions cmd/plugin/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@ var git = require('simple-git/promise')();
var folderExists = require('../../tools/folderExists');
var isSdkDirectory = require('../../tools/isSdkDirectory');
var rmDir = require('../../tools/rmDir');
var fs = require('fs');

function isUrl(str) {
var pattern = new RegExp(/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/)
return str && pattern.test(str);
}

function isGitUrl(str) {
var pattern = new RegExp(/(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$/);
return str && pattern.test(str);
}

function isDirectory(str) {
try {
var stats = fs.statSync(str);
return stats.isDirectory();
} catch(e) {
return false;
}
}

function initPlugin(args) {
var cwd = process.cwd();
Expand All @@ -27,9 +46,12 @@ function initPlugin(args) {
return console.log('\x1b[31mError: Plugin folder with that name already exists');
}

console.log('\x1b[32mCreating Plugin ' + args[2] + ' with tempalte ' + args[3] + '\x1b[0m');
console.log('\x1b[32mCreating Plugin ' + args[2] + ' with template ' + args[3] + '\x1b[0m');

git.clone('https://github.com/BuildFire/' + args[3] + 'PluginTemplate.git', targetPath)
var gitUrl = isUrl(args[3]) || isGitUrl(args[3]) || isDirectory(args[3])
? args[3]
: `https://github.com/BuildFire/${args[3]}PluginTemplate.git`;
git.clone(gitUrl, targetPath)
.then(function() {
rmDir(path.join(targetPath, '.git'));

Expand Down