diff --git a/bin/stencil-start.js b/bin/stencil-start.js index 00b93acf..ab306783 100755 --- a/bin/stencil-start.js +++ b/bin/stencil-start.js @@ -42,12 +42,12 @@ if (!versionCheck()) { process.exit(2); } -if (!fileExist(dotStencilFilePath)) { +if (!Fs.existsSync(dotStencilFilePath)) { console.error('Error: Please run'.red + ' $ stencil init'.cyan + ' first.'.red); process.exit(2); } -if (!fileExist(Path.join(themePath, 'config.json'))) { +if (!Fs.existsSync(Path.join(themePath, 'config.json'))) { console.error('Error: You must have a '.red + 'config.json'.cyan + ' file in your top level theme directory.'); process.exit(2); } @@ -244,20 +244,6 @@ function assembleTemplates(templatePath, callback) { }); } -/** - * Check if file exist synchronous - * @param {string} path - * @return {boolean} - */ -function fileExist(path) { - try { - return !!Fs.statSync(path); - } - catch (e) { - return false; - } -} - /** * Displays information about your environment and configuration. * @return {string} diff --git a/lib/theme-config.js b/lib/theme-config.js index f532d44b..5f110c11 100644 --- a/lib/theme-config.js +++ b/lib/theme-config.js @@ -279,7 +279,7 @@ ThemeConfig.prototype.getDemoUrl = function () { * @return {Boolean} */ ThemeConfig.prototype.configExists = function () { - return fileExists(this.configPath); + return Fs.existsSync(this.configPath); }; /** @@ -287,7 +287,7 @@ ThemeConfig.prototype.configExists = function () { * @return {Boolean} */ ThemeConfig.prototype.schemaExists = function () { - return fileExists(this.schemaPath); + return Fs.existsSync(this.schemaPath); }; /** @@ -295,7 +295,7 @@ ThemeConfig.prototype.schemaExists = function () { * @return {Boolean} */ ThemeConfig.prototype.schemaTranslationsExists = function () { - return fileExists(this.schemaTranslationsPath); + return Fs.existsSync(this.schemaTranslationsPath); }; /** @@ -477,17 +477,3 @@ function getVariation(config, variationIndex) { return variation; } - -/** - * Check if file exist syncronous - * @param {string} path - * @return {boolean} - */ -function fileExists(path) { - try { - return !!Fs.statSync(path); - } - catch (e) { - return false; - } -} diff --git a/tasks/changelog/changelog-generator.js b/tasks/changelog/changelog-generator.js index 22de919c..98f52d9f 100644 --- a/tasks/changelog/changelog-generator.js +++ b/tasks/changelog/changelog-generator.js @@ -33,9 +33,7 @@ function ChangelogGenerator(fs, cwd, commandExecutor) { ...customOptions, }; - try { - fs.statSync(options.infile); - } catch(error) { + if (!fs.existsSync(options.infile)) { options.releaseCount = 0; } diff --git a/tasks/changelog/changelog-generator.spec.js b/tasks/changelog/changelog-generator.spec.js index 1e6ee8a1..c5dda660 100644 --- a/tasks/changelog/changelog-generator.spec.js +++ b/tasks/changelog/changelog-generator.spec.js @@ -12,7 +12,7 @@ describe('ChangelogGenerator', () => { beforeEach( () => { fsMock = { - statSync: function() { return true; }, + existsSync: () => true, }; commandExecutor = new CommandExecutor(require('child_process')); @@ -70,7 +70,10 @@ describe('ChangelogGenerator', () => { }); it('executes `conventional-changelog` command from scratch if CHANGELOG does not exist', async() => { - const changelogGeneratorWithoutFs = new ChangelogGenerator({}, '/src', commandExecutor); + const fsMock = { + existsSync: () => false, + }; + const changelogGeneratorWithoutFs = new ChangelogGenerator(fsMock, '/src', commandExecutor); try { await promisify(changelogGeneratorWithoutFs.generateChangelog.bind(changelogGeneratorWithoutFs))({});