Skip to content

Commit

Permalink
fix(install): properly copy and overwrite files
Browse files Browse the repository at this point in the history
  • Loading branch information
pathurs committed Sep 27, 2020
1 parent 1f0c731 commit a9e3462
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
6 changes: 3 additions & 3 deletions source/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { default as rootPath } from 'app-root-path';
import {
absoluteCurrentDefaultDirectory,
absoluteCurrentDefaultFilesGlob,
absoluteDefaultForceOverwriteFilePaths,
relativeForceOverwriteFilePaths,
renamedPrefix
} from './variables';
import {
Expand Down Expand Up @@ -40,12 +40,12 @@ function copyDefaultFilesToRoot(): void {
const absoluteDefaultFilePaths = getFilePaths(absoluteCurrentDefaultFilesGlob);

for (const absoluteDefaultFilePath of absoluteDefaultFilePaths) {
const relativeFilePath = absoluteDefaultFilePath.replace(absoluteCurrentDefaultDirectory, '');
const relativeFilePath = absoluteDefaultFilePath.replace(`${absoluteCurrentDefaultDirectory}\\`, '');

const absoluteFilePath = path.join(rootPath.path, relativeFilePath);

if (fs.existsSync(absoluteFilePath)) {
if (absoluteDefaultForceOverwriteFilePaths.includes(absoluteFilePath)) {
if (relativeForceOverwriteFilePaths.includes(relativeFilePath)) {
log(`Copying and overwriting file '${relativeFilePath}' to '${absoluteFilePath}'.`);

fs.copyFileSync(absoluteDefaultFilePath, absoluteFilePath);
Expand Down
36 changes: 15 additions & 21 deletions source/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ const relativeGitHubWorkflowsNodejsMasterYmlPath = path.normalize('./.github/wor
const relativeVSCodeSettingsJsonPath = path.normalize('./.vscode/settings.json');
const relativeDocumentationAssetsColonise256PngPath = path.normalize('./documentation/assets/colonise256.png');

export const relativeForceOverwriteFilePaths = [
relativeEslintRCPath,
relativeLicensePath,
relativeNYCConfigJsPath,
relativeSemanticReleaseConfigJsPath,
relativeTSConfigJsonPath,
relativeGitHubDependabotYmlPath,
relativeGitHubWorkflowsNodejsMasterYmlPath,
relativeVSCodeSettingsJsonPath,
relativeDocumentationAssetsColonise256PngPath
];

// Absolute Root

export const absoluteRootDirectory = RootPath.path;
Expand Down Expand Up @@ -106,29 +118,11 @@ export const absoluteSourceDeclarationFilesGlob = path.join(absoluteSourceDirect

// Absolute Default

const absoluteDefaultEslintRCPath = path.join(absoluteDefaultDirectory, relativeEslintRCPath);
const absoluteDefaultLicensePath = path.join(absoluteDefaultDirectory, relativeLicensePath);
const absoluteDefaultNYCConfigJsPath = path.join(absoluteDefaultDirectory, relativeNYCConfigJsPath);
const absoluteDefaultSemanticReleaseConfigJsPath = path.join(absoluteDefaultDirectory, relativeSemanticReleaseConfigJsPath);
const absoluteDefaultTSConfigJsonPath = path.join(absoluteDefaultDirectory, relativeTSConfigJsonPath);
const absoluteDefaultGitHubDependabotYmlPath = path.join(absoluteDefaultDirectory, relativeGitHubDependabotYmlPath);
const absoluteDefaultGitHubWorkflowsNodejsMasterYmlPath = path.join(absoluteDefaultDirectory, relativeGitHubWorkflowsNodejsMasterYmlPath);
const absoluteDefaultVSCodeSettingsJsonPath = path.join(absoluteDefaultDirectory, relativeVSCodeSettingsJsonPath);
const absoluteDefaultDocumentationAssetsColonise256PngPath = path.join(absoluteDefaultDirectory, relativeDocumentationAssetsColonise256PngPath);

export const absoluteDefaultFilesGlob = `${absoluteDefaultDirectory}/**/*`;

export const absoluteDefaultForceOverwriteFilePaths = [
absoluteDefaultEslintRCPath,
absoluteDefaultLicensePath,
absoluteDefaultNYCConfigJsPath,
absoluteDefaultSemanticReleaseConfigJsPath,
absoluteDefaultTSConfigJsonPath,
absoluteDefaultGitHubDependabotYmlPath,
absoluteDefaultGitHubWorkflowsNodejsMasterYmlPath,
absoluteDefaultVSCodeSettingsJsonPath,
absoluteDefaultDocumentationAssetsColonise256PngPath
];
export const absoluteDefaultForceOverwriteFilePaths = relativeForceOverwriteFilePaths.map(
relativeFilePath => path.join(absoluteDefaultDirectory, relativeFilePath)
);

// Absolute Distribute

Expand Down

0 comments on commit a9e3462

Please sign in to comment.