Skip to content

feat: add default values to postclone prompts if it is executed on non interactive environment and fix typo in script args #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions seed-tests/postclone.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand All @@ -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();
}
});
Expand Down
4 changes: 2 additions & 2 deletions seed-tests/tests.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
47 changes: 38 additions & 9 deletions src/scripts/postclone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -578,11 +588,6 @@ function askInitGit() {
}
}

// todo
function getTslintCommand(appPath) {

}

function replaceFiles() {
for (key in filesToReplace) {
var file = filesToReplace[key];
Expand Down Expand Up @@ -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');
Expand Down