Skip to content

Commit dc2f9e8

Browse files
feat: add default values to postclone prompts if it is executed on non interactive environment and fix typo in script args (#131)
* feat: add default values to postclone prompts if it is executed on non interactive environment chore: update unit tests to check if postclone script has added an import of the plugin to the dynamically created apps fix: Resolve a typo in the postclone script arguments * chore: fix typo in prompts
1 parent 860d8ac commit dc2f9e8

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

seed-tests/postclone.tests.js

+6
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ describe('postclone', function () {
6363
} else {
6464
var seedCopyPath = path.resolve(__dirname, constants.SEED_COPY_LOCATION);
6565
expect(fs.existsSync(seedCopyPath + "/demo")).toBe(true);
66+
expect(stdout.includes("Updating ../demo/")).toBe(true);
6667

6768
expect(fs.existsSync(seedCopyPath + "/demo-angular")).toBe(false);
69+
expect(stdout.includes("Updating ../demo-angular/")).toBe(false);
70+
6871
done();
6972
}
7073
});
@@ -84,8 +87,11 @@ describe('postclone', function () {
8487
} else {
8588
var seedCopyPath = path.resolve(__dirname, constants.SEED_COPY_LOCATION);
8689
expect(fs.existsSync(seedCopyPath + "/demo")).toBe(false);
90+
expect(stdout.includes("Updating ../demo/")).toBe(false);
8791

8892
expect(fs.existsSync(seedCopyPath + "/demo-angular")).toBe(true);
93+
expect(stdout.includes("Updating ../demo-angular/")).toBe(true);
94+
8995
done();
9096
}
9197
});

seed-tests/tests.utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ exports.copySeedDir = function copySeedDir(seedLocation, copyLocation, callback)
6868
});
6969
};
7070

71-
exports.callPostclone = function callPostclone(seedLocation, githubUsername, pluginName, initGit, includeTypescriptDemo, includeAngularDemo, callback) {
71+
exports.callPostclone = function callPostclone(seedLocation, githubUsername, pluginName, initGit, includeTypeScriptDemo, includeAngularDemo, callback) {
7272
var postcloneScript = getPackageJsonPostcloneScript();
73-
postcloneScript = postcloneScript.replace("postclone.js", "postclone.js gitHubUsername=" + githubUsername + " pluginName=" + pluginName + " initGit=" + initGit + " includeTypescriptDemo=" + includeTypescriptDemo + " includeAngularDemo=" + includeAngularDemo);
73+
postcloneScript = postcloneScript.replace("postclone.js", "postclone.js gitHubUsername=" + githubUsername + " pluginName=" + pluginName + " initGit=" + initGit + " includeTypeScriptDemo=" + includeTypeScriptDemo + " includeAngularDemo=" + includeAngularDemo);
7474
console.log("Executing postclone script with args: " + postcloneScript);
7575
exec("cd " + seedLocation + "/src && " + postcloneScript, function (error, stdout, stderr) {
7676
callback(error, stdout, stderr);

src/scripts/postclone.js

+38-9
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ var class_name,
9797

9898
console.log('NativeScript Plugin Seed Configuration');
9999

100-
// Expected order: `gitHubUsername` `pluginName` `initGit` `includeTypescriptDemo` `includeAngularDemo`
101-
// Example: gitHubUsername=PluginAuthor pluginName=myPluginClassName initGit=n includeTypescriptDemo=y includeAngularDemo=n
100+
// Expected order: `gitHubUsername` `pluginName` `initGit` `includeTypeScriptDemo` `includeAngularDemo`
101+
// Example: gitHubUsername=PluginAuthor pluginName=myPluginClassName initGit=n includeTypeScriptDemo=y includeAngularDemo=n
102102
var parseArgv = function () {
103103
var argv = Array.prototype.slice.call(process.argv, 2);
104104
var result = {};
@@ -115,11 +115,21 @@ if (argv) {
115115
inputParams.github_username = argv.gitHubUsername;
116116
inputParams.plugin_name = argv.pluginName;
117117
inputParams.init_git = argv.initGit;
118-
inputParams.include_typescript_demo = argv.includeTypescriptDemo;
118+
inputParams.include_typescript_demo = argv.includeTypeScriptDemo;
119119
inputParams.include_angular_demo = argv.includeAngularDemo;
120120
// inputParams.include_vue_demo = argv.includeVueDemo;
121121
}
122122

123+
if (!isInteractive() && (!inputParams.github_username || !inputParams.plugin_name || !inputParams.init_git || !inputParams.include_typescript_demo || !inputParams.include_angular_demo)) {
124+
console.log("Using default values for plugin creation since your shell is not interactive.");
125+
inputParams.github_username = "PluginAuthor";
126+
inputParams.plugin_name = "myPluginClassName";
127+
inputParams.init_git = "y";
128+
inputParams.include_typescript_demo = "y";
129+
inputParams.include_angular_demo = "n";
130+
// inputParams.include_vue_demo = "n";
131+
}
132+
123133
askGithubUsername();
124134

125135
function askGithubUsername() {
@@ -197,7 +207,7 @@ function askAngularDemo() {
197207
prompt.start();
198208
prompt.get({
199209
name: 'include_angular_demo',
200-
description: 'Do you want to include a "Angular NativeScript" application linked with your plugin to make development easier (y/n)?',
210+
description: 'Do you want to include an "Angular NativeScript" application linked with your plugin to make development easier (y/n)?',
201211
default: 'n'
202212
}, function (err, result) {
203213
if (err) {
@@ -578,11 +588,6 @@ function askInitGit() {
578588
}
579589
}
580590

581-
// todo
582-
function getTslintCommand(appPath) {
583-
584-
}
585-
586591
function replaceFiles() {
587592
for (key in filesToReplace) {
588593
var file = filesToReplace[key];
@@ -626,6 +631,30 @@ function addPluginToDemoApps() {
626631
}
627632
}
628633

634+
function isInteractive() {
635+
const result = isRunningInTTY() && !isCIEnvironment();
636+
return result;
637+
}
638+
639+
/**
640+
* Checks if current process is running in Text Terminal (TTY)
641+
*/
642+
function isRunningInTTY() {
643+
return process.stdout &&
644+
process.stdout.isTTY &&
645+
process.stdin &&
646+
process.stdin.isTTY;
647+
}
648+
649+
function isCIEnvironment() {
650+
// The following CI environments set their own environment variables that we respect:
651+
// travis: "CI",
652+
// circleCI: "CI",
653+
// jenkins: "JENKINS_HOME"
654+
655+
return !!(process.env && (process.env.CI || process.env.JENKINS_HOME));
656+
}
657+
629658
function initGit() {
630659
if (inputParams.init_git && inputParams.init_git.toLowerCase() === 'y') {
631660
rimraf.sync('../.git');

0 commit comments

Comments
 (0)