Skip to content

Commit

Permalink
Merge pull request #1517 from LLazyEmail/prepare-for-publish
Browse files Browse the repository at this point in the history
move logic for working with file system of markdown file and html with js into start.js
  • Loading branch information
vadim9999 authored Feb 14, 2023
2 parents cc9c146 + 27eca9b commit c21d3a7
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 68 deletions.
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import run from '@rollup/plugin-run';
const dev = process.env.NODE_ENV !== 'production';

export default {
input: 'src/index.js',
input: dev ? './start.js' : 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'cjs',
Expand Down
3 changes: 1 addition & 2 deletions src/domain/objectBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ const ERROR_REGEX_CONSTANT = (value) =>
const ERROR_REPLACER_FUNCTION = (value) =>
`something wrong with replacer function ${value}`;


// TODO to make this method working better [improvement]
// 1. to handle a case when literal is false, it's very scary
// 2. we really need to be able to handle a situation when replacer isn't defined before (by different reasons)
// 3. does this function works fine with `components`
// 3. does this function works fine with `components`
// 4. when something wrong - i want to have a better output about params that we passed

function objectBuilder(constant, replacer, literal = false) {
Expand Down
4 changes: 2 additions & 2 deletions src/domain/parse.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import stateInit from './state';

function parse(source, configureReplacer, configurationMap) {
function parse(markdown, configureReplacer, configurationMap) {
// passing content into the state,
// so we can do our updates step by step and track any errors
const state = stateInit(source, configurationMap);
const state = stateInit(markdown, configurationMap);

configureReplacer(state);

Expand Down
6 changes: 1 addition & 5 deletions src/domain/state/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
//------------------
// ---- helper > command-line-methods
import {
readSourceFile,
checkErrors,
checkWarnings,
// checkHtml,
} from '../../helper';
// TODO convert into singleton
const stateInit = (source, configurationMap) => {
// TODO rename
const markdown = readSourceFile(source);

const stateInit = (markdown, configurationMap) => {
const stateObject = {
content: markdown,
previewText: '',
Expand Down
23 changes: 5 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
import { isFolderExists } from './domain/write';

import { generateReactFullTemplate } from './templates/HackernoonTemplate/react/generateReactFullTemplate';
import { generateReactFullTemplateHackernoon } from './templates/HackernoonTemplate/react/generateReactFullTemplate';
import { generateHtmlFullTemplateHackernoon } from './templates/HackernoonTemplate/html/generateHtmlFullTemplate';
import { generateHtmlFullTemplateRecipes } from './templates/RecipesTemplate/html/generateHtmlFullTemplate';
//-------------------
// @TODO add path package, in order to make it work PERFECTLY
const FULL_SOURCE = 'source/source.md';

isFolderExists('./generated');
isFolderExists('./tests/_generated');

console.log('Mode', process.env.PARSE);

const modeMap = {
full: () => generateHtmlFullTemplateHackernoon(FULL_SOURCE),
reactFull: () => generateReactFullTemplate(FULL_SOURCE),
recipesFull: () =>
generateHtmlFullTemplateRecipes('source/recipes/source-nmtg.md'),
export {
generateHtmlFullTemplateHackernoon,
generateReactFullTemplateHackernoon,
generateHtmlFullTemplateRecipes,
};

modeMap[process.env.PARSE ?? 'full']();
16 changes: 5 additions & 11 deletions src/templates/HackernoonTemplate/html/generateHtmlFullTemplate.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
import TObject from 'atherdon-old-newsletter-js-outertemplate';
import parse from '../../../domain/parse';
import { deliver } from '../../../domain/deliver/deliver';
import { MESSAGE_HTML_FULL_TEMPLATE2 } from '../../../domain/deliver/deliver.constants';
import { verification } from '../../../domain/helper-methods';
import Replace from './components/Replace.class';
import configurationMap from './components/configurationMap';

const parseContent = ({ source }) => {
return parse(source, (state) => Replace.configure(state), configurationMap);
const parseContent = ({ markdown }) => {
return parse(markdown, (state) => Replace.configure(state), configurationMap);
};

const hackernoonTemplate = (content) => TObject.printTemplate(content);

export const generateHtmlFullTemplateHackernoon = (sourceFile) => {
export const generateHtmlFullTemplateHackernoon = (markdown) => {
// should warnings be returned here?
const {
content,
warnings,
// previewText
} = parseContent({
source: sourceFile,
markdown,
});

verification(warnings, content);

const hackernoonFullTemplate = hackernoonTemplate(content);

deliver(
hackernoonFullTemplate,
'hackernoon-full-template',
MESSAGE_HTML_FULL_TEMPLATE2,
);
return hackernoonFullTemplate;
};
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
import parse from '../../../domain/parse';
import { verification } from '../../../domain/helper-methods';
import { generateTemplateName, printMessage } from '../../../helper';
import { reactFullTemplate } from './generateReactFullTemplate/components/reactFullTemplate';
import {
writeHTML,
// isFolderExists
} from '../../../domain/write';
import Replace from './components/Replacer.class';
import configurationMap from './components/configurationMap';

// TODO add more messages here, and finally replace messages in our methods
const MESSAGE_REACT_FULL_TEMPLATE =
'The FullTemplate has been parsed successfully';
// const MESSAGE_REACT_CONTENT = 'The Content has been parsed successfully';
const parseReactContent = (markdown) =>
parse(markdown, (state) => Replace.configure(state), configurationMap);

const parseReactContent = (source) =>
parse(source, (state) => Replace.configure(state), configurationMap);

export const generateReactFullTemplate = (sourceFile) => {
export const generateReactFullTemplateHackernoon = (markdown) => {
const {
content,
warnings,
// previewText
} = parseReactContent(sourceFile);
} = parseReactContent(markdown);

verification(warnings);

const fullContent = reactFullTemplate(content);

// TODO replace this three rows on deliver function
const fileName = generateTemplateName('FullTemplate', 'js');
writeHTML(fileName, fullContent);
printMessage(MESSAGE_REACT_FULL_TEMPLATE, 'green2');
return fullContent;
};
16 changes: 5 additions & 11 deletions src/templates/RecipesTemplate/html/generateHtmlFullTemplate.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
import parse from '../../../domain/parse';
import { deliver } from '../../../domain/deliver/deliver';
import { MESSAGE_HTML_FULL_TEMPLATE2 } from '../../../domain/deliver/deliver.constants';
import { verification } from '../../../domain/helper-methods';
import Replace from './components/Replace.class';
import configurationMap from './components/configurationMap';

const parseContent = ({ source }) => {
return parse(source, (state) => Replace.configure(state), configurationMap);
const parseContent = ({ markdown }) => {
return parse(markdown, (state) => Replace.configure(state), configurationMap);
};

const recipesTemplate = (content) => `<html>${content}</html>`;

export const generateHtmlFullTemplateRecipes = (sourceFile) => {
export const generateHtmlFullTemplateRecipes = (markdown) => {
// should warnings be returned here?
const {
content,
warnings,
// previewText
} = parseContent({
source: sourceFile,
markdown,
});

verification(warnings, content);

const recipesFullTemplate = recipesTemplate(content);

deliver(
recipesFullTemplate,
'recipes-full-template',
MESSAGE_HTML_FULL_TEMPLATE2,
);
return recipesFullTemplate;
};
62 changes: 62 additions & 0 deletions start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
generateHtmlFullTemplateHackernoon,
generateReactFullTemplateHackernoon,
generateHtmlFullTemplateRecipes,
} from './src';
import {
readSourceFile,
generateTemplateName,
printMessage,
} from './src/helper';
import { writeHTML, isFolderExists } from './src/domain/write';
import { deliver } from './src/domain/deliver/deliver';
import { MESSAGE_HTML_FULL_TEMPLATE2 } from './src/domain/deliver/deliver.constants';

// TODO add more messages here, and finally replace messages in our methods
const MESSAGE_REACT_FULL_TEMPLATE =
'The FullTemplate has been parsed successfully';
// const MESSAGE_REACT_CONTENT = 'The Content has been parsed successfully';

//-------------------
// @TODO add path package, in order to make it work PERFECTLY
const FULL_SOURCE = 'source/source.md';
const RECIPES_SOURCE = 'source/recipes/source-nmtg.md';

const markdown = readSourceFile(FULL_SOURCE);

isFolderExists('./generated');
isFolderExists('./tests/_generated');

export const modes = {
full: () => {
const hackernoonFullTemplate = generateHtmlFullTemplateHackernoon(markdown);

deliver(
hackernoonFullTemplate,
'hackernoon-full-template',
MESSAGE_HTML_FULL_TEMPLATE2,
);
},
reactFull: () => {
const fullContent = generateReactFullTemplateHackernoon(markdown);

// TODO replace this three rows on deliver function
const fileName = generateTemplateName('FullTemplate', 'js');
writeHTML(fileName, fullContent);
printMessage(MESSAGE_REACT_FULL_TEMPLATE, 'green2');
},
recipesFull: () => {
const markdownRecipes = readSourceFile(RECIPES_SOURCE);

const recipesFullTemplate =
generateHtmlFullTemplateRecipes(markdownRecipes);

deliver(
recipesFullTemplate,
'recipes-full-template',
MESSAGE_HTML_FULL_TEMPLATE2,
);
},
};

modes[process.env.PARSE ?? 'full'](FULL_SOURCE);

0 comments on commit c21d3a7

Please sign in to comment.