Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[cli]: Consistent list logging#4287

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Brianzchen merged 2 commits intoflow-typed:masterfromBrianzchen:list-logger
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from1 commit
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
NextNext commit
add consistent logger
  • Loading branch information
@Brianzchen
Brianzchen committedMar 18, 2022
commit2ce95f64c66324bbb3077dfb4bb9e9dc582fc487
26 changes: 6 additions & 20 deletionscli/src/commands/install.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@ import {
} from '../lib/npm/npmProjectUtils';
import {getRangeLowerBound} from '../lib/semver';
import {createStub, pkgHasFlowFiles} from '../lib/stubUtils';
import {listItem} from '../lib/logger';

export const name = 'install [explicitLibDefs...]';
export const description = 'Installs libdefs into the ./flow-typed directory';
Expand DownExpand Up@@ -273,15 +274,7 @@ async function installEnvLibDefs(
const localFile = fs.readFileSync(defLocalPath, 'utf-8');

if (!verifySignedCode(localFile) && !overwrite) {
console.log(
colors.bold(
' • %s\n' +
' └> %s\n' +
' %s\n' +
' %s\n' +
' %s\n' +
' %s',
),
listItem(
en,
colors.red(
`${en} already exists and appears to have been manually written or changed!`,
Expand DownExpand Up@@ -312,16 +305,14 @@ async function installEnvLibDefs(
const codeSignPreprocessor = signCodeStream(repoVersion);
await copyFile(def.path, defLocalPath, codeSignPreprocessor);

console.log(
colors.bold(' • %s\n' + ' └> %s'),
listItem(
en,
colors.green(
`.${path.sep}${path.relative(flowProjectRoot, defLocalPath)}`,
),
);
} else {
console.log(
colors.bold(' • %s\n' + ' └> %s'),
listItem(
en,
colors.yellow(
`Was unable to install ${en}. The env might not exist or there is not a version compatible with your version of flow`,
Expand DownExpand Up@@ -703,8 +694,7 @@ async function installNpmLibDef(
);

if (!overwrite && (await fs.exists(filePath))) {
console.error(
' • %s\n' + ' %s\n %s\n └> %s',
listItem(
colors.bold(
colors.red(
`${terseFilePath} already exists and appears to have been manually ` +
Expand All@@ -727,11 +717,7 @@ async function installNpmLibDef(
const codeSignPreprocessor = signCodeStream(repoVersion);
await copyFile(npmLibDef.path, filePath, codeSignPreprocessor);

console.log(
colors.bold(' • %s\n' + ' └> %s'),
fileName,
colors.green(`.${path.sep}${terseFilePath}`),
);
listItem(fileName, colors.green(`.${path.sep}${terseFilePath}`));

// Remove any lingering stubs
console.log(npmLibDef.name);
Expand Down
27 changes: 27 additions & 0 deletionscli/src/lib/__tests__/logger.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
// @flow
import colors from 'colors';

import {listItem} from '../logger';

describe('logger', () => {
const consoleLog = jest.fn();
jest.spyOn(console, 'log').mockImplementation(consoleLog);

beforeEach(() => {
jest.clearAllMocks();
});

describe('listItem', () => {
it('returns expected result', () => {
listItem('test', 'a', 'b');

expect(consoleLog).toHaveBeenCalledWith(
colors.bold(` • test
└> a
b`),
);
});
});

describe('list', () => {});
});
24 changes: 24 additions & 0 deletionscli/src/lib/logger.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
// @flow
import colors from 'colors';

const bulletPoint = ` • `;
const arrow = ` └> `;
const genericRowPad = ` `;

const createListItem = (values: Array<string>): string => {
const [first, second, ...rest] = values;
let value = `${bulletPoint}${first}\n`;
if (second) {
value += `${arrow}${second}\n`;
}
if (rest.length > 0) {
rest.forEach((r, i) => {
value += `${genericRowPad}${r}${i === rest.length - 1 ? '' : '\n'}`;
});
}
return colors.bold(value);
};

export const listItem = (...values: Array<string>): void => {
console.log(createListItem(values));
};
8 changes: 2 additions & 6 deletionscli/src/lib/stubUtils.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@ import {path} from './node';
import {signCode} from './codeSign';
import {verifySignedCode} from './codeSign';
import {versionToString} from './semver';
import {listItem} from './logger';

export function glob(pattern: string, options: Object): Promise<Array<string>> {
return new Promise((resolve, reject) =>
Expand DownExpand Up@@ -532,12 +533,7 @@ export async function createStub(
typescriptTypingsContent,
);
const terseFilename = path.relative(projectRoot, filename);
console.log(
colors.bold(' • %s@%s\n' + ' └> %s'),
packageName,
version,
colors.red(terseFilename),
);
listItem(`${packageName}@${version}`, colors.red(terseFilename));
if (resolutionError) {
console.log(
colors.yellow(
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp