Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
reject(code);
}
});
});
};
const hasCommand = await execute(['--version'])
.then(() => true, () => false);
if (!hasCommand) {
return;
}
const insideRepo = await execute(['rev-parse', '--is-inside-work-tree'], true)
.then(() => true, () => false);
if (insideRepo) {
context.logger.info(tags.oneLine`
Directory is already under version control.
Skipping initialization of git.
`);
return;
}
// if git is not found or an error was thrown during the `git`
// init process just swallow any errors here
// NOTE: This will be removed once task error handling is implemented
try {
await execute(['init']);
await execute(['add', '.']);
if (options.commit) {
const message = options.message || 'initial commit';
it('should not do anything if shouldTransform returns false', () => {
const input = tags.stripIndent`
export { AppModule } from './app/app.module';
`;
const transformer = exportNgFactory(
() => false,
() => ({ path: '/project/src/app/app.module', className: 'AppModule' }),
);
const result = transformTypescript(input, [transformer]);
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${input}`);
});
});
it('replaces wrapped __extends', () => {
const input = tags.stripIndent`
export default function appGlobal() {
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
}
`;
const output = tags.stripIndent`
import { __extends } from "tslib";
export default function appGlobal() { }
`;
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
});
logger.warn(
`ERROR! ${eventPath} ${
event.description == 'alreadyExist'
? 'already exists'
: 'does not exist.'
}.`
);
} else if (event.kind === 'update') {
record.loggingQueue.push(
tags.oneLine`${terminal.white('UPDATE')} ${eventPath} (${
event.content.length
} bytes)`
);
} else if (event.kind === 'create') {
record.loggingQueue.push(
tags.oneLine`${terminal.green('CREATE')} ${eventPath} (${
event.content.length
} bytes)`
);
} else if (event.kind === 'delete') {
record.loggingQueue.push(`${terminal.yellow('DELETE')} ${eventPath}`);
} else if (event.kind === 'rename') {
record.loggingQueue.push(
`${terminal.blue('RENAME')} ${eventPath} => ${event.to}`
);
}
};
}
export function validateProjectName(projectName: string) {
const errorIndex = getRegExpFailPosition(projectName);
if (errorIndex !== null) {
const firstMessage = tags.oneLine`
Project name "${projectName}" is not valid. New project names must
start with a letter, and must contain only alphanumeric characters or dashes.
When adding a dash the segment after the dash must also start with a letter.
`;
const msg = tags.stripIndent`
${firstMessage}
${projectName}
${Array(errorIndex + 1).join(' ') + '^'}
`;
throw new SilentError(msg);
} else if (unsupportedProjectNames.indexOf(projectName) !== -1) {
throw new SilentError(`Project name "${projectName}" is not a supported name.`);
}
}
const getProjectName = () => {
if (this._workspace) {
const projectNames = getProjectsByPath(this._workspace, process.cwd(), this.workspace.root);
if (projectNames.length === 1) {
return projectNames[0];
} else {
if (projectNames.length > 1) {
this.logger.warn(tags.oneLine`
Two or more projects are using identical roots.
Unable to determine project using current working directory.
Using default workspace project instead.
`);
}
const defaultProjectName = this._workspace.extensions['defaultProject'];
if (typeof defaultProjectName === 'string' && defaultProjectName) {
return defaultProjectName;
}
}
}
return undefined;
};
${clazz}
Clazz.propDecorators = {
'notNgIf': [{ type: NotInput }]
};
`;
const input = tags.stripIndent`
import { Input } from '@angular/core';
import { NotInput } from 'another-lib';
${clazz}
Clazz.propDecorators = {
'ngIf': [{ type: Input }],
'notNgIf': [{ type: NotInput }]
};
`;
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
});
});
collectionName: string,
options: string[] = [],
): Promise {
const runOptions: RunSchematicOptions = {
schematicOptions: options,
collectionName,
schematicName: 'ng-add',
dryRun: false,
force: false,
};
try {
return await this.runSchematic(runOptions);
} catch (e) {
if (e instanceof NodePackageDoesNotSupportSchematics) {
this.logger.error(tags.oneLine`
The package that you are trying to add does not support schematics. You can try using
a different version of the package or contact the package author to add ng-add support.
`);
return 1;
}
throw e;
}
}
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
`;
const transformer = registerLocaleData(() => true, () => null, 'fr');
const result = transformTypescript(input, [transformer]);
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${input}`);
});
});
export function Warning(message: string) {
return tags.oneLine` ${color.bgYellow(color.black('WARNING'))} ${message}`;
}