Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function updateJsonFile(
host: Tree,
path: string,
callback: UpdateJsonFn,
): Tree {
const source = host.read(path);
if (source) {
const sourceText = source.toString('utf-8');
const json = parseJson(sourceText);
callback((json as {}) as T);
host.overwrite(path, JSON.stringify(json, null, 2));
}
return host;
}
function readJsonFile(path) {
return core_1.parseJson(readFile(path), core_1.JsonParseMode.Loose);
}
exports.readJsonFile = readJsonFile;
export function getWorkspace(host: Tree): WorkspaceSchema {
const path = getWorkspacePath(host);
const configBuffer = host.read(path);
if (configBuffer === null) {
throw new SchematicsException(`Could not find (${path})`);
}
const content = configBuffer.toString();
return (parseJson(content, JsonParseMode.Loose) as {}) as WorkspaceSchema;
}
function migrateLegacyGlobalConfig() {
const homeDir = os.homedir();
if (homeDir) {
const legacyGlobalConfigPath = path.join(homeDir, '.angular-cli.json');
if (fs_1.existsSync(legacyGlobalConfigPath)) {
const content = fs_1.readFileSync(legacyGlobalConfigPath, 'utf-8');
const legacy = core_1.parseJson(content, core_1.JsonParseMode.Loose);
if (!legacy || typeof legacy != 'object' || Array.isArray(legacy)) {
return false;
}
const cli = {};
if (legacy.packageManager && typeof legacy.packageManager == 'string'
&& legacy.packageManager !== 'default') {
cli['packageManager'] = legacy.packageManager;
}
if (legacy.defaults && typeof legacy.defaults == 'object' && !Array.isArray(legacy.defaults)
&& legacy.defaults.schematics && typeof legacy.defaults.schematics == 'object'
&& !Array.isArray(legacy.defaults.schematics)
&& typeof legacy.defaults.schematics.collection == 'string') {
cli['defaultCollection'] = legacy.defaults.schematics.collection;
}
if (legacy.warnings && typeof legacy.warnings == 'object'
&& !Array.isArray(legacy.warnings)) {
private getIvyWorkspace(): string {
try {
const content = fs.readFileSync(path.resolve(this.workspace.root, 'tsconfig.json'), 'utf-8');
const tsConfig = parseJson(content, JsonParseMode.Loose);
if (!isJsonObject(tsConfig)) {
return '';
}
const { angularCompilerOptions } = tsConfig;
return isJsonObject(angularCompilerOptions) && angularCompilerOptions.enableIvy === false
? 'No'
: 'Yes';
} catch {
return '';
}
}
}
function updateJsonFile(
host: Tree,
path: string,
callback: UpdateJsonFn,
): Tree {
const source = host.read(path);
if (source) {
const sourceText = source.toString('utf-8');
const json = parseJson(sourceText);
callback((json as {}) as T);
host.overwrite(path, JSON.stringify(json, null, 2));
}
return host;
}
function getTsConfigOutDir(host, targets) {
const tsConfigPath = targets.build.options.tsConfig;
const tsConfigBuffer = host.read(tsConfigPath);
if (!tsConfigBuffer) {
throw new schematics_1.SchematicsException(`Could not read ${tsConfigPath}`);
}
const tsConfigContent = tsConfigBuffer.toString();
const tsConfig = core_1.parseJson(tsConfigContent);
if (tsConfig === null || typeof tsConfig !== 'object' || Array.isArray(tsConfig) ||
tsConfig.compilerOptions === null || typeof tsConfig.compilerOptions !== 'object' ||
Array.isArray(tsConfig.compilerOptions)) {
throw new schematics_1.SchematicsException(`Invalid tsconfig - ${tsConfigPath}`);
}
const outDir = tsConfig.compilerOptions.outDir;
return outDir;
}
function default_1(options) {
function getWorkspace(
host: Tree
): { path: string; workspace: experimental.workspace.WorkspaceSchema } {
const possibleFiles = ['/angular.json', '/.angular.json'];
const path = possibleFiles.filter(path => host.exists(path))[0];
const configBuffer = host.read(path);
if (configBuffer === null) {
throw new SchematicsException(`Could not find angular.json`);
}
const content = configBuffer.toString();
let workspace: experimental.workspace.WorkspaceSchema;
try {
workspace = (parseJson(
content,
JsonParseMode.Loose
) as {}) as experimental.workspace.WorkspaceSchema;
} catch (e) {
throw new SchematicsException(`Could not parse angular.json: ` + e.message);
}
return {
path,
workspace
};
}
interface NgAddOptions {
function getTsConfigOutDir(host, architect) {
const tsConfigPath = architect.build.options.tsConfig;
const tsConfigBuffer = host.read(tsConfigPath);
if (!tsConfigBuffer) {
throw new schematics_1.SchematicsException(`Could not read ${tsConfigPath}`);
}
const tsConfigContent = tsConfigBuffer.toString();
const tsConfig = core_1.parseJson(tsConfigContent);
if (tsConfig === null || typeof tsConfig !== 'object' || Array.isArray(tsConfig) ||
tsConfig.compilerOptions === null || typeof tsConfig.compilerOptions !== 'object' ||
Array.isArray(tsConfig.compilerOptions)) {
throw new schematics_1.SchematicsException(`Invalid tsconfig - ${tsConfigPath}`);
}
const outDir = tsConfig.compilerOptions.outDir;
return outDir;
}
function default_1(options) {
export function getWorkspace(host: Tree): WorkspaceSchema {
const path = getWorkspacePath(host);
const configBuffer = host.read(path);
if (configBuffer === null) {
throw new SchematicsException(`Could not find (${path})`);
}
const content = configBuffer.toString();
return parseJson(content, JsonParseMode.Loose) as {} as WorkspaceSchema;
}