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
Remove irrelevant hookcode, fix ti clean forking with --project-dir arg #402
Conversation
BREAKING CHANGE: Drops compatability code for below SDK 4.X
Fixes TIMOB-27866
hooks/sdk-fork-fix.js
Outdated
tiPath = path.join(cli.sdk.path, 'node_modules', 'node-titanium-sdk', 'lib', 'titanium.js'); | ||
|
||
if (!fs.existsSync(tiPath)) { | ||
tiPath = path.join(cli.sdk.path, 'node_modules', 'titanium-sdk', 'lib', 'titanium.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need this line because according to https://wiki.appcelerator.org/display/guides2/Titanium+Compatibility+Matrix#TitaniumCompatibilityMatrix-SupportedSDKreleases, we still support SDK 6.0.x and 6.1.x... which are over 3 years old! I can't believe we still support SDK 6.x. I think we need someone to double check our supported SDK releases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove that statement from the docs, we shouldn't be putting supported versions on random pages. Maybe it should link to the product lifecycle doc instead (although it requires some mental gymnastics to try and figure out the valid versions from there :)
At a high level, I'm cool with this PR, but I think we should probably just fix the |
…on check node-titanium-sdk is in all supported SDK lines so we can trust that it will be there, this check doesn't need to compare an SDK version so we don't need to make sure that we can get a semver compliant SDK version
@sgtcoolguy, @cb1kenobi, pushed an update to do the following:
I still need to do the following:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found an issue. The issue exists with the current Titanium CLI code. Here's the scenario:
- App is set to Titanium SDK 9.0.0.GA
- Titanium CLI has 9.0.3.GA as the selected SDK
- Make sure you are NOT in a Titanium app directory (like your home directory)
- Run
titanium build
with NO additional options/args to trigger prompting - Titanium CLI loads SDK 9.0.3.GA and does validation phase
- Titanium CLI prompts you for the platform
- Titanium CLI prompts for the project directory using the --project-dir prompt "field" from SDK 9.0.3.GA
- Type a valid path to a Titanium app
- Project dir prompt takes input and passes it to the field's validate callback, which is really just the project dir option's validate that is monkey patched by sdk-fork-fix.js
pd.validate()
is called, which in turn callsorigValidate()
...ti.validateCorrectSDK()
is a noop, soorigValidate()
succeedsrealValidateCorrectSDK()
is called... 9.0.3.GA != 9.0.0.GA... forks correct Titanium CLI command and throws GracefulShutdown- Error caught by fields, prints empty
[ERROR]
, reprompts for project directory using 9.0.3.GA field - Correct Titanium CLI with 9.0.0.GA selected fires up, but doesn't know the project dir you just entered... prompts for project dir using 9.0.0.GA
- You type the project dir again... but now you have TWO prompts prompting at the same time!!! WTF?
- Typing the path is useless because the prompts stomp on each other's state... you must paste the path and hit enter QUICKLY (may take a few times)
- Build finally takes off, app builds fine, sim launches fine
- Everyone is completely confused
As stated above, this happens before this PR, but it seems like something that might be able to be fixed here.
The problem is project dir's validate()
doesn't know if it's being run from the Titanium CLI when --project-dir is specified or .
resolves a validate dir or if it was prompting. Fields happily prints the error and reprompts.
So, to fix this, you need to monkey patch project-dir's prompt()
to monkey patch field's prompt()
just so you can intercept the GracefulShutdown error! Wowza! Here's the code:
const origPrompt = pd.prompt;
const origValidate = pd.validate;
let gracefulShutdown = false;
pd.validate = function (projectDir, callback) {
return origValidate(projectDir, function (err, projectDir) {
if (!err) {
// if we don't have a tiapp loaded, then the --project-dir callback() wasn't
// called, so just call it now
if (!cli.tiapp) {
projectDir = pd.callback(projectDir);
}
// force overwrite when validate() was called during prompting, otherwise
// the value should be the same
cli.argv['project-dir'] = projectDir;
// now validate the sdk
if (!realValidateCorrectSDK(logger, config, cli, commandName)) {
throw new cli.GracefulShutdown();
}
}
callback(err, projectDir);
});
};
pd.prompt = callback => {
origPrompt(field => {
field.validate = (projectDir, cb) => {
try {
pd.validate(projectDir, cb);
} catch (err) {
if (err instanceof cli.GracefulShutdown) {
gracefulShutdown = true;
return true;
} else {
cb(err);
}
}
};
const origFieldPrompt = field.prompt.bind(field);
field.prompt = cb => {
origFieldPrompt((err, value) => {
if (err) {
cb(err);
} else if (gracefulShutdown) {
// do nothing!
} else {
cb(null, value);
}
});
};
callback(field);
});
};
This [I think] will fix all possible avenues:
titanium build
outside the app directory with promptingtitanium build --project-dir <path>
outside the app directory (no prompting)titanium build
inside an app directory (no prompting)
Note that the prompting of project-dir is the only relevant prompt here. Any other prompt (like pp-uuid, output-dir, etc) is unaffected since they don't throw a GracefulShutdown error.
@cb1kenobi, I added code to force a file prompt for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't have written it any better if I did it myself. APPROVED!
ti clean --project-dir <dir>
when the selected SDK and tiapp SDK differ (TIMOB-27866), and renames the hook file to be representative of it's new purpose