Skip to content

Commit ae76475

Browse files
author
Eric Fischer
authored
Make put_comments.sh static, data can be dynamic (#10)
Also update tests to illustrate what's happening now.
1 parent 221d5f7 commit ae76475

File tree

7 files changed

+17
-18
lines changed

7 files changed

+17
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typings/
5959

6060
# test output for diffs
6161
test_data/test_output.json
62+
output.txt
6263

6364
# package-lock is dumb and not at all worth it here
6465
package-lock.json

bash_scripts/hashed_data.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
12345deadbeef|It's a message, for testing
2+
8badf00d|Also a message for testing
3+
bada55|It's a message, for testing
4+
feedface9876|Also a message for testing

bash_scripts/put_comments.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
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
3-
curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"Also a message for testing\"}" $18badf00d
4-
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
5-
curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"Also a message for testing\"}" $1feedface9876
2+
while IFS='|' read -r string_hash string_comment; do
3+
curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"$string_comment\"}" $1$string_hash
4+
done < bash_scripts/hashed_data.txt

main.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@ inData.forEach((message) => {
2323
if (process.argv[3] === "--comments") {
2424
process.stdout.write("generating bash scripts...\n");
2525
var messageInfo = JSON.parse(fs.readFileSync(__dirname + "/bash_scripts/hashmap.json"));
26-
var scriptPath = __dirname + "/bash_scripts/put_comments.sh";
27-
fs.writeFileSync(scriptPath, "#!/bin/bash\n");
26+
var dataPath = __dirname + "/bash_scripts/hashed_data.txt";
27+
fs.writeFileSync(dataPath, "");
2828
inData.forEach((message) => {
2929
var info = messageInfo.find(mi => mi.key == message.id);
3030
if (info) {
31-
var header = " -H \"Content-Type: application/json\"";
32-
var escapedDescription = message.description.replace(/(["])/g, "\\\\\\$1");
33-
var data = " --data \"{\\\"comment\\\": \\\"" + escapedDescription + "\\\"}\"";
34-
var url = " $1" + info.string_hash;
35-
fs.appendFileSync(scriptPath, "curl -L -w \"\\n\" --user $SECRET_USER:$SECRET_PWD -X PUT" + header + data + url + "\n");
31+
fs.appendFileSync(dataPath, info.string_hash + "|" + message.description + "\n");
3632
} else {
3733
process.stdout.write("string " + message.id + " does not yet exist on transifex!\n");
3834
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "reactifex",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A helper for moving react-intl messages to transifex and back",
55
"bin": "./main.js",
66
"scripts": {
77
"lint": "eslint .",
88
"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",
9-
"test_comments": "node main.js test_data/input/ --comments && diff bash_scripts/put_comments.sh test_data/expected_output/put_comments.sh"
9+
"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"
1010
},
1111
"repository": {
1212
"type": "git",

test_data/expected_output/put_comments.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
+ 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
2+
+ 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
3+
+ 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
4+
+ 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

0 commit comments

Comments
 (0)