Skip to content

Commit

Permalink
refactor(@angular/cli): remove chalk dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin committed May 1, 2018
1 parent 894e008 commit ceeb292
Show file tree
Hide file tree
Showing 22 changed files with 1,887 additions and 424 deletions.
2,160 changes: 1,820 additions & 340 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@angular-devkit/schematics": "github:angular/angular-devkit-schematics-builds",
"@schematics/angular": "github:angular/schematics-angular-builds",
"@schematics/update": "github:angular/schematics-update-builds",
"chalk": "~2.2.0",
"opn": "~5.1.0",
"resolve": "^1.1.7",
"rxjs": "^6.0.0",
Expand Down
6 changes: 2 additions & 4 deletions packages/@angular/cli/bin/ng
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
// Due to an obscure Mac bug, do not start this title with any symbol.
process.title = 'ng';

var red = require('chalk').red;

var version = process.version.substr(1).split('.');
if (Number(version[0]) < 8 || (Number(version[0]) === 8 && Number(version[1]) < 9)) {
process.stderr.write(red(
process.stderr.write(
'You are running version ' + process.version + ' of Node.js, which is not supported by Angular CLI v6.\n' +
'The official Node.js version that is supported is 8.9 and greater.\n\n' +
'Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.\n'
));
);

process.exit(3);
}
Expand Down
7 changes: 3 additions & 4 deletions packages/@angular/cli/commands/add.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { tags } from '@angular-devkit/core';
import { tags, terminal } from '@angular-devkit/core';
import { NodePackageDoesNotSupportSchematics } from '@angular-devkit/schematics/tools';
import chalk from 'chalk';
import { CommandScope, Option } from '../models/command';
import { parseOptions } from '../models/command-runner';
import { getPackageManager } from '../utilities/config';
Expand Down Expand Up @@ -36,7 +35,7 @@ export default class AddCommand extends SchematicCommand {
if (!collectionName) {
throw new SilentError(
`The "ng ${this.name}" command requires a name argument to be specified eg. `
+ `${chalk.yellow('ng add [name] ')}. For more details, use "ng help".`
+ `${terminal.yellow('ng add [name] ')}. For more details, use "ng help".`
);
}

Expand All @@ -49,7 +48,7 @@ export default class AddCommand extends SchematicCommand {
if (!collectionName) {
throw new SilentError(
`The "ng ${this.name}" command requires a name argument to be specified eg. `
+ `${chalk.yellow('ng add [name] ')}. For more details, use "ng help".`
+ `${terminal.yellow('ng add [name] ')}. For more details, use "ng help".`
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@angular/cli/commands/easter-egg.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command, Option } from '../models/command';
import chalk from 'chalk';
import { terminal } from '@angular-devkit/core';

function pickOne(of: string[]): string {
return of[Math.floor(Math.random() * of.length)];
Expand All @@ -23,6 +23,6 @@ export default class AwesomeCommand extends Command {
`I spy with my little eye a great developer!`,
`Noop... already awesome.`
]);
this.logger.info(chalk.green(phrase));
this.logger.info(terminal.green(phrase));
}
}
6 changes: 2 additions & 4 deletions packages/@angular/cli/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { CommandScope, Option } from '../models/command';
import chalk from 'chalk';
import { getDefaultSchematicCollection } from '../utilities/config';
import {
getCollection,
getEngineHost
} from '../utilities/schematics';
import { tags } from '@angular-devkit/core';
import { tags, terminal } from '@angular-devkit/core';
import { SchematicCommand } from '../models/schematic-command';

const { cyan } = chalk;

export default class GenerateCommand extends SchematicCommand {
public readonly name = 'generate';
Expand Down Expand Up @@ -106,7 +104,7 @@ export default class GenerateCommand extends SchematicCommand {
});

this.logger.warn(`\nTo see help for a schematic run:`);
this.logger.info(cyan(` ng generate <schematic> --help`));
this.logger.info(terminal.cyan(` ng generate <schematic> --help`));
}
}
}
5 changes: 2 additions & 3 deletions packages/@angular/cli/commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Command, Option } from '../models/command';
import chalk from 'chalk';
import { terminal } from '@angular-devkit/core';

const { cyan } = chalk;

export default class HelpCommand extends Command {
public readonly name = 'help';
Expand All @@ -23,7 +22,7 @@ export default class HelpCommand extends Command {
}));
this.logger.info(`Available Commands:`);
commands.forEach(cmd => {
this.logger.info(` ${cyan(cmd.name)} ${cmd.description}`);
this.logger.info(` ${terminal.cyan(cmd.name)} ${cmd.description}`);
});

this.logger.info(`\nFor more detailed help run "ng [command name] --help"`);
Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const packageJson = require('../package.json');
const path = require('path');
const resolve = require('resolve');
const stripIndents = require('@angular-devkit/core').tags.stripIndents;
const yellow = require('chalk').yellow;
const yellow = require('@angular-devkit/core').terminal.yellow;
const SemVer = require('semver').SemVer;
const events = require('events');

Expand Down
5 changes: 2 additions & 3 deletions packages/@angular/cli/models/command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { logging } from '@angular-devkit/core';
const { cyan } = require('chalk');
import { logging, terminal } from '@angular-devkit/core';

export interface CommandConstructor {
new(context: CommandContext, logger: logging.Logger): Command;
Expand Down Expand Up @@ -66,7 +65,7 @@ export abstract class Command<T = any> {
const aliases = o.aliases && o.aliases.length > 0
? '(' + o.aliases.map(a => `-${a}`).join(' ') + ')'
: '';
this.logger.info(` ${cyan('--' + o.name)} ${aliases}`);
this.logger.info(` ${terminal.cyan('--' + o.name)} ${aliases}`);
this.logger.info(` ${o.description}`);
});
}
Expand Down
1 change: 0 additions & 1 deletion packages/@angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@angular-devkit/schematics": "0.5.10",
"@schematics/angular": "0.5.10",
"@schematics/update": "0.5.10",
"chalk": "~2.2.0",
"opn": "~5.1.0",
"resolve": "^1.1.7",
"rxjs": "^6.0.0",
Expand Down
10 changes: 4 additions & 6 deletions packages/@angular/cli/tasks/npm-install.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { ModuleNotFoundException, resolve } from '@angular-devkit/core/node';

import chalk from 'chalk';
import { spawn } from 'child_process';
import { logging } from '@angular-devkit/core';
import { logging, terminal } from '@angular-devkit/core';

const SilentError = require('silent-error');

Expand All @@ -22,7 +20,7 @@ export default async function (packageName: string,
packageManager = 'npm';
}

logger.info(chalk.green(`Installing packages for tooling via ${packageManager}.`));
logger.info(terminal.green(`Installing packages for tooling via ${packageManager}.`));

const installArgs: string[] = [];
switch (packageManager) {
Expand Down Expand Up @@ -68,11 +66,11 @@ export default async function (packageName: string,
spawn(packageManager, installArgs, installOptions)
.on('close', (code: number) => {
if (code === 0) {
logger.info(chalk.green(`Installed packages for tooling via ${packageManager}.`));
logger.info(terminal.green(`Installed packages for tooling via ${packageManager}.`));
resolve();
} else {
const message = 'Package install failed, see above.';
logger.info(chalk.red(message));
logger.info(terminal.red(message));
reject(message);
}
});
Expand Down
22 changes: 9 additions & 13 deletions packages/@angular/cli/upgrade/version.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { SemVer, satisfies } from 'semver';
import chalk from 'chalk';
import { tags } from '@angular-devkit/core';
import { tags, terminal } from '@angular-devkit/core';
import * as path from 'path';
import { isWarningEnabled } from '../utilities/config';
import { requireProjectModule } from '../utilities/require-project-module';

const resolve = require('resolve');


const { bold, red, yellow } = chalk;


export class Version {
private _semver: SemVer = null;
constructor(private _version: string = null) {
Expand Down Expand Up @@ -64,14 +60,14 @@ export class Version {
angularPkgJson = requireProjectModule(projectRoot, '@angular/core/package.json');
rxjsPkgJson = requireProjectModule(projectRoot, 'rxjs/package.json');
} catch {
console.error(bold(red(tags.stripIndents`
console.error(terminal.bold(terminal.red(tags.stripIndents`
You seem to not be depending on "@angular/core" and/or "rxjs". This is an error.
`)));
process.exit(2);
}

if (!(angularPkgJson && angularPkgJson['version'] && rxjsPkgJson && rxjsPkgJson['version'])) {
console.error(bold(red(tags.stripIndents`
console.error(terminal.bold(terminal.red(tags.stripIndents`
Cannot determine versions of "@angular/core" and/or "rxjs".
This likely means your local installation is broken. Please reinstall your packages.
`)));
Expand All @@ -82,12 +78,12 @@ export class Version {
let rxjsVersion = new Version(rxjsPkgJson['version']);

if (angularVersion.isLocal()) {
console.warn(yellow('Using a local version of angular. Proceeding with care...'));
console.warn(terminal.yellow('Using a local version of angular. Proceeding with care...'));
return;
}

if (!angularVersion.isGreaterThanOrEqualTo(new SemVer('5.0.0'))) {
console.error(bold(red(tags.stripIndents`
console.error(terminal.bold(terminal.red(tags.stripIndents`
This version of CLI is only compatible with Angular version 5.0.0 or higher.
Please visit the link below to find instructions on how to update Angular.
Expand All @@ -99,7 +95,7 @@ export class Version {
&& !rxjsVersion.isGreaterThanOrEqualTo(new SemVer('5.6.0-forward-compat.0'))
&& !rxjsVersion.isGreaterThanOrEqualTo(new SemVer('6.0.0-beta.0'))
) {
console.error(bold(red(tags.stripIndents`
console.error(terminal.bold(terminal.red(tags.stripIndents`
This project uses version ${rxjsVersion} of RxJs, which is not supported by Angular v6.
The official RxJs version that is supported is 5.6.0-forward-compat.0 and greater.
Expand All @@ -111,7 +107,7 @@ export class Version {
angularVersion.isGreaterThanOrEqualTo(new SemVer('6.0.0-rc.0'))
&& !rxjsVersion.isGreaterThanOrEqualTo(new SemVer('6.0.0-beta.0'))
) {
console.warn(bold(red(tags.stripIndents`
console.warn(terminal.bold(terminal.red(tags.stripIndents`
This project uses a temporary compatibility version of RxJs (${rxjsVersion}).
Please visit the link below to find instructions on how to update RxJs.
Expand All @@ -129,7 +125,7 @@ export class Version {
compilerVersion = requireProjectModule(projectRoot, '@angular/compiler-cli').VERSION.full;
tsVersion = requireProjectModule(projectRoot, 'typescript').version;
} catch {
console.error(bold(red(tags.stripIndents`
console.error(terminal.bold(terminal.red(tags.stripIndents`
Versions of @angular/compiler-cli and typescript could not be determined.
The most common reason for this is a broken npm install.
Expand All @@ -153,7 +149,7 @@ export class Version {

if (currentCombo && !satisfies(tsVersion, currentCombo.typescript)) {
// First line of warning looks weird being split in two, disable tslint for it.
console.log((yellow('\n' + tags.stripIndent`
console.log((terminal.yellow('\n' + tags.stripIndent`
@angular/compiler-cli@${compilerVersion} requires typescript@'${
currentCombo.typescript}' but ${tsVersion} was found instead.
Using this version can result in undefined behaviour and difficult to debug problems.
Expand Down
12 changes: 6 additions & 6 deletions packages/@angular/cli/utilities/check-package-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from 'chalk';
import { terminal } from '@angular-devkit/core';
import { exec } from 'child_process';
import { promisify } from 'util';
import { getPackageManager } from './config';
Expand All @@ -19,16 +19,16 @@ export function checkYarnOrCNPM() {
.then((data: Array<boolean>) => {
const [isYarnInstalled, isCNPMInstalled] = data;
if (isYarnInstalled && isCNPMInstalled) {
console.log(chalk.yellow('You can `ng config -g cli.packageManager yarn` '
console.log(terminal.yellow('You can `ng config -g cli.packageManager yarn` '
+ 'or `ng config -g cli.packageManager cnpm`.'));
} else if (isYarnInstalled) {
console.log(chalk.yellow('You can `ng config -g cli.packageManager yarn`.'));
console.log(terminal.yellow('You can `ng config -g cli.packageManager yarn`.'));
} else if (isCNPMInstalled) {
console.log(chalk.yellow('You can `ng config -g cli.packageManager cnpm`.'));
console.log(terminal.yellow('You can `ng config -g cli.packageManager cnpm`.'));
} else {
if (packageManager !== 'default' && packageManager !== 'npm') {
console.log(chalk.yellow(`Seems that ${packageManager} is not installed.`));
console.log(chalk.yellow('You can `ng config -g cli.packageManager npm`.'));
console.log(terminal.yellow(`Seems that ${packageManager} is not installed.`));
console.log(terminal.yellow('You can `ng config -g cli.packageManager npm`.'));
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion scripts/git-builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const spawnSync = require( 'child_process').spawnSync;
const fs = require('fs');
const temp = require('temp');
const { blue, green, gray } = require('chalk');
const { blue, green, gray } = require('@angular-devkit/core').terminal;

const path = require('path');
const glob = require('glob');
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/* eslint-disable no-console */
const { packages } = require('../../lib/packages');
const { yellow } = require('chalk');
const { yellow } = require('@angular-devkit/core').terminal;
const fs = require('fs');
const http = require('http');
const path = require('path');
Expand Down
16 changes: 8 additions & 8 deletions scripts/publish/validate_dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

/* eslint-disable no-console */
const chalk = require('chalk');
const terminal = require('@angular-devkit/core').terminal;
const fs = require('fs');
const glob = require('glob');
const packages = require('../../lib/packages').packages;
Expand Down Expand Up @@ -70,19 +70,19 @@ function listIgnoredModules(source) {

function reportMissingDependencies(missingDeps) {
if (missingDeps.length == 0) {
console.log(chalk.green(' no dependency missing from package.json.'));
console.log(terminal.green(' no dependency missing from package.json.'));
} else {
console.log(chalk.yellow(` ${missingDeps.length} missing from package.json:`));
console.log(terminal.yellow(` ${missingDeps.length} missing from package.json:`));
missingDeps.forEach(md => console.log(` ${md}`));
exitCode = 1;
}
}

function reportExcessiveDependencies(overDeps) {
if (overDeps.length == 0) {
console.log(chalk.green(' no excessive dependencies in package.json.'));
console.log(terminal.green(' no excessive dependencies in package.json.'));
} else {
console.log(chalk.yellow(` ${overDeps.length} excessive dependencies in package.json:`));
console.log(terminal.yellow(` ${overDeps.length} excessive dependencies in package.json:`));
overDeps.forEach(md => console.log(` ${md}`));
exitCode = 1;
}
Expand All @@ -91,7 +91,7 @@ function reportExcessiveDependencies(overDeps) {
let exitCode = 0;
const overallDeps = [];
for (const packageName of Object.keys(packages)) {
console.log(chalk.green(`Reading dependencies of "${packageName}".`));
console.log(terminal.green(`Reading dependencies of "${packageName}".`));

const allSources = glob.sync(path.join(__dirname, '../../packages/', packageName, '**/*'))
.filter(p => p.match(/\.(js|ts)$/))
Expand All @@ -117,7 +117,7 @@ for (const packageName of Object.keys(packages)) {
.filter(x => NODE_PACKAGES.indexOf(x) == -1);
overallDeps.push(...dependencies);

console.log(chalk.green(` found ${dependencies.length} dependencies...`));
console.log(terminal.green(` found ${dependencies.length} dependencies...`));
const packageJson = JSON.parse(fs.readFileSync(packages[packageName].packageJson, 'utf8'));
const allDeps = []
.concat(Object.keys(packageJson['dependencies'] || {}))
Expand All @@ -136,7 +136,7 @@ for (const packageName of Object.keys(packages)) {
console.log('');
}

console.log(chalk.green('Validating root package. [devDependencies ignored]'));
console.log(terminal.green('Validating root package. [devDependencies ignored]'));
const rootPackagePath = path.join(__dirname, '../../package.json');
const rootPackageJson = JSON.parse(fs.readFileSync(rootPackagePath, 'utf8'));
// devDependencies are ignored
Expand Down
13 changes: 6 additions & 7 deletions scripts/test-commit-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ require('../lib/bootstrap-local');

const validateCommitMessage = require('./validate-commit-message');
const execSync = require('child_process').execSync;
const chalk = require('chalk');
const { logging } = require('@angular-devkit/core');
const { logging, terminal } = require('@angular-devkit/core');
const Logger = logging.Logger;
const filter = require('rxjs/operators').filter;

// Configure logger
const logger = new Logger('test-commit-messages');

logger.subscribe((entry) => {
let color = chalk.white;
let color = terminal.white;
let output = process.stdout;
switch (entry.level) {
case 'info': color = chalk.white; break;
case 'warn': color = chalk.yellow; break;
case 'error': color = chalk.red; output = process.stderr; break;
case 'fatal': color = (x) => chalk.bold(chalk.red(x)); output = process.stderr; break;
case 'info': color = terminal.white; break;
case 'warn': color = terminal.yellow; break;
case 'error': color = terminal.red; output = process.stderr; break;
case 'fatal': color = (x) => terminal.bold(terminal.red(x)); output = process.stderr; break;
}

output.write(color(entry.message) + '\n');
Expand Down

0 comments on commit ceeb292

Please sign in to comment.