Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let isDirectory = false;
try {
isDirectory = host.isDirectory(resolvedAssetPath);
} catch {
isDirectory = true;
}
if (isDirectory) {
// Folders get a recursive star glob.
glob = '**/*';
// Input directory is their original path.
input = assetPath;
} else {
// Files are their own glob.
glob = basename(assetPath);
// Input directory is their original dirname.
input = dirname(assetPath);
}
// Output directory for both is the relative path from source root to input.
output = relative(resolvedSourceRoot, resolve(root, input));
// Return the asset pattern in object format.
return { glob, input, output };
} else {
// It's already an AssetPatternObject, no need to convert.
return assetPattern;
}
});
}
function getAssetsParts(resolvedAssetPath: Path, assetPath: Path) {
if (isDirectory(resolvedAssetPath)) {
return {
glob: '**/*', // Folders get a recursive star glob.
input: assetPath, // Input directory is their original path.
};
}
return {
glob: basename(assetPath), // Files are their own glob.
input: dirname(assetPath), // Input directory is their original dirname.
};
}
return extraEntryPoints.map(entry => {
let normalizedEntry;
if (typeof entry === 'string') {
normalizedEntry = { input: entry, lazy: false, bundleName: defaultBundleName };
}
else {
let bundleName;
if (entry.bundleName) {
bundleName = entry.bundleName;
}
else if (entry.lazy) {
// Lazy entry points use the file name as bundle name.
bundleName = core_1.basename(core_1.normalize(entry.input.replace(/\.(js|css|scss|sass|less|styl)$/i, '')));
}
else {
bundleName = defaultBundleName;
}
normalizedEntry = Object.assign({}, entry, { bundleName });
}
return normalizedEntry;
});
}
function getAssetsParts(resolvedAssetPath: Path, assetPath: Path) {
if (isDirectory(resolvedAssetPath)) {
return {
glob: '**/*', // Folders get a recursive star glob.
input: assetPath, // Input directory is their original path.
};
}
return {
glob: basename(assetPath), // Files are their own glob.
input: dirname(assetPath), // Input directory is their original dirname.
};
}
export function importPath(from: Path, to: Path): string {
const relativePath = relative(dirname(from), dirname(to));
if (relativePath.startsWith('.')) {
return relativePath;
}
if (!relativePath) {
return generateCurrentDirImport(basename(to));
}
return generateCurrentDirImport(join(relativePath, basename(to)));
}
return (host, context) => {
const clientProject = project_1.getProject(host, options.clientProject);
if (clientProject.projectType !== 'application') {
throw new schematics_1.SchematicsException(`Universal requires a project type of "application".`);
}
const clientTargets = project_targets_1.getProjectTargets(clientProject);
const outDir = getTsConfigOutDir(host, clientTargets);
if (!clientTargets.build) {
throw project_targets_1.targetBuildNotFoundError();
}
const tsConfigExtends = core_1.basename(core_1.normalize(clientTargets.build.options.tsConfig));
const rootInSrc = clientProject.root === '';
const tsConfigDirectory = core_1.join(core_1.normalize(clientProject.root), rootInSrc ? 'src' : '');
if (!options.skipInstall) {
context.addTask(new tasks_1.NodePackageInstallTask());
}
const templateSource = schematics_1.apply(schematics_1.url('./files/src'), [
schematics_1.template(Object.assign({}, core_1.strings, options, { stripTsExtension: (s) => s.replace(/\.ts$/, '') })),
schematics_1.move(core_1.join(core_1.normalize(clientProject.root), 'src')),
]);
const rootSource = schematics_1.apply(schematics_1.url('./files/root'), [
schematics_1.template(Object.assign({}, core_1.strings, options, { stripTsExtension: (s) => s.replace(/\.ts$/, ''), outDir,
tsConfigExtends,
rootInSrc })),
schematics_1.move(tsConfigDirectory),
]);
return schematics_1.chain([
public nameParser(options: ParseOptions): Location {
const nameWithoutPath: string = basename(options.name as Path);
const namePath: string = dirname((options.path === undefined ? '' : options.path)
.concat('/')
.concat(options.name) as Path);
return {
name: nameWithoutPath,
path: normalize('/'.concat(namePath))
};
}
export function parseName(path: string, name: string): Location {
const nameWithoutPath = basename(normalize(name));
const namePath = dirname(join(normalize(path), name) as Path);
return {
name: nameWithoutPath,
path: normalize('/' + namePath),
};
}
export function main(options: IControllerOptions): Rule {
const name = strings.dasherize(basename(options.name as Path));
const fullName = strings.dasherize(join(dirname(options.name as Path), pluralize.plural(name)));
const projectPath = options.path || '.';
const path: Path = strings.dasherize(normalize(join(projectPath as Path, 'src/app', options.name, '..'))) as Path;
return chain([
mergeWith(
apply(url('./files'), [
options.spec ? noop() : filter(p => !p.endsWith('.spec.ts')),
template({
...strings,
name,
fullName,
}),
move(path),
formatTsFiles(),
]),
return (host, context) => {
const clientProject = getClientProject(host, options);
if (clientProject.projectType !== 'application') {
throw new schematics_1.SchematicsException(`Universal requires a project type of "application".`);
}
const clientArchitect = getClientArchitect(host, options);
const outDir = getTsConfigOutDir(host, clientArchitect);
const tsConfigExtends = core_1.basename(clientArchitect.build.options.tsConfig);
const rootInSrc = clientProject.root === '';
const tsConfigDirectory = core_1.join(core_1.normalize(clientProject.root), rootInSrc ? 'src' : '');
if (!options.skipInstall) {
context.addTask(new tasks_1.NodePackageInstallTask());
}
const templateSource = schematics_1.apply(schematics_1.url('./files/src'), [
schematics_1.template(Object.assign({}, core_1.strings, options, { stripTsExtension: (s) => { return s.replace(/\.ts$/, ''); } })),
schematics_1.move(core_1.join(core_1.normalize(clientProject.root), 'src')),
]);
const rootSource = schematics_1.apply(schematics_1.url('./files/root'), [
schematics_1.template(Object.assign({}, core_1.strings, options, { stripTsExtension: (s) => { return s.replace(/\.ts$/, ''); }, outDir,
tsConfigExtends,
rootInSrc })),
schematics_1.move(tsConfigDirectory),
]);
return schematics_1.chain([