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/cli #1614

Merged
merged 9 commits into from
Jul 1, 2024
Merged

Fix/cli #1614

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
81 changes: 61 additions & 20 deletions packages/cli/src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const PRIVATE_PARAMS = ['-k', '--key'];
let _isInfoEnabled = false;
let _infoFilter: Array<string> = [];
// let _c: RnvContext;
// let _isMono = false;
let _isMono = false;
let _defaultColor: any = _chalkCols.white;
let _highlightColor = _chalkCols.white;
// let _analytics: AnalyticsApi;
Expand All @@ -47,8 +47,9 @@ export const logInitialize = () => {
// _analytics = analytics;

if (ctx.program.opts().mono) {
_isMono = true;
currentChalk = _chalkMono;
chalkBlue = _chalkMono;
chalkBlue = _chalkMono.white;
}
_updateDefaultColors();
// RNV = getCurrentCommand();
Expand All @@ -57,7 +58,7 @@ export const logInitialize = () => {

export const logWelcome = () => {
const ctx = getContext();
if (ctx.program?.opts().help) return;
if (ctx.program?.opts().help || ctx.program?.opts().noIntro) return;
const shortLen = 64;
// prettier-ignore
let str = _defaultColor(`
Expand All @@ -74,7 +75,9 @@ export const logWelcome = () => {
ctx.rnvVersion = ctx.files.rnv.package.version;
str += printIntoBox(
currentChalk.grey(
`${ICN_ROCKET} v:${ctx.rnvVersion} | ${'renative.org'} | ${ctx.timeStart.toLocaleString()}`
`${!_isMono ? ICN_ROCKET : 'RNV'} v:${
ctx.rnvVersion
} | ${'renative.org'} | ${ctx.timeStart.toLocaleString()}`
),
shortLen
);
Expand All @@ -89,7 +92,7 @@ export const logWelcome = () => {
// shortLen
// );
// str += printIntoBox(` ${ICN_ROCKET} ${currentChalk.yellow('Firing up!...')}`);
str += printIntoBox(`$ ${currentChalk.bold(getCurrentCommand(true))}`, shortLen);
str += printIntoBox(`$ ${_highlightColor(getCurrentCommand(true))}`, shortLen);
if (ctx.timeStart) {
// str += printIntoBox(` Start Time: ${currentChalk.grey(ctx.timeStart.toLocaleString())}`);
}
Expand Down Expand Up @@ -144,8 +147,8 @@ export function stripAnsi(string: string) {
// };

const _updateDefaultColors = () => {
_defaultColor = currentChalk;
_highlightColor = currentChalk.bold; //currentChalk.bold;
_defaultColor = currentChalk.white;
_highlightColor = currentChalk.bold.white; //currentChalk.bold;
};
_updateDefaultColors();

Expand Down Expand Up @@ -207,8 +210,39 @@ export const logRaw = (...args: Array<string>) => {
export const logSummary = (opts?: { header?: string; headerStyle?: 'success' | 'warning' | 'error' | 'none' }) => {
const ctx = getContext();
if (ctx.program?.opts().help) return;
if (_jsonOnly) {
if (!ctx.logging.logMessages || !ctx.logging.logMessages.length) {
return;
} else {
const cleanedMessages = ctx.logging.logMessages
.map(stripAnsi)
.map((msg) => {
const headerEndIndex = msg.indexOf(':') + 1;
const header = msg.slice(0, headerEndIndex).trim();
const items = msg
.slice(headerEndIndex)
.split('\n')
.map((line) => line.trim())
.filter((line) => line);
return `${header} ${items.join(', ')}`;
})
.join('');
return _printJson({
type: 'summaryLog',
task: stripAnsi(_getCurrentTask()),
message: cleanedMessages,
});
}
}

if (_jsonOnly) return;
if (ctx.program?.opts().noSummary) {
if (!ctx.logging.logMessages || !ctx.logging.logMessages.length) {
return;
} else {
console.log(ctx.logging.logMessages.join('').replace(/\n\s*\n\s*\n/g, '\n\n'));
return;
}
}

if (ctx.paths.project.configExists && !ctx.paths.IS_NPX_MODE && !ctx.paths.IS_LINKED) {
logAndSave(chalk().yellow('You are trying to run global rnv command in your current project.'), true);
Expand Down Expand Up @@ -243,14 +277,20 @@ export const logSummary = (opts?: { header?: string; headerStyle?: 'success' | '
const headerPrefix =
headerStyle === 'success' ? '✔ ' : headerStyle === 'warning' ? '⚠ ' : headerStyle === 'error' ? '⨯ ' : '';
const headerTextPlain = `${headerPrefix}${opts?.header || 'SUMMARY'}`;
const headerChalk =
headerStyle === 'success'
? currentChalk.green.bold
: headerStyle === 'warning'
? currentChalk.yellow.bold
: headerStyle === 'error'
? currentChalk.green.red
: (v: string) => v;
let headerChalk;

if (_isMono) {
headerChalk = currentChalk.white;
} else {
headerChalk =
headerStyle === 'success'
? currentChalk.green.bold
: headerStyle === 'warning'
? currentChalk.yellow.bold
: headerStyle === 'error'
? currentChalk.green.red
: (v: string) => v;
}
let str = printBoxStart(
`${headerChalk(headerTextPlain)} ${timeString} | rnv@${ctx.rnvVersion}`,
getCurrentCommand()
Expand Down Expand Up @@ -469,8 +509,9 @@ export const logInitTask = (task: string) => {
message: stripAnsi(_sanitizePaths(task)),
});
}

const msg = `${chalkBlue.bold('task:')} ○ ${task} ${taskCount}`;
const msg = !_isMono
? `${chalkBlue.bold('task:')} ○ ${task} ${taskCount}`
: `${currentChalk.white('task:')} ○ ${task} ${taskCount}`;

console.log(msg);
};
Expand Down Expand Up @@ -536,7 +577,7 @@ export const logInfo = (msg: string) => {
message: stripAnsi(_sanitizePaths(msg)),
});
}
console.log(`${currentChalk.bold('info:')} ${_sanitizePaths(msg)}`);
console.log(`${_highlightColor('info:')} ${_sanitizePaths(msg)}`);
};

export const logDebug = (...args: Array<string>) => {
Expand Down Expand Up @@ -616,7 +657,7 @@ export const logError = (e: Error | string | unknown, opts?: { skipAnalytics: bo

export const logAppInfo = (c: RnvContext) => {
if (!_jsonOnly) {
logInfo(`Current app config: ${currentChalk.bold(c.runtime.appId)}`);
logInfo(`Current app config: ${_highlightColor(c.runtime.appId)}`);
}
};

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ export const loadDefaultConfigTemplates = async () => {

if (!configTemplatesPath) {
return Promise.reject(
`RNV Cannot find package: ${chalk().bold(pkgName)}. Looked in: ${chalk().gray(pathLookups.join(', '))}`
`RNV Cannot find package: ${chalk().bold.white(pkgName)}. Looked in: ${chalk().gray(
pathLookups.join(', ')
)}`
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/configs/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ export const getWorkspaceDirPath = async (c: RnvContext) => {
const { conf } = await inquirerPrompt({
name: 'conf',
type: 'confirm',
message: `Your project belongs to workspace ${chalk().bold(
message: `Your project belongs to workspace ${chalk().bold.white(
ws
)}. do you want to add new workspace ${chalk().bold(ws)} to your local system at ${chalk().bold(
wsDir
)}?`,
)}. do you want to add new workspace ${chalk().bold.white(
ws
)} to your local system at ${chalk().bold.white(wsDir)}?`,
warningMessage: 'No app configs found for this project',
});
confirm = conf;
Expand Down Expand Up @@ -88,7 +88,7 @@ export const getWorkspaceOptions = () => {
return generateOptions(c.files.dotRnv.configWorkspaces?.workspaces, false, null, (i, obj, mapping, defaultVal) => {
logDebug('getWorkspaceOptions');

return ` [${chalk().grey(i + 1)}]> ${chalk().bold(defaultVal)} ${getWorkspaceConnectionString(obj)}\n`;
return ` [${chalk().grey(i + 1)}]> ${chalk().bold.white(defaultVal)} ${getWorkspaceConnectionString(obj)}\n`;
});
};

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/context/contextProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const getAppConfigBuildsFolder = (customPath?: string) => {
const pp = customPath || c.paths.appConfig.dir;
if (!pp) {
logWarning(
`getAppConfigBuildsFolder: Path ${chalk().bold(
`getAppConfigBuildsFolder: Path ${chalk().bold.white(
'c.paths.appConfig.dir'
)} not defined! can't return path. You might not be in renative project`
);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/engines/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ export const loadEnginePluginDeps = async (engineConfigs: Array<RnvEngineInstall
const addedPluginsKeys = Object.keys(addedPlugins);

logInfo(
`Engines: ${chalk().yellow(engineKeys.join(','))} require plugins ${chalk().bold(
`Engines: ${chalk().yellow(engineKeys.join(','))} require plugins ${chalk().bold.white(
addedPluginsKeys.join(',')
)} to be added to ${chalk().bold(c.paths.project.config)}`
)} to be added to ${chalk().bold.white(c.paths.project.config)}`
);
const confirm = await inquirerPrompt({
name: 'selectedScheme',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/formatter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const checkForDuplicates = (arr: Array<any>) => {
if (v) {
Object.keys(v).forEach((k) => {
if (dupCheck[k]) {
logWarning(`Key ${chalk().bold(k)} is duplicated in your package.json`);
logWarning(`Key ${chalk().bold.white(k)} is duplicated in your package.json`);
}
dupCheck[k] = true;
});
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/platforms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const _isPlatformSupportedSync = (platform: RnvPlatform, resolve?: () => void, r
if (reject) {
reject(
chalk().red(
`Platform ${platform} is not supported. Use one of the following: ${chalk().bold(
`Platform ${platform} is not supported. Use one of the following: ${chalk().bold.white(
c.runtime.availablePlatforms.join(', ')
)} .`
)
Expand All @@ -117,7 +117,9 @@ export const isPlatformActive = (resolve?: () => void) => {

if (!c.buildConfig || !c.buildConfig.platforms) {
logError(
`Your appConfigFile is not configured properly! check ${chalk().bold(c.paths.appConfig.config)} location.`
`Your appConfigFile is not configured properly! check ${chalk().bold.white(
c.paths.appConfig.config
)} location.`
);
if (resolve) resolve();
return false;
Expand Down
36 changes: 21 additions & 15 deletions packages/core/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ export const configurePlugins = async () => {
// Skip Warning as this is intentional "plugin":null override
} else {
logWarning(
`Plugin with name ${chalk().bold(
`Plugin with name ${chalk().bold.white(
k
)} does not exists in ReNative source:rnv scope. you need to define it manually here: ${chalk().bold(
)} does not exists in ReNative source:rnv scope. you need to define it manually here: ${chalk().bold.white(
c.paths.project.builds.config
)}`
);
Expand Down Expand Up @@ -415,9 +415,9 @@ const _resolvePluginDependencies = async (
const { confirm } = await inquirerPrompt({
type: 'confirm',
message: `Install ${key}?`,
warningMessage: `Plugin ${chalk().bold(key)} source:${chalk().bold(scope)} required by ${chalk().red(
parentKey
)} is not installed`,
warningMessage: `Plugin ${chalk().bold.white(key)} source:${chalk().bold.white(
scope
)} required by ${chalk().red(parentKey)} is not installed`,
});
if (confirm && c.files.project.config_original?.plugins) {
c.files.project.config_original.plugins[key] = `source:${scope}`;
Expand All @@ -427,7 +427,9 @@ const _resolvePluginDependencies = async (
}
} else {
logWarning(
`Plugin ${chalk().bold(parentKey)} requires ${chalk().red(key)} which is not available in your system`
`Plugin ${chalk().bold.white(parentKey)} requires ${chalk().red(
key
)} which is not available in your system`
);
}
} else {
Expand Down Expand Up @@ -533,13 +535,13 @@ export const parsePlugins = (
// );
// }
} else {
logError(`You have no plugins defined in ${chalk().bold(c.paths.project.builds.config)}`);
logError(`You have no plugins defined in ${chalk().bold.white(c.paths.project.builds.config)}`);
}
} else {
logWarning(
`You haven't included any ${chalk().bold('{ common: { includedPlugins: [] }}')} in your ${chalk().bold(
c.paths.appConfig.config
)}. Your app might not work correctly`
`You haven't included any ${chalk().bold.white(
'{ common: { includedPlugins: [] }}'
)} in your ${chalk().bold.white(c.paths.appConfig.config)}. Your app might not work correctly`
);
}
}
Expand Down Expand Up @@ -684,7 +686,9 @@ const _overridePlugin = (c: RnvContext, pluginsPath: string, dir: string) => {
// });
} else {
logDebug(
`Your plugin configuration has no override path ${chalk().bold(source)}. skipping folder override action`
`Your plugin configuration has no override path ${chalk().bold.white(
source
)}. skipping folder override action`
);
}

Expand Down Expand Up @@ -761,7 +765,7 @@ export const overrideFileContents = (dest: string, override: Record<string, stri
foundRegEx = true;
fileToFix = fileToFix.replace(regEx, override[fk]);
logSuccess(
`${chalk().bold(dest.split('node_modules').pop())} requires override by: ${chalk().bold(
`${chalk().bold.white(dest.split('node_modules').pop())} requires override by: ${chalk().bold.white(
overridePath.split('node_modules').pop()
)}. FIXING...DONE`
);
Expand All @@ -774,7 +778,7 @@ export const overrideFileContents = (dest: string, override: Record<string, stri
logWarning(
`No Match found in ${chalk().red(
dest.split('node_modules').pop()
)} for expression: ${chalk().gray(term)}. source: ${chalk().bold(
)} for expression: ${chalk().gray(term)}. source: ${chalk().bold.white(
overridePath.split('node_modules').pop()
)}`
);
Expand Down Expand Up @@ -842,7 +846,7 @@ export const checkForPluginDependencies = async (postInjectHandler?: AsyncCallba
const answer = await inquirerPrompt({
type: 'confirm',
message: `Install ${Object.keys(toAdd).join(', ')}?`,
warningMessage: `One or more dependencies are not installed: ${chalk().bold(
warningMessage: `One or more dependencies are not installed: ${chalk().bold.white(
Object.keys(toAdd).join(', ')
)}`,
});
Expand Down Expand Up @@ -895,7 +899,9 @@ export const overrideTemplatePlugins = async () => {
}
} else {
logInfo(
`Plugin overrides disabled for: ${chalk().bold(key)} with disablePluginTemplateOverrides. SKIPPING`
`Plugin overrides disabled for: ${chalk().bold.white(
key
)} with disablePluginTemplateOverrides. SKIPPING`
);
}
}, true);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/projects/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export const copyRuntimeAssets = async () => {
if (!c.buildConfig?.common) {
logDebug('BUILD_CONFIG', c.buildConfig);
logWarning(
`Your ${chalk().bold(
`Your ${chalk().bold.white(
c.paths.appConfig.config
)} is misconfigured. (Maybe you have older version?). Missing ${chalk().bold(
)} is misconfigured. (Maybe you have older version?). Missing ${chalk().bold.white(
'{ common: {} }'
)} object at root`
);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/projects/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const handleMutations = async () => {
);
let msg = '';
mutations.forEach((m) => {
msg += `- ${chalk().bold(m.name)} (${chalk().red(m.original?.version || 'N/A')}) => (${chalk().green(
msg += `- ${chalk().bold.white(m.name)} (${chalk().red(m.original?.version || 'N/A')}) => (${chalk().green(
m.updated.version
)}) ${chalk().gray(`${m.msg} | ${m.source}`)}\n`;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/projects/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const versionCheck = async (c: RnvContext) => {
);
if (c.runtime.rnvVersionRunner && c.runtime.rnvVersionProject) {
if (c.runtime.rnvVersionRunner !== c.runtime.rnvVersionProject && !c.program.opts().skipRnvCheck) {
const recCmd = chalk().bold(`$ npx ${getCurrentCommand(true)}`);
const recCmd = chalk().bold.white(`$ npx ${getCurrentCommand(true)}`);
const actionNoUpdate = 'Continue and skip updating package.json';
const actionWithUpdate = 'Continue and update package.json';
const actionUpgrade = `Upgrade project to ${c.runtime.rnvVersionRunner}`;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/system/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ const execCLI = (cli: string, command: string, opts: ExecOptions = {}) => {
c.buildConfig?.sdks
);
return Promise.reject(
`Location of your cli ${chalk().bold(p)} does not exist. check your ${chalk().bold(
`Location of your cli ${chalk().bold.white(p)} does not exists. check your ${chalk().bold.white(
c.paths.workspace.config
)} file if your ${chalk().bold('sdks')} paths are correct`
)} file if your ${chalk().bold.white('sdks')} paths are correct`
);
}

Expand Down
Loading
Loading