How to use the @ngrx/store-devtools/schematics-core.addImportToModule function in @ngrx/store-devtools

To help you get started, we’ve selected a few @ngrx/store-devtools 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 ngrx / platform / modules / store-devtools / schematics / ng-add / index.ts View on Github external
}

    const text = host.read(modulePath);
    if (text === null) {
      throw new SchematicsException(`File ${modulePath} does not exist.`);
    }
    const sourceText = text.toString('utf-8');

    const source = ts.createSourceFile(
      modulePath,
      sourceText,
      ts.ScriptTarget.Latest,
      true
    );

    const [instrumentNgModuleImport] = addImportToModule(
      source,
      modulePath,
      `StoreDevtoolsModule.instrument({ maxAge: ${
        options.maxAge
      }, logOnly: environment.production })`,
      modulePath
    );

    const srcPath = dirname(options.path as Path);
    const environmentsPath = buildRelativePath(
      modulePath,
      `/${srcPath}/environments/environment`
    );

    const changes = [
      insertImport(
github ngrx / store-devtools-builds / schematics / ng-add / index.js View on Github external
return (host) => {
            const modulePath = options.module;
            if (!modulePath) {
                return host;
            }
            if (!host.exists(modulePath)) {
                throw new Error('Specified module does not exist');
            }
            const text = host.read(modulePath);
            if (text === null) {
                throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
            }
            const sourceText = text.toString('utf-8');
            const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
            const [instrumentNgModuleImport] = schematics_core_1.addImportToModule(source, modulePath, `StoreDevtoolsModule.instrument({ maxAge: ${options.maxAge}, logOnly: environment.production })`, modulePath);
            const srcPath = core_1.dirname(options.path);
            const environmentsPath = schematics_core_1.buildRelativePath(modulePath, `/${srcPath}/environments/environment`);
            const changes = [
                schematics_core_1.insertImport(source, modulePath, 'StoreDevtoolsModule', '@ngrx/store-devtools'),
                schematics_core_1.insertImport(source, modulePath, 'environment', environmentsPath),
                instrumentNgModuleImport,
            ];
            const recorder = host.beginUpdate(modulePath);
            for (const change of changes) {
                if (change instanceof schematics_core_1.InsertChange) {
                    recorder.insertLeft(change.pos, change.toAdd);
                }
            }
            host.commitUpdate(recorder);
            return host;
        };