Nativefier/src/options/fields/name.js

27 lines
820 B
JavaScript
Raw Normal View History

import log from 'loglevel';
import { sanitizeFilename } from './../../utils';
import { inferTitle } from './../../infer';
import { DEFAULT_APP_NAME } from './../../constants';
function tryToInferName({ name, targetUrl }) {
// .length also checks if its the commanderJS function or a string
if (name && name.length > 0) {
return Promise.resolve(name);
}
return inferTitle(targetUrl)
2018-05-24 09:02:44 +02:00
.then((pageTitle) => pageTitle || DEFAULT_APP_NAME)
.catch((error) => {
2018-05-24 09:02:44 +02:00
log.warn(
`Unable to automatically determine app name, falling back to '${DEFAULT_APP_NAME}'. Reason: ${error}`,
);
return DEFAULT_APP_NAME;
});
}
2018-05-24 09:02:44 +02:00
export default function({ platform, name, targetUrl }) {
return tryToInferName({ name, targetUrl }).then((result) =>
sanitizeFilename(platform, result),
);
}