Skip to content

Commit 6258f92

Browse files
committed
🐛 chore: fix init script
1 parent db02f37 commit 6258f92

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

cli/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ const commandAliases = {
1414
interactive: 'i',
1515
};
1616

17-
const options = parseArgs(process.argv.slice(2),{
17+
const parsedOptions = parseArgs(process.argv.slice(2),{
1818
alias: commandAliases,
1919
boolean: ['dry', 'interactive', 'help'],
2020
string: ['table', 'tableNames'],
2121
number: ['tNumber'],
2222
});
2323

24+
const options = Object.entries(parsedOptions).reduce((acc, [key, value]) => {
25+
if (['tableNames','n'].includes(key)) {
26+
acc[key] = value.split(',');
27+
}
28+
return acc;
29+
},{});
30+
2431
const showHelp = () => {
2532
console.info('Available commands:');
2633
Object.entries(COMMAND_DESCRIPTION).forEach(([key, value]) => {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dynamo-data-transform",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "DynamoDB Data Transformation Tool",
55
"main": "./index.js",
66
"repository": "https://github.com/jitsecurity/dynamo-data-transform",

src/command-handlers/init.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require('fs');
2+
const path = require('path');
23
const { DATA_TRANSFORMATIONS_FOLDER_NAME } = require('../config/constants');
34

45
const createFolderIfNotExist = (folderPath) => {
@@ -12,24 +13,20 @@ const createFolderIfNotExist = (folderPath) => {
1213
};
1314

1415
const initHandler = async ({ tableNames }) => {
15-
const baseTransformationsFolderPath = `${process.cwd()}/${DATA_TRANSFORMATIONS_FOLDER_NAME}`;
16+
const baseTransformationsFolderPath = path.join(process.cwd(), DATA_TRANSFORMATIONS_FOLDER_NAME);
1617

1718
createFolderIfNotExist(baseTransformationsFolderPath);
1819

1920
tableNames?.forEach((tableName) => {
2021
const isExist = createFolderIfNotExist(`${baseTransformationsFolderPath}/${tableName}`);
2122
if (!isExist) {
22-
const origin = `${__dirname}/../config/transformation-template-file.js`;
23-
const destination = `${baseTransformationsFolderPath}/${tableName}/v1_script-name.js`;
23+
const origin = path.join(__dirname, '../config/transformation-template-file.js');
24+
const destination = path.join(baseTransformationsFolderPath, tableName, 'v1_script-name.js');
2425
const originFile = fs.readFileSync(origin, 'utf8');
2526
const destinationFile = originFile.replace(/{{YOUR_TABLE_NAME}}/g, tableName);
26-
fs.writeFile(destination, destinationFile, 'utf8', (error) => {
27-
if (error) {
28-
console.error(`Could not write transformation template file for table ${tableName}`, error);
29-
throw error;
30-
}
31-
console.info(`Transformation template v1.js file has created for ${tableName}`);
32-
});
27+
28+
fs.writeFileSync(destination, destinationFile);
29+
console.info(`Transformation template v1.js file has created for ${tableName}`);
3330
}
3431
});
3532
};

0 commit comments

Comments
 (0)