/**
 * Creates a sample workspace with two applications: 'app' (default) and 'second-app'
 */
export const createTestApp = async (runner, appOptions = {}, files) => {
    let tree = await createWorkspace(runner);
    if (files) {
        addTestFiles(tree, files);
    }
    tree = await runner.runExternalSchematic('@schematics/angular', 'application', { name: 'app', ...appOptions }, tree);
    tree = await runner.runExternalSchematic('@schematics/angular', 'application', { name: 'second-app', ...appOptions }, tree);
    return tree;
};
const createWorkspace = (runner) => {
    return runner.runExternalSchematic('@schematics/angular', 'workspace', {
        name: 'workspace',
        version: '1.0.0',
        newProjectRoot: 'projects'
    });
};
export const addTestFiles = (tree, files) => {
    Object.entries(files).forEach(([path, content]) => {
        if (tree.exists(path)) {
            tree.overwrite(path, content);
        }
        else {
            tree.create(path, content);
        }
    });
    return tree;
};
export const readLines = (tree, path) => tree
    .readContent(path)
    .split('\n')
    .filter(l => l.length > 0);
export const removeTestFiles = (tree, files) => {
    files.forEach(path => {
        if (tree.exists(path)) {
            tree.delete(path);
        }
    });
    return tree;
};
