Skip to content

Commit

Permalink
refactor: working
Browse files Browse the repository at this point in the history
  • Loading branch information
Gal Tidhar committed Apr 29, 2024
1 parent b302629 commit 8727f0f
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions automation/src/generators/provider/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {
generateFiles,
Tree,
} from '@nx/devkit';
const fs = require('fs');
import * as path from 'path';
import { ProviderGeneratorSchema } from './schema';

const fs = require('fs');

export async function providerGenerator(
tree: Tree,
options: ProviderGeneratorSchema
Expand All @@ -29,13 +30,41 @@ export async function providerGenerator(
generateFiles(tree, path.join(__dirname, 'files'), projectRoot, options);

const filePath = base + '/index.ts';
const lineToAdd = `export * from './${options.name}/${options.name}.provider';`;
fs.appendFile(filePath, `\n${lineToAdd}`, (err) => {
if (err) console.error('Error appending line to file:', err);
else console.log('Line added to file successfully.');
});
addLineToFile(
filePath,
`export * from './${options.name}/${options.name}.provider';`
);
await formatFiles(tree);
}
function addLineToFile(filePath, lineToAdd) {
// Read the file
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}

// Split the file content into lines
const lines = data.split('\n');

// Remove any trailing empty lines
while (lines.length > 0 && lines[lines.length - 1].trim() === '') {
lines.pop();
}

// Add the new line
lines.push(lineToAdd);

// Write the updated content back to the file
fs.writeFile(filePath, lines.join('\n') + '\n', 'utf8', (err) => {
if (err) {
console.error('Error writing to file:', err);
return;
}
console.log('Line added successfully.');
});
});
}

function toPascalCase(kebabString) {
return kebabString
Expand Down

0 comments on commit 8727f0f

Please sign in to comment.