Skip to content

Commit d01215a

Browse files
authored
Merge pull request #67 from oslabs-beta/writeFile
Write file location and commands updated to allow proto files to be written properly and read from properly from production build
2 parents 9a64e8b + 251ccb0 commit d01215a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/client/protoParser.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ async function protoParserFunc(protoBodyData) {
1515
let protoID = Math.floor(Math.random() * 10000);
1616
//if file path for that ID already exists, increment the ID
1717
try {
18-
while (fs.existsSync('src/client/components/composer/protos/' + protoID + '.proto')) {
18+
if (!fs.existsSync(path.join(process.cwd(), '/protos/'))) {
19+
fs.mkdirSync(path.join(process.cwd(), '/protos/'));
20+
}
21+
}catch(err) {
22+
console.error(err)
23+
}
24+
25+
try {
26+
while (fs.existsSync(path.join(process.cwd(), '/protos/' + protoID + '.proto'))) {
1927
//if file name exists try incrementing by 1
2028
protoID += 1;
2129
}
@@ -25,11 +33,13 @@ async function protoParserFunc(protoBodyData) {
2533
// const dirName = remote.app.getAppPath(); // remote.app.getAppPath() stopped working at some point so switched to process.cwd()
2634

2735
// write to saveProto file for interaction with the server
28-
fs.writeFileSync(path.join(process.cwd(), 'src/client/components/composer/protos/' + protoID + '.proto'), protoBodyData, 'utf-8');
36+
fs.writeFileSync(path.join(process.cwd(), '/protos/' + protoID + '.proto'), protoBodyData, 'utf-8');
2937

3038
// define the modular client for testing
3139
// declare path variable of imported proto file
32-
const PROTO_PATH = path.join(process.cwd(), 'src/client/components/composer/protos/' + protoID + '.proto');
40+
41+
42+
const PROTO_PATH = path.join(process.cwd(), '/protos/' + protoID + '.proto');
3343

3444
// create gRPC package options
3545
const protoOptionsObj = {

0 commit comments

Comments
 (0)