Skip to content

Commit

Permalink
refactor: 💡 extract log logic to main
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho-vazquez committed Oct 16, 2020
1 parent bfe0276 commit e6befd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ async function run(): Promise<void> {
const filePath: string = core.getInput('file_path');
core.debug(`merging found dependencies with file ${filePath}`);

await overrideAngularVersions(versions, filePath);
const modified = overrideAngularVersions(versions, filePath);

core.debug(
`Depedencies merge in package.json: \n ${JSON.stringify(
modified,
null,
2
)}`
);

core.debug(new Date().toTimeString());
} catch (error) {
Expand Down
15 changes: 5 additions & 10 deletions src/override-angular-versions.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import {PackageJsonVersion} from './types/package-json-version';
import * as fs from 'fs';
import * as core from '@actions/core';

export async function overrideAngularVersions(
export function overrideAngularVersions(
angularVersions: PackageJsonVersion,
path: string
): Promise<void> {
): PackageJsonVersion {
const rawData = fs.readFileSync(path);
let packageJson: PackageJsonVersion = JSON.parse(rawData.toString());
packageJson = {...packageJson, ...angularVersions};
core.debug(
`Depedencies merge in package.json: \n ${JSON.stringify(
packageJson,
null,
2
)}`
);

fs.writeFileSync(path, JSON.stringify(packageJson));

return packageJson;
}

0 comments on commit e6befd2

Please sign in to comment.