Skip to content

Commit

Permalink
Use util-deprecate over custom implementation (will only log once)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Jun 7, 2017
1 parent 4a01541 commit 468515b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions app/react/src/server/utils.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import path from 'path';
import fs from 'fs';
import chalk from 'chalk';
import deprecate from 'util-deprecate';

const logger = console;
const fallbackHeadUsage = deprecate(
() => {},
'Usage of head.html has been deprecated. Please rename head.html to preview-head.html'
);

export function parseList(str) {
return str.split(',');
}

export function getHeadHtml(configDirPath) {
const headHtmlPath = path.resolve(configDirPath, 'preview-head.html');
const fallbackHtmlPath = path.resolve(configDirPath, 'head.html')
const fallbackHtmlPath = path.resolve(configDirPath, 'head.html');
let headHtml = '';
if (fs.existsSync(headHtmlPath)) {
headHtml = fs.readFileSync(headHtmlPath, 'utf8');
} else if(fs.existsSync(fallbackHtmlPath)) {
} else if (fs.existsSync(fallbackHtmlPath)) {
headHtml = fs.readFileSync(fallbackHtmlPath, 'utf8');
const msg = "WARNING: head.html has been deprecated.\nPlease rename head.html to preview-head.html"
logger.warn(chalk.bold(msg + chalk.reset('\n')));

fallbackHeadUsage();
}

return headHtml;
Expand All @@ -34,7 +35,6 @@ export function getManagerHeadHtml(configDirPath) {
return scriptHtml;
}


export function getEnvConfig(program, configEnv) {
Object.keys(configEnv).forEach(fieldName => {
const envVarName = configEnv[fieldName];
Expand Down

0 comments on commit 468515b

Please sign in to comment.