-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1517 from LLazyEmail/prepare-for-publish
move logic for working with file system of markdown file and html with js into start.js
- Loading branch information
Showing
9 changed files
with
87 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
src/templates/HackernoonTemplate/html/generateHtmlFullTemplate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
23 changes: 5 additions & 18 deletions
23
src/templates/HackernoonTemplate/react/generateReactFullTemplate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
src/templates/RecipesTemplate/html/generateHtmlFullTemplate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |