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 7 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
47 changes: 27 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 Down Expand Up @@ -89,7 +90,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 +145,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 +208,7 @@ 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) return;
if (_jsonOnly || ctx.program?.opts().noSummary) 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 +243,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 +475,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 +543,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 +623,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
6 changes: 3 additions & 3 deletions packages/core/src/system/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ export const readObjectSync = <T = object>(filePath?: string, sanitize?: boolean
}
}
} catch (e) {
logError(`readObjectSync: Parsing of ${chalk().bold(filePath)} failed with ${e}`);
logError(`readObjectSync: Parsing of ${chalk().bold.white(filePath)} failed with ${e}`);
return null;
}
return obj as T;
Expand All @@ -541,7 +541,7 @@ export const updateObjectSync = (filePath: string, updateObj: object) => {
export const getRealPath = (p: string | undefined, key = 'undefined', original?: string) => {
if (!p) {
if (original) {
logDebug(`Path ${chalk().bold(key)} is not defined. using default: ${chalk().bold(original)}`);
logDebug(`Path ${chalk().bold.white(key)} is not defined. using default: ${chalk().bold.white(original)}`);
}
return original;
}
Expand Down Expand Up @@ -576,7 +576,7 @@ const _refToValue = (ref: string, key: string) => {
const output = lGet(obj, valPath);
return output;
} else {
logWarning(`_refToValue: ${chalk().bold(realPath)} does not exist!`);
logWarning(`_refToValue: ${chalk().bold.white(realPath)} does not exist!`);
}
}
return ref;
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/tasks/creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ type TaskOptionsMap<OKey> = Record<Extract<OKey, string>, RnvTaskOption<OKey>>;
export const createTaskOptionsMap = <OKey>(opts: ReadonlyArray<RnvTaskOption<OKey>>) => {
const map: Partial<TaskOptionsMap<OKey>> = {};
opts.forEach((opt) => {
map[opt.key] = opt;
if (opt.altKey) {
map[opt.altKey] = opt;
} else {
map[opt.key] = opt;
}
});
return map as TaskOptionsMap<OKey>;
};
Expand Down
Loading
Loading