diff --git a/.gitignore b/.gitignore index 5994348..6e4421b 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ typings/ # test output for diffs test_data/test_output.json +output.txt # package-lock is dumb and not at all worth it here package-lock.json diff --git a/bash_scripts/hashed_data.txt b/bash_scripts/hashed_data.txt new file mode 100644 index 0000000..6fcb020 --- /dev/null +++ b/bash_scripts/hashed_data.txt @@ -0,0 +1,4 @@ +12345deadbeef|It's a message, for testing +8badf00d|Also a message for testing +bada55|It's a message, for testing +feedface9876|Also a message for testing diff --git a/bash_scripts/put_comments.sh b/bash_scripts/put_comments.sh index 6473489..bc16eb9 100755 --- a/bash_scripts/put_comments.sh +++ b/bash_scripts/put_comments.sh @@ -1,5 +1,4 @@ #!/bin/bash -curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"It's a message, for testing\"}" $112345deadbeef -curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"Also a message for testing\"}" $18badf00d -curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"It's a message, for testing\"}" $1bada55 -curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"Also a message for testing\"}" $1feedface9876 +while IFS='|' read -r string_hash string_comment; do + curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"$string_comment\"}" $1$string_hash +done < bash_scripts/hashed_data.txt diff --git a/main.js b/main.js index 712892e..ed59525 100755 --- a/main.js +++ b/main.js @@ -23,16 +23,12 @@ inData.forEach((message) => { if (process.argv[3] === "--comments") { process.stdout.write("generating bash scripts...\n"); var messageInfo = JSON.parse(fs.readFileSync(__dirname + "/bash_scripts/hashmap.json")); - var scriptPath = __dirname + "/bash_scripts/put_comments.sh"; - fs.writeFileSync(scriptPath, "#!/bin/bash\n"); + var dataPath = __dirname + "/bash_scripts/hashed_data.txt"; + fs.writeFileSync(dataPath, ""); inData.forEach((message) => { var info = messageInfo.find(mi => mi.key == message.id); if (info) { - var header = " -H \"Content-Type: application/json\""; - var escapedDescription = message.description.replace(/(["])/g, "\\\\\\$1"); - var data = " --data \"{\\\"comment\\\": \\\"" + escapedDescription + "\\\"}\""; - var url = " $1" + info.string_hash; - fs.appendFileSync(scriptPath, "curl -L -w \"\\n\" --user $SECRET_USER:$SECRET_PWD -X PUT" + header + data + url + "\n"); + fs.appendFileSync(dataPath, info.string_hash + "|" + message.description + "\n"); } else { process.stdout.write("string " + message.id + " does not yet exist on transifex!\n"); } diff --git a/package.json b/package.json index 80156e6..2b566db 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "reactifex", - "version": "1.0.1", + "version": "1.0.2", "description": "A helper for moving react-intl messages to transifex and back", "bin": "./main.js", "scripts": { "lint": "eslint .", "test_compile": "node main.js test_data/input/ test_data/test_output.json && diff test_data/test_output.json test_data/expected_output/messages.json", - "test_comments": "node main.js test_data/input/ --comments && diff bash_scripts/put_comments.sh test_data/expected_output/put_comments.sh" + "test_comments": "node main.js test_data/input/ --comments && SECRET_USER=uname SECRET_PWD=password bash -x ./bash_scripts/put_comments.sh http://totally_real.notfake.com/api/ 2>&1 | grep PUT > output.txt && diff -w output.txt test_data/expected_output/test_curl.txt" }, "repository": { "type": "git", diff --git a/test_data/expected_output/put_comments.sh b/test_data/expected_output/put_comments.sh deleted file mode 100755 index 6473489..0000000 --- a/test_data/expected_output/put_comments.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"It's a message, for testing\"}" $112345deadbeef -curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"Also a message for testing\"}" $18badf00d -curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"It's a message, for testing\"}" $1bada55 -curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"Also a message for testing\"}" $1feedface9876 diff --git a/test_data/expected_output/test_curl.txt b/test_data/expected_output/test_curl.txt new file mode 100644 index 0000000..2f3ef7a --- /dev/null +++ b/test_data/expected_output/test_curl.txt @@ -0,0 +1,4 @@ ++ curl -L -w '\n' --user uname:password -X PUT -H 'Content-Type: application/json' --data '{"comment": "It'\''s a message, for testing"}' http://totally_real.notfake.com/api/12345deadbeef ++ curl -L -w '\n' --user uname:password -X PUT -H 'Content-Type: application/json' --data '{"comment": "Also a message for testing"}' http://totally_real.notfake.com/api/8badf00d ++ curl -L -w '\n' --user uname:password -X PUT -H 'Content-Type: application/json' --data '{"comment": "It'\''s a message, for testing"}' http://totally_real.notfake.com/api/bada55 ++ curl -L -w '\n' --user uname:password -X PUT -H 'Content-Type: application/json' --data '{"comment": "Also a message for testing"}' http://totally_real.notfake.com/api/feedface9876