Skip to content

Commit 9ec2c05

Browse files
CopilotAttilaMihaly
andcommitted
Address code review feedback
- Replace deprecated fs.exists with fs.access - Use async fs.unlink instead of sync fs.unlinkSync - Fix command line argument parsing to handle paths with spaces Co-authored-by: AttilaMihaly <60483498+AttilaMihaly@users.noreply.github.com>
1 parent f7981e0 commit 9ec2c05

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

cli/morphir-elm-gen.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ const showDeprecationMessage = (cmd, opts) => {
3636

3737
switch (backendTarget) {
3838
case "TypeScript":
39-
const copyDeps = (options.copyDeps) ? "--copy-deps" : "";
40-
const cmdOptions = `--input=${options.input} --output=${options.output} ${copyDeps}`.trim();
39+
const args = ['--input=' + options.input, '--output=' + options.output];
40+
if (options.copyDeps) {
41+
args.push('--copy-deps');
42+
}
43+
const cmdOptions = args.join(' ');
4144
showDeprecationMessage("typescript", cmdOptions);
4245
// Try to use morphir from bin, fallback to direct node execution
4346
const morphirPath = path.join(__dirname, '..', 'cli2', 'lib', 'morphir.js');
44-
execa('node', [morphirPath, 'typescript-gen', ...cmdOptions.split(/\s+/)], { stdio: 'inherit' })
47+
execa('node', [morphirPath, 'typescript-gen'].concat(args), { stdio: 'inherit' })
4548
.then(() => {
4649
console.log("Done.")
4750
})

cli2/morphir-typescript-gen.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import * as util from 'util'
99

1010
const prettier = require("prettier");
1111

12-
const fsExists = util.promisify(fs.exists);
12+
const fsAccess = util.promisify(fs.access);
1313
const fsWriteFile = util.promisify(fs.writeFile);
1414
const fsMakeDir = util.promisify(fs.mkdir);
1515
const fsReadFile = util.promisify(fs.readFile);
16+
const fsUnlink = util.promisify(fs.unlink);
1617
const worker = require("./../Morphir.Elm.CLI").Elm.Morphir.Elm.CLI.init();
1718

1819
require('log-timestamp')
@@ -103,7 +104,8 @@ const gen = async (
103104
const filePath: string = path.join(fileDir, fileName)
104105
const incomingContent = prettier.format(content, { parser: "typescript" })
105106

106-
if(await fsExists(filePath)) {
107+
try {
108+
await fsAccess(filePath, fs.constants.F_OK);
107109
const existingContent: Buffer = await fsReadFile(filePath)
108110
if (existingContent.toString() == incomingContent) {
109111
//console.log(`No Changes Detected - ${filePath}`);
@@ -112,7 +114,7 @@ const gen = async (
112114
console.log(`UPDATE - ${filePath}`)
113115
}
114116
}
115-
else {
117+
catch (_) {
116118
console.log(`INSERT - ${filePath}`);
117119
}
118120

@@ -124,7 +126,7 @@ const gen = async (
124126

125127
const deletePromises = filesToDelete.map(async (fileToDelete: string) => {
126128
console.log(`DELETE - ${fileToDelete}`);
127-
return fs.unlinkSync(fileToDelete);
129+
return fsUnlink(fileToDelete);
128130
});
129131

130132
if (options.copyDeps) {

0 commit comments

Comments
 (0)