Skip to content
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

fix: Fixed 'ti sdk install' silent fail when copying new modules to dest #655

Merged
merged 5 commits into from
May 25, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* fix: `ti sdk rm <ver>` treats confirm prompt as false
* fix: Assert required Node.js version
* fix: Clear out undefined command args which fixes `ti project`
* fix: `ti sdk install` no longer silently fails when installing new modules
* fix: When reinstalling an SDK, choosing "Overwrite" will force modules to
also be reinstalled
* fix: Properly handle result from `ti sdk install` overwrite prompt,
`ti sdk uninstall` version prompt, and `ti setup user` name prompt

7.0.0 (5/10/2024)
-------------------
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "titanium",
"version": "7.0.0",
"version": "7.1.0",
"author": "TiDev, Inc. <npm@tidev.io>",
"description": "Command line interface for building Titanium SDK apps",
"type": "module",
Expand Down
87 changes: 50 additions & 37 deletions src/commands/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ SdkSubcommands.install = {
const showProgress = !cli.argv.quiet && !!cli.argv['progress-bars'];
const osName = cli.env.os.name;
const subject = cli.argv._.shift() || 'latest';
const { trace } = cli.debugLogger;

logger.skipBanner(false);
logger.banner();
Expand All @@ -360,7 +361,8 @@ SdkSubcommands.install = {

// step 2: extract the sdk zip file

let { name, renameTo, tempDir } = await extractSDK({
let { forceModules, name, renameTo, tempDir } = await extractSDK({
debugLogger: cli.debugLogger,
file,
force: cli.argv.force,
logger,
Expand Down Expand Up @@ -402,46 +404,49 @@ SdkSubcommands.install = {

// step 5: install the modules

const modules = [];
const modules = {};
src = join(tempDir, 'modules');
try {
if (fs.statSync(src).isDirectory()) {
const modulesDest = join(titaniumDir, 'modules');
if (fs.statSync(src).isDirectory()) {
const modulesDest = join(titaniumDir, 'modules');

for (const platform of fs.readdirSync(src)) {
const srcPlatformDir = join(src, platform);
if (!fs.statSync(srcPlatformDir).isDirectory()) {
continue;
}

for (const platform of fs.readdirSync(src)) {
const srcPlatformDir = join(src, platform);
if (!fs.statSync(srcPlatformDir).isDirectory()) {
for (const moduleName of fs.readdirSync(srcPlatformDir)) {
const srcModuleDir = join(srcPlatformDir, moduleName);
if (!fs.statSync(srcModuleDir).isDirectory()) {
continue;
}

for (const moduleName of fs.readdirSync(srcPlatformDir)) {
const srcModuleDir = join(srcPlatformDir, moduleName);
if (!fs.statSync(srcModuleDir).isDirectory()) {
for (const ver of fs.readdirSync(srcModuleDir)) {
const srcVersionDir = join(srcModuleDir, ver);
if (!fs.statSync(srcVersionDir).isDirectory()) {
continue;
}

for (const ver of fs.readdirSync(srcModuleDir)) {
const srcVersionDir = join(srcModuleDir, ver);
if (!fs.statSync(srcVersionDir).isDirectory()) {
continue;
}

const destDir = join(modulesDest, platform, moduleName, ver);
if (!cli.argv.force || fs.statSync(destDir).isDirectory()) {
continue;
}

modules.push({ src: srcVersionDir, dest: destDir });
const destDir = join(modulesDest, platform, moduleName, ver);
if (!forceModules && fs.existsSync(destDir)) {
trace(`Module ${cyan(`${moduleName}@${ver}`)} already installed`);
continue;
}

modules[`${moduleName}@${ver}`] = { src: srcVersionDir, dest: destDir };
}
}
}
} catch {}
}

if (modules.length) {
for (const { src, dest } of modules) {
if (Object.keys(modules).length) {
trace(`Installing ${cyan(Object.keys(modules).length)} modules:`);
for (const [name, { src, dest }] of Object.entries(modules)) {
trace(` ${cyan(name)}`);
await fs.move(src, dest, { overwrite: true });
}
} else {
trace('SDK has new modules to install');
}

// step 6: cleanup
Expand Down Expand Up @@ -616,20 +621,21 @@ async function getInstallFile({ branch, config, logger, osName, showProgress, su
return { downloadedFile, file };
}

async function extractSDK({ file, force, logger, noPrompt, osName, showProgress, subject, titaniumDir }) {
async function extractSDK({ debugLogger, file, force, logger, noPrompt, osName, showProgress, subject, titaniumDir }) {
const sdkDestRegExp = new RegExp(`^mobilesdk[/\\\\]${osName}[/\\\\]([^/\\\\]+)`);
const tempDir = join(os.tmpdir(), `titanium-cli-${Math.floor(Math.random() * 1e6)}`);
let artifact;
let bar;
let name;
let renameTo;
let forceModules = force;

const onEntry = async (filename, _idx, total) => {
if (total > 1) {
const m = !name && filename.match(sdkDestRegExp);
if (m) {
name = m[1];
renameTo = await checkSDKFile({
const result = await checkSDKFile({
force,
logger,
filename,
Expand All @@ -640,6 +646,9 @@ async function extractSDK({ file, force, logger, noPrompt, osName, showProgress,
subject
});

forceModules = result?.forceModules ?? force;
renameTo = result?.renameTo;

logger.log('Extracting SDK...');
if (showProgress && !bar) {
bar = new ProgressBar(' :paddedPercent [:bar]', {
Expand All @@ -657,30 +666,30 @@ async function extractSDK({ file, force, logger, noPrompt, osName, showProgress,
}
};

logger.trace(`Extracting ${file} -> ${tempDir}`);
debugLogger.trace(`Extracting ${file} -> ${tempDir}`);
await extractZip({
dest: tempDir,
file,
onEntry
});

if (!artifact) {
return { name, renameTo, tempDir };
return { forceModules, name, renameTo, tempDir };
}

logger.trace(`Detected artifact: ${artifact}`);
debugLogger.trace(`Detected artifact: ${artifact}`);
const tempDir2 = join(os.tmpdir(), `titanium-cli-${Math.floor(Math.random() * 1e6)}`);
file = join(tempDir, artifact);

logger.trace(`Extracting ${file} -> ${tempDir2}`);
debugLogger.trace(`Extracting ${file} -> ${tempDir2}`);
await extractZip({
dest: tempDir2,
file,
onEntry
});

await fs.remove(tempDir);
return { name, renameTo, tempDir: tempDir2 };
return { forceModules, name, renameTo, tempDir: tempDir2 };
}

async function checkSDKFile({ force, logger, filename, name, noPrompt, osName, sdkDir, subject }) {
Expand Down Expand Up @@ -720,7 +729,7 @@ async function checkSDKFile({ force, logger, filename, name, noPrompt, osName, s
}
}

const { action } = await prompt({
const action = await prompt({
type: 'select',
name: 'action',
message: `Titanium SDK ${name} is already installed`,
Expand All @@ -739,9 +748,13 @@ async function checkSDKFile({ force, logger, filename, name, noPrompt, osName, s

logger.log();

const result = { action };
if (action === 'rename') {
return renameTo;
result.renameTo = renameTo;
} else if (action === 'overwrite') {
result.forceModules = true;
}
return result;
}

/**
Expand Down Expand Up @@ -789,7 +802,7 @@ SdkSubcommands.uninstall = {
}

if (!versions.length) {
({ versions } = await prompt({
versions = await prompt({
type: 'multiselect',
name: 'versions',
message: 'Which SDKs to uninstall?',
Expand All @@ -799,7 +812,7 @@ SdkSubcommands.uninstall = {
title: v,
value: v
}))
}));
});
if (!versions) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/setup-screens.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ export class SetupScreens {
async userScreen() {
this.logger.log(screenTitle('User'));

const { name } = await prompt({
const name = await prompt({
type: 'text',
message: 'What do you want as your "author" name?',
initial: this.config.get('user.name', ''),
Expand Down
Loading