Skip to content

Commit

Permalink
Merge pull request #1232 from Sikora00/master
Browse files Browse the repository at this point in the history
fix(sub-app): dry-run
  • Loading branch information
kamilmysliwiec committed Dec 27, 2022
2 parents 543b8f8 + d7cd380 commit 6972b2d
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/lib/sub-app/sub-app.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
apply,
branchAndMerge,
chain,
FileEntry,
mergeWith,
move,
noop,
Expand Down Expand Up @@ -211,7 +212,7 @@ function updateNpmScripts(
options.rootDir !== undefined ? options.rootDir : DEFAULT_APPS_PATH;
scripts[
defaultStartScriptName
] = `node dist/${defaultSourceRoot}/${defaultAppName}/main`;
] = `node dist/${defaultSourceRoot}/${defaultAppName}/main`;
}
}

Expand Down Expand Up @@ -252,26 +253,28 @@ function moveDefaultAppToApps(
if (process.env.NODE_ENV === TEST_ENV) {
return host;
}
try {
if (fse.existsSync(sourceRoot)) {
fse.moveSync(
sourceRoot,
join(projectRoot as Path, appName, sourceRoot),
);
}
const testDir = 'test';
if (fse.existsSync(testDir)) {
fse.moveSync(testDir, join(projectRoot as Path, appName, testDir));
}
} catch (err) {
throw new SchematicsException(
`The "${projectRoot}" directory exists already.`,
);
}
const appDestination = join(projectRoot as Path, appName);

moveDirectoryTo(sourceRoot, appDestination, host);

moveDirectoryTo('test', appDestination, host);
return host;
};
}

function moveDirectoryTo(
srcDir: string,
destination: string,
tree: Tree,
): void {
tree.getDir(srcDir).visit((filePath: Path, file: Readonly<FileEntry>) => {
const newFilePath = join(destination as Path, filePath);
tree.create(newFilePath, file.content);
tree.delete(filePath);
});
tree.delete(srcDir);
}

function addAppsToCliOptions(
projectRoot: string,
projectName: string,
Expand Down

0 comments on commit 6972b2d

Please sign in to comment.