11// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22// See LICENSE in the project root for license information.
33
4- import * as fs from 'fs' ;
54import * as path from 'path' ;
65import * as semver from 'semver' ;
76
7+ import {
8+ FileSystem ,
9+ JsonFile
10+ } from '@microsoft/node-core-library' ;
11+
812import {
913 PublishUtilities ,
1014 IChangeInfoHash
@@ -71,19 +75,18 @@ export class ChangelogGenerator {
7175 const markdownPath : string = path . resolve ( project . projectFolder , CHANGELOG_MD ) ;
7276 const markdownJSONPath : string = path . resolve ( project . projectFolder , CHANGELOG_JSON ) ;
7377
74- if ( fs . existsSync ( markdownPath ) ) {
78+ if ( FileSystem . exists ( markdownPath ) ) {
7579 console . log ( 'Found: ' + markdownPath ) ;
76- if ( ! fs . existsSync ( markdownJSONPath ) ) {
80+ if ( ! FileSystem . exists ( markdownJSONPath ) ) {
7781 throw new Error ( 'A CHANGELOG.md without json: ' + markdownPath ) ;
7882 }
7983
8084 const changelog : IChangelog = ChangelogGenerator . _getChangelog ( project . packageName , project . projectFolder ) ;
8185 const isLockstepped : boolean = ! ! project . versionPolicy && project . versionPolicy . isLockstepped ;
8286
83- fs . writeFileSync (
87+ FileSystem . writeFile (
8488 path . join ( project . projectFolder , CHANGELOG_MD ) ,
85- ChangelogGenerator . _translateToMarkdown ( changelog , rushConfiguration , isLockstepped ) ,
86- { encoding : 'utf8' }
89+ ChangelogGenerator . _translateToMarkdown ( changelog , rushConfiguration , isLockstepped )
8790 ) ;
8891 }
8992
@@ -146,12 +149,11 @@ export class ChangelogGenerator {
146149
147150 if ( shouldCommit ) {
148151 // Write markdown transform.
149- fs . writeFileSync ( changelogFilename , JSON . stringify ( changelog , undefined , 2 ) , { encoding : 'utf8' } ) ;
152+ JsonFile . save ( changelog , changelogFilename ) ;
150153
151- fs . writeFileSync (
154+ FileSystem . writeFile (
152155 path . join ( projectFolder , CHANGELOG_MD ) ,
153- ChangelogGenerator . _translateToMarkdown ( changelog , rushConfiguration , isLockstepped ) ,
154- { encoding : 'utf8' }
156+ ChangelogGenerator . _translateToMarkdown ( changelog , rushConfiguration , isLockstepped )
155157 ) ;
156158 }
157159 return changelog ;
@@ -168,8 +170,8 @@ export class ChangelogGenerator {
168170 let changelog : IChangelog | undefined = undefined ;
169171
170172 // Try to read the existing changelog.
171- if ( fs . existsSync ( changelogFilename ) ) {
172- changelog = JSON . parse ( fs . readFileSync ( changelogFilename , 'utf8' ) ) as IChangelog ;
173+ if ( FileSystem . exists ( changelogFilename ) ) {
174+ changelog = JsonFile . load ( changelogFilename ) ;
173175 }
174176
175177 if ( ! changelog ) {
0 commit comments