How to use the @angular-devkit/schematics.SchematicsException function in @angular-devkit/schematics

To help you get started, we’ve selected a few @angular-devkit/schematics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github martinroob / ngx-i18nsupport / projects / tooling / src / schematics / src / addLanguage / index.ts View on Github external
} else {
        if (!optionsFromCommandline.languages) {
            options.parsedLanguages = [];
        } else {
            options.parsedLanguages = optionsFromCommandline.languages.split(',');
        }
    }
    if (options.parsedLanguages.length === 0) {
        const msg = 'At least 1 language must be specified.';
        context.logger.fatal(msg);
        throw new SchematicsException(msg);
    }
    if (options.parsedLanguages.indexOf(options.i18nLocale) >= 0) {
        const msg = `Language "${options.i18nLocale}" is already configured (as default language).`;
        context.logger.fatal(msg);
        throw new SchematicsException(msg);
    }
    options.configuredLanguages = xliffmergeOptions.xliffmergeOptions.languages ? xliffmergeOptions.xliffmergeOptions.languages : [];
    // check languages
    for (const lang of options.parsedLanguages) {
        if (options.configuredLanguages.indexOf(lang) >= 0) {
            const msg = `Language "${lang}" is already configured.`;
            context.logger.fatal(msg);
            throw new SchematicsException(msg);
        }
    }
    for (const lang of options.parsedLanguages) {
        if (!isValidLanguageSyntax(lang)) {
            const msg = `"${lang}" is not a valid language code.`;
            context.logger.fatal(msg);
            throw new SchematicsException(msg);
        }
github positive-js / mosaic / packages / cdk / schematics / utils / project-targets.ts View on Github external
project.targets[buildTarget] &&
        project.targets[buildTarget].options) {

        return project.targets[buildTarget].options;
    }

    // over to `targets`, and the `architect` support has been removed.
    // See: https://github.com/angular/angular-cli/commit/307160806cb48c95ecb8982854f452303801ac9f
    if (project.architect &&
        project.architect[buildTarget] &&
        project.architect[buildTarget].options) {

        return project.architect[buildTarget].options;
    }

    throw new SchematicsException(
        `Cannot determine project target configuration for: ${buildTarget}.`);
}
github rxweb / rxweb / rxweb.io / node_modules / @schematics / update / update / index.js View on Github external
function _performUpdate(tree, context, infoMap, logger, migrateOnly) {
    const packageJsonContent = tree.read('/package.json');
    if (!packageJsonContent) {
        throw new schematics_1.SchematicsException('Could not find a package.json. Are you in a Node project?');
    }
    let packageJson;
    try {
        packageJson = JSON.parse(packageJsonContent.toString());
    }
    catch (e) {
        throw new schematics_1.SchematicsException('package.json could not be parsed: ' + e.message);
    }
    const updateDependency = (deps, name, newVersion) => {
        const oldVersion = deps[name];
        // We only respect caret and tilde ranges on update.
        const execResult = /^[\^~]/.exec(oldVersion);
        deps[name] = `${execResult ? execResult[0] : ''}${newVersion}`;
    };
    const toInstall = [...infoMap.values()]
        .map(x => [x.name, x.target, x.installed])
github angular / components / src / cdk / schematics / utils / version-agnostic-typescript.ts View on Github external
*/
let ts: typeof typescript;

try {
  ts = require('@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript');
} catch {
  // Fallback for CLI versions before v8.0.0. The TypeScript dependency has been dropped in
  // CLI version v8.0.0 but older CLI versions can still run the latest generation schematics.
  // See: https://github.com/angular/angular-cli/commit/bf1c069f73c8e3d4f0e8d584cbfb47c408c1730b
  try {
    ts = require('@schematics/angular/node_modules/typescript');
  } catch {
    try {
      ts = require('typescript');
    } catch {
      throw new SchematicsException(
          'Error: Could not find a TypeScript version for the ' +
          'schematics. Please report an issue on the Angular Material repository.');
    }
  }
}

export {ts, typescript};
github nstudio / xplat / packages / nativescript-angular / src / schematics / application / index.ts View on Github external
export default function(options: Schema) {
  if (!options.name) {
    throw new SchematicsException(
      missingArgument(
        'name',
        'Provide a name for your NativeScript app.',
        'nx g @nstudio/nativescript-angular:app name'
      )
    );
  }
  if (options.setupSandbox) {
    // always setup routing with sandbox
    options.routing = true;
  }

  return chain([
    prerun(options),
    // adjust naming convention
    XplatHelpers.applyAppNamingConvention(options, 'nativescript'),
github nrwl / nx / packages / storybook / src / utils / utils.ts View on Github external
export function getJsonFile(tree: Tree, path: string): JsonAstObject {
  const buffer = tree.read(path);
  if (buffer === null) {
    throw new SchematicsException(`Could not read JSON file (${path}).`);
  }
  const content = buffer.toString();

  const packageJson = parseJsonAst(content, JsonParseMode.Strict);
  if (packageJson.kind !== 'object') {
    throw new SchematicsException('Invalid JSON file. Was expecting an object');
  }

  return packageJson;
}
github martinroob / ngx-i18nsupport / projects / tooling / src / schematics / src / common / package-json-snapshot.ts View on Github external
private readPackageJson(): IPackageJson {
        const packageJsonPath = `${this._path}/package.json`;
        const content = this.host.read(packageJsonPath);
        if (!content) {
            throw new SchematicsException(`${packageJsonPath} does not exist`);
        }
        const contentString = content.toString('UTF-8');
        return JSON.parse(contentString) as IPackageJson;
    }
}
github briebug / jest-schematic / src / utility / util.ts View on Github external
export function parseJsonAtPath(tree: Tree, path: string): JsonAstObject {
  const buffer = tree.read(path);

  if (buffer === null) {
    throw new SchematicsException('Could not read package.json.');
  }

  const content = buffer.toString();

  const json = parseJsonAst(content, JsonParseMode.Strict);
  if (json.kind != 'object') {
    throw new SchematicsException(
      'Invalid package.json. Was expecting an object'
    );
  }

  return json;
}
github johandb / svg-drawing-tool / node_modules / @schematics / update / update / index.js View on Github external
let peerErrors = false;
    infoMap.forEach(info => {
        const { name, target } = info;
        if (!target) {
            return;
        }
        const pkgLogger = logger.createChild(name);
        logger.debug(`${name}...`);
        const peers = target.packageJson.peerDependencies || {};
        peerErrors = _validateForwardPeerDependencies(name, infoMap, peers, pkgLogger) || peerErrors;
        peerErrors
            = _validateReversePeerDependencies(name, target.version, infoMap, pkgLogger)
                || peerErrors;
    });
    if (!force && peerErrors) {
        throw new schematics_1.SchematicsException(`Incompatible peer dependencies found. See above.`);
    }
}
function _performUpdate(tree, context, infoMap, logger, migrateOnly) {