Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
) => {
story.info('extractor', `Processing ${chalk.cyan.bold(filePath)}...`);
const absPath = path.resolve(process.cwd(), filePath);
const rawSnapshots = loadSnapshot(absPath);
const suiteCss = getSuiteCss(filePath, story);
const finalFilePath = `-/${filePath.normalize()}`;
const prevSuite = _snapshotSuiteDict[finalFilePath];
// $FlowFixMe
const suite: SnapshotSuiteT = {};
let suiteDirty = false;
const nextIds = Object.keys(rawSnapshots);
for (let i = 0; i < nextIds.length; i++) {
const id = nextIds[i];
const rawSnapshot = rawSnapshots[id];
const [snap, html] = rawSnapshot.split(HTML_PREVIEW_SEPARATOR);
const css = suiteCss != null ? addLast(commonCss, suiteCss) : commonCss;
const snapshot: SnapshotT = {
id,
snap,
html,
css,
dirty: false,
deleted: false,
};
if (prevSuite && prevSuite[id]) {
const prevSnapshot = prevSuite[id];
const prevBaseline = prevSnapshot.baseline;
// Copy the previous baseline, if any
if (prevBaseline != null) {
snapshot.baseline = prevBaseline;
snapshot.dirty =
html !== prevBaseline.html || snap !== prevBaseline.snap;
Object.keys(_snapshotSuiteDict).forEach(filePath => {
const suite = _snapshotSuiteDict[filePath];
const suiteCss = getSuiteCss(filePath, story);
const css = suiteCss != null ? addLast(commonCss, suiteCss) : commonCss;
forEachSnapshot(suite, snapshot => {
snapshot.css = css; // eslint-disable-line no-param-reassign
});
});
};
onAddLang = () => {
const prevLangs = this.state.langs;
const availableLangs = this.props.viewer.config.langs;
const newLang = availableLangs.find(o => prevLangs.indexOf(o) < 0);
if (newLang == null) return;
const nextLangs = timm.addLast(prevLangs, newLang);
this.updateLangs(nextLangs);
};
onCreateListItem = (ev: SyntheticEvent) => {
if (!(ev.currentTarget instanceof HTMLElement)) return;
const { id } = ev.currentTarget;
const newList = timm.addLast(this.state[id], '');
this.setState({ [id]: newList });
};
handleOptionsAdd = () => {
const options = addLast(this.props.options, this.state.newItemValue);
this.setState({ newItemValue: "" });
this.props.onChange({ options });
};
handleOptionsRemove = index => {
definitionOptions,
modelName,
options,
context
) => {
const extensions =
options && options.extensions && options.extensions[modelName];
if (!extensions) return;
if (extensions.validate) {
definitionOptions.validate = merge(
definitionOptions.validate,
extensions.validate(context)
);
}
if (extensions.indexes) {
definitionOptions.indexes = addLast(
definitionOptions.indexes,
extensions.indexes(context)
);
}
if (extensions.hooks) {
definitionOptions.hooks = merge(
definitionOptions.hooks,
extensions.hooks(context)
);
}
};
const diveProcess = (err, filePath) => {
const finalFilePath = path.normalize(filePath);
story.info('importData', `Processing ${chalk.cyan.bold(finalFilePath)}...`);
const lang = path.basename(filePath, '.json').replace(/_/gi, '-');
if (outLangs.indexOf(lang) < 0) {
outLangs = timm.addLast(outLangs, lang);
}
const js = JSON.parse(fs.readFileSync(finalFilePath));
let numNewK = 0;
let numNewT = 0;
Object.keys(js).forEach(keyId => {
const newTranslation = js[keyId];
const {
fTranslated,
context,
original: text,
translation,
firstUsed,
unusedSince,
sources,
} = newTranslation;