Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function createFileSystemTestApp(runner: SchematicTestRunner) {
const tempFileSystemHost = new TempScopedNodeJsSyncHost();
const hostTree = new HostTree(tempFileSystemHost);
const appTree: UnitTestTree = await createTestApp(runner, {name: 'cdk-testing'}, hostTree);
const tempPath = getSystemPath(tempFileSystemHost.root);
// Since the TypeScript compiler API expects all files to be present on the real file system, we
// map every file in the app tree to a temporary location on the file system.
appTree.files.forEach(f => writeFile(f, appTree.readContent(f)));
return {
appTree,
tempFileSystemHost,
tempPath,
writeFile,
removeTempDir: () => removeSync(tempPath),
};
function writeFile(filePath: string, content: string) {
} 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);
}
const project = getProject(host, id);
if (options.path === undefined) {
options.path = buildDefaultPath(project);
}
options.module = findModuleFromOptions(host, options);
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
validateName(options.name);
console.log(options);
const templateSource = apply(url('./_files'), [
template({
...strings,
...options,
}),
// move(parsedPath.path),
]);
const rule = chain([branchAndMerge(chain([mergeWith(templateSource)]))]);
return rule(host, context);
};
}
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
validateName(options.name);
console.log(options);
const templateSource = apply(url('./_files'), [
template({
...strings,
...options,
}),
// move(parsedPath.path),
]);
const rule = chain([branchAndMerge(chain([mergeWith(templateSource)]))]);
return rule(host, context);
};
}
it('works with template files exclusively', done => {
const tree = new UnitTestTree(new HostTree());
tree.create('a/b/file1', 'hello world');
tree.create('a/b/file2', 'hello world');
tree.create('a/b/file3.template', 'hello <%= 1 %> world');
tree.create('a/b/file__a__.template', 'hello <%= 1 %> world');
tree.create('a/b/file__norename__', 'hello <%= 1 %> world');
tree.create('a/c/file4', 'hello world');
const context: SchematicContext = {
strategy: MergeStrategy.Default,
} as SchematicContext;
// Rename all files that contain 'b' to 'hello'.
callRule(applyTemplates({ a: 'foo' }), observableOf(tree), context)
.toPromise()
.then(() => {
expect([...tree.files].sort()).toEqual([
describe('@schematics/update', () => {
const schematicRunner = new SchematicTestRunner(
'@schematics/update',
require.resolve('../collection.json'),
);
let host: virtualFs.test.TestHost;
let appTree: UnitTestTree = new UnitTestTree(new HostTree());
beforeEach(() => {
host = new virtualFs.test.TestHost({
'/package.json': `{
"name": "blah",
"dependencies": {
"@angular-devkit-tests/update-base": "1.0.0"
}
}`,
});
appTree = new UnitTestTree(new HostTree(host));
});
it('updates package.json', done => {
// Since we cannot run tasks in unit tests, we need to validate that the default
// update schematic updates the package.json appropriately, AND validate that the
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}.`);
}
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])
*/
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};
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'),