Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (tree.exists(componentPath)) {
console.log(`${componentClassName} file found at: ${componentPath}`);
} else {
throw new SchematicsException(`Cannot locate Component ${componentClassName} at: ${componentPath}`);
}
} else {
console.log(`Trying to deduct ${componentClassName} location following Angular best practices`);
const fileName = `${dasherize(options.name)}.component.ts`;
const app = join(projectSettings.sourceRoot, 'app');
// search at src/app/file-name
if (tree.exists(join(app, fileName))) {
componentPath = join(app, fileName);
} else if (tree.exists(join(app, dasherize(options.name), fileName))) {
componentPath = join(app, dasherize(options.name), fileName);
} else {
throw new SchematicsException(`Couldn't find component's .ts file.
You can use --component-path parameter to provide the path to the component.
Hint. don't include src/app with --component-path`);
}
}
return componentPath;
};
componentPath = projectSettings.tsResolver(componentImportPath, modulePath);
if (!componentPath.endsWith('.ts')) {
componentPath = componentPath + '.ts';
}
if (tree.exists(componentPath)) {
console.log(`${componentClassName} file found at: ${componentPath}`);
} else {
throw new SchematicsException(`Cannot locate Component ${componentClassName} at: ${componentPath}`);
}
} else {
console.log(`Trying to deduct ${componentClassName} location following Angular best practices`);
const fileName = `${dasherize(options.name)}.component.ts`;
const app = join(projectSettings.sourceRoot, 'app');
// search at src/app/file-name
if (tree.exists(join(app, fileName))) {
componentPath = join(app, fileName);
} else if (tree.exists(join(app, dasherize(options.name), fileName))) {
componentPath = join(app, dasherize(options.name), fileName);
} else {
throw new SchematicsException(`Couldn't find component's .ts file.
You can use --component-path parameter to provide the path to the component.
Hint. don't include src/app with --component-path`);
}
}
return componentPath;
};
const generateTemplate = (options: MasterDetailSchema) => (tree: Tree, context: SchematicContext) => {
context.logger.info('Generating Master Detail template');
context.logger.info(`Project Params: ${JSON.stringify(projectParams, null, 2)}`);
const templateOptions = {
prefix: 'app', // options.prefix,
name: dasherize(options.master),
master: dasherize(options.master),
detail: dasherize(options.detail),
masterClassName: classify(options.master),
detailClassName: classify(options.detail),
nsext: projectParams.nsext,
};
const templatePath = projectParams.shared ? './_files-shared' : './_files-nsonly';
const templateSource = apply(
url(templatePath), [
template(templateOptions),
move(projectParams.appPath),
]);
return mergeWith(templateSource);
const dest = ({ name, sourceDir, path, flat }: ModuleOptions) =>
`${sourceDir}/${path}/${flat ? '' : dasherize(name)}`;
const getModuleBasename = (options: ModuleOptions) =>
const parseComponentInfo = (tree: Tree, options: ComponentOptions): ComponentInfo => {
const component = new ComponentInfo();
const parsedPath = parseName(options.path || '', options.name);
component.name = dasherize(parsedPath.name);
const getGeneratedFilePath = (searchPath: string) => {
const action = tree.actions.find(({ path }) => path.endsWith(searchPath));
if (!action) {
throw new SchematicsException(
`Failed to find generated component file ${searchPath}. ` +
`Please contact the @nativescript/schematics author.`);
}
return action.path;
};
const className = `/${component.name}.component.ts`;
component.classPath = getGeneratedFilePath(className);
const templateName = `/${component.name}.component.html`;
function applyDefaults(parsedArguments: ParsedArguments): PackageNamesConfig {
const { prefix } = parsedArguments;
const config = {
prefix,
unscopedPrefix: prefix.replace(/^@/, ''),
unprefixed: {},
};
for (const nbPackageName of NEBULAR_PACKAGES) {
const packageName = parsedArguments[nbPackageName] || dasherize(nbPackageName);
config.unprefixed[nbPackageName] = packageName;
config[nbPackageName] = `${prefix}/${packageName}`;
}
return config as PackageNamesConfig;
}
const getParsedName = (options: ModuleOptions): { name: string, moduleName: string, routingName: string } => {
const parsedPath = parseName(options.path || '', options.name);
const name = dasherize(parsedPath.name);
return {
name,
moduleName: `/${name}.module.ts`,
routingName: `/${name}-routing.module.ts`,
};
};
public async handle(inputs: Input[], options: Input[]) {
const dryRunOption = options.find(option => option.name === 'dry-run');
const isDryRunEnabled = dryRunOption && dryRunOption.value;
await askForMissingInformation(inputs);
await generateApplicationFiles(inputs, options).catch(exit);
const shouldSkipInstall = options.some(
option => option.name === 'skip-install' && option.value === true,
);
const shouldSkipGit = options.some(
option => option.name === 'skip-git' && option.value === true,
);
const projectDirectory = dasherize(
getApplicationNameInput(inputs)!.value as string,
);
if (!shouldSkipInstall) {
await installPackages(
options,
isDryRunEnabled as boolean,
projectDirectory,
);
}
if (!isDryRunEnabled) {
if (!shouldSkipGit) {
await initializeGitRepository(projectDirectory);
await createGitIgnoreFile(projectDirectory);
}
function setOptionsValue(target, defaultSourceRoot: string) {
target.path =
target.path !== undefined
? join(normalize(defaultSourceRoot), target.path)
: normalize(defaultSourceRoot);
if (target.name) {
const location: Location = new Parser().nameParser(target);
target.name = strings.dasherize(location.name);
target.path = join(strings.dasherize(location.path) as Path, target.name);
}
return target;
}