diff --git a/seed-tests/postclone.tests.js b/seed-tests/postclone.tests.js index e954f2a..c9c3c55 100644 --- a/seed-tests/postclone.tests.js +++ b/seed-tests/postclone.tests.js @@ -63,8 +63,11 @@ describe('postclone', function () { } else { var seedCopyPath = path.resolve(__dirname, constants.SEED_COPY_LOCATION); expect(fs.existsSync(seedCopyPath + "/demo")).toBe(true); + expect(stdout.includes("Updating ../demo/")).toBe(true); expect(fs.existsSync(seedCopyPath + "/demo-angular")).toBe(false); + expect(stdout.includes("Updating ../demo-angular/")).toBe(false); + done(); } }); @@ -84,8 +87,11 @@ describe('postclone', function () { } else { var seedCopyPath = path.resolve(__dirname, constants.SEED_COPY_LOCATION); expect(fs.existsSync(seedCopyPath + "/demo")).toBe(false); + expect(stdout.includes("Updating ../demo/")).toBe(false); expect(fs.existsSync(seedCopyPath + "/demo-angular")).toBe(true); + expect(stdout.includes("Updating ../demo-angular/")).toBe(true); + done(); } }); diff --git a/seed-tests/tests.utils.js b/seed-tests/tests.utils.js index 8975eaa..feb6115 100644 --- a/seed-tests/tests.utils.js +++ b/seed-tests/tests.utils.js @@ -68,9 +68,9 @@ exports.copySeedDir = function copySeedDir(seedLocation, copyLocation, callback) }); }; -exports.callPostclone = function callPostclone(seedLocation, githubUsername, pluginName, initGit, includeTypescriptDemo, includeAngularDemo, callback) { +exports.callPostclone = function callPostclone(seedLocation, githubUsername, pluginName, initGit, includeTypeScriptDemo, includeAngularDemo, callback) { var postcloneScript = getPackageJsonPostcloneScript(); - postcloneScript = postcloneScript.replace("postclone.js", "postclone.js gitHubUsername=" + githubUsername + " pluginName=" + pluginName + " initGit=" + initGit + " includeTypescriptDemo=" + includeTypescriptDemo + " includeAngularDemo=" + includeAngularDemo); + postcloneScript = postcloneScript.replace("postclone.js", "postclone.js gitHubUsername=" + githubUsername + " pluginName=" + pluginName + " initGit=" + initGit + " includeTypeScriptDemo=" + includeTypeScriptDemo + " includeAngularDemo=" + includeAngularDemo); console.log("Executing postclone script with args: " + postcloneScript); exec("cd " + seedLocation + "/src && " + postcloneScript, function (error, stdout, stderr) { callback(error, stdout, stderr); diff --git a/src/scripts/postclone.js b/src/scripts/postclone.js index d353961..9313189 100644 --- a/src/scripts/postclone.js +++ b/src/scripts/postclone.js @@ -97,8 +97,8 @@ var class_name, console.log('NativeScript Plugin Seed Configuration'); -// Expected order: `gitHubUsername` `pluginName` `initGit` `includeTypescriptDemo` `includeAngularDemo` -// Example: gitHubUsername=PluginAuthor pluginName=myPluginClassName initGit=n includeTypescriptDemo=y includeAngularDemo=n +// Expected order: `gitHubUsername` `pluginName` `initGit` `includeTypeScriptDemo` `includeAngularDemo` +// Example: gitHubUsername=PluginAuthor pluginName=myPluginClassName initGit=n includeTypeScriptDemo=y includeAngularDemo=n var parseArgv = function () { var argv = Array.prototype.slice.call(process.argv, 2); var result = {}; @@ -115,11 +115,21 @@ if (argv) { inputParams.github_username = argv.gitHubUsername; inputParams.plugin_name = argv.pluginName; inputParams.init_git = argv.initGit; - inputParams.include_typescript_demo = argv.includeTypescriptDemo; + inputParams.include_typescript_demo = argv.includeTypeScriptDemo; inputParams.include_angular_demo = argv.includeAngularDemo; // inputParams.include_vue_demo = argv.includeVueDemo; } +if (!isInteractive() && (!inputParams.github_username || !inputParams.plugin_name || !inputParams.init_git || !inputParams.include_typescript_demo || !inputParams.include_angular_demo)) { + console.log("Using default values for plugin creation since your shell is not interactive."); + inputParams.github_username = "PluginAuthor"; + inputParams.plugin_name = "myPluginClassName"; + inputParams.init_git = "y"; + inputParams.include_typescript_demo = "y"; + inputParams.include_angular_demo = "n"; + // inputParams.include_vue_demo = "n"; +} + askGithubUsername(); function askGithubUsername() { @@ -197,7 +207,7 @@ function askAngularDemo() { prompt.start(); prompt.get({ name: 'include_angular_demo', - description: 'Do you want to include a "Angular NativeScript" application linked with your plugin to make development easier (y/n)?', + description: 'Do you want to include an "Angular NativeScript" application linked with your plugin to make development easier (y/n)?', default: 'n' }, function (err, result) { if (err) { @@ -578,11 +588,6 @@ function askInitGit() { } } -// todo -function getTslintCommand(appPath) { - -} - function replaceFiles() { for (key in filesToReplace) { var file = filesToReplace[key]; @@ -626,6 +631,30 @@ function addPluginToDemoApps() { } } +function isInteractive() { + const result = isRunningInTTY() && !isCIEnvironment(); + return result; +} + +/** + * Checks if current process is running in Text Terminal (TTY) + */ +function isRunningInTTY() { + return process.stdout && + process.stdout.isTTY && + process.stdin && + process.stdin.isTTY; +} + +function isCIEnvironment() { + // The following CI environments set their own environment variables that we respect: + // travis: "CI", + // circleCI: "CI", + // jenkins: "JENKINS_HOME" + + return !!(process.env && (process.env.CI || process.env.JENKINS_HOME)); +} + function initGit() { if (inputParams.init_git && inputParams.init_git.toLowerCase() === 'y') { rimraf.sync('../.git');