Skip to content

Commit

Permalink
moved to path.join
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldelcore committed Jan 28, 2022
1 parent d0ebfd5 commit 49b7bcb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-bulldogs-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@codeshift/initializer': patch
---

Usage path module over string concatinations for better cross OS support
39 changes: 25 additions & 14 deletions packages/initializer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,20 @@ export function initDirectory(
targetPath: string = './',
isReduced: boolean = false,
) {
const basePath = `${targetPath}/${packageName.replace('/', '__')}`;
const configPath = `${basePath}${
!isReduced ? '/src' : ''
}/codeshift.config.js`;
const basePath = path.join(targetPath, packageName.replace('/', '__'));
const configPath = path.join(
basePath,
!isReduced ? 'src' : '',
'codeshift.config.js',
);

fs.copySync(`${__dirname}/../template${isReduced ? '/src' : ''}`, basePath, {
filter: src => !src.includes('src/codemod'),
});
fs.copySync(
path.join(__dirname, '..', 'template', isReduced ? 'src' : ''),
basePath,
{
filter: src => !src.includes('src/codemod'),
},
);

if (!isReduced) {
fs.writeFileSync(
Expand All @@ -135,19 +141,24 @@ export function initTransform(
throw new Error(`Provided version ${id} is not a valid semver version`);
}

const basePath = `${targetPath}/${packageName.replace('/', '__')}`;
const transformPath = `${basePath}${!isReduced ? '/src' : ''}/${id}`;
const configPath = `${basePath}${
!isReduced ? '/src' : ''
}/codeshift.config.js`;
const basePath = path.join(targetPath, packageName.replace('/', '__'));
const transformPath = path.join(basePath, !isReduced ? 'src' : '', id);
const configPath = path.join(
basePath,
!isReduced ? 'src' : '',
'codeshift.config.js',
);

if (fs.existsSync(transformPath)) {
throw new Error(`Codemod for ${type} "${id}" already exists`);
}

fs.copySync(`${__dirname}/../template${isReduced ? '/src' : ''}`, basePath);
fs.copySync(
path.join(__dirname, '..', 'template', isReduced ? 'src' : ''),
basePath,
);
fs.renameSync(
`${basePath}${!isReduced ? '/src' : ''}/codemod`,
path.join(basePath, !isReduced ? 'src' : '', 'codemod'),
transformPath,
);

Expand Down

0 comments on commit 49b7bcb

Please sign in to comment.