es6 to commonjs

develop
HerrHase 2 years ago
parent 9104d0c702
commit 8c5cebef39

@ -1,27 +1,12 @@
import { validate } from 'schema-utils'
import HappySite from './src/happySite.js'
// schema for options object
const schema = {
type: 'object',
properties: {
source: {
type: 'string'
},
destination: {
type: 'string'
},
views: {
type: 'string'
}
}
}
const HappySite = require('./src/happySite.js')
export default class HappySiteWebpackPlugin {
constructor(options = {}) {
validate(schema, options)
class HappySiteWebpackPlugin {
this._options = options
constructor(source, views) {
this._options = {
source: source,
views: views
}
}
apply(compiler) {
@ -42,6 +27,9 @@ export default class HappySiteWebpackPlugin {
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
const compilationHash = compilation.hash
const webpackPublicPath = '.' + compilation.getAssetPath(compilation.outputOptions.publicPath, { hash: compilationHash })
// Tapping to the assets processing pipeline on a specific stage.
compilation.hooks.processAssets.tap({
name: pluginName,
@ -52,10 +40,11 @@ export default class HappySiteWebpackPlugin {
},
(assets) => {
const happySite = new HappySite(this._options.source, this._options.destination, this._views)
const happySite = new HappySite(webpackPublicPath + this._options.source, this._options.views, webpackPublicPath)
happySite.run()
})
})
}
}
module.exports = { HappySiteWebpackPlugin }
module.exports = HappySiteWebpackPlugin

@ -1,7 +1,7 @@
{
"name": "happy-site-webpack-plugin",
"version": "0.1.0",
"type": "module",
"build": "webpack",
"author": "Björn Hase <me@herr-hase.wtf>",
"main": "index.js",
"description": "Generating a Website from a Markdown Generator",

@ -33,4 +33,4 @@ class ConfigStore {
// create instance
const instance = new ConfigStore();
export default instance
module.exports =instance

@ -1,8 +1,8 @@
import nunjucks from 'nunjucks'
import { minify } from 'html-minifier'
import fs from 'fs'
const nunjucks = require('nunjucks')
const { minify } = require('html-minifier')
const fs = require('fs')
import { asset, resize } from './helpers/engine.js'
const { asset, resize } = require('./engine.js')
/**
* engine - handle eta.js
@ -33,7 +33,7 @@ class Engine {
resize(args[0], args[1], options, done)
}, true)
// adding defaults for view, function and data from config.yml
// adding defaults for view, function and data = config.yml
this._defaults = {
site: site,
asset: asset
@ -58,4 +58,4 @@ class Engine {
}
export default Engine
module.exports = Engine

@ -1,14 +1,14 @@
import fs from 'fs'
import path from 'path'
import mkdirp from 'mkdirp'
const fs = require('fs')
const path = require('path')
const mkdirp = require('mkdirp')
import Engine from './engine.js'
import Sitemap from './sitemap.js'
const Engine = require('./engine.js')
const Sitemap = require('./sitemap.js')
import PagesQuery from './queries/pages.js'
import parseYamlFile from './parsers/yaml.js'
const PagesQuery = require('./queries/pages.js')
const parseYamlFile = require('./parsers/yaml.js')
import configStore from './config.js'
const configStore = require('./config.js')
/**
* Main
@ -29,10 +29,10 @@ class HappySite {
* @param {string} destination
*
*/
constructor(source, destination, views) {
constructor(source, views, destination) {
this._source = source
this._destination = destination
this._views = views
this._destination = destination
configStore.set('source', source)
configStore.set('destination', destination)
@ -76,7 +76,7 @@ class HappySite {
return;
}
// create directories and write file from page
// create directories and write file = page
mkdirp(this._destination + page.pathname).then(() => {
fs.writeFileSync(this._destination + page.pathname + '/' + page.filename, content)
})
@ -90,4 +90,4 @@ class HappySite {
}
}
export default HappySite
module.exports = HappySite

@ -1,7 +1,7 @@
import path from 'path'
import * as fs from 'fs'
const path = require('path')
const fs = require('fs')
import Media from './../media.js'
const Media = require('./../media.js')
/**
* asset - checks manifest.json for given path and return

@ -1,12 +1,12 @@
import path from 'path'
import * as fs from 'fs'
const path = require('path')
const fs = require('fs')
import sharp from 'sharp'
import mkdirp from 'mkdirp'
import crypto from 'crypto'
import slugify from 'slugify'
const sharp = require('sharp')
const mkdirp = require('mkdirp')
const crypto = require('crypto')
const slugify = require('slugify')
import configStore from './config.js'
const configStore = require('./config.js')
/**
*
@ -83,7 +83,7 @@ class Media {
}
/**
* resolve path to write file, hash will be get from fileBuffer and
* resolve path to write file, hash will be get = fileBuffer and
*
*
* @param {object} fileBuffer
@ -98,4 +98,4 @@ class Media {
}
}
export default Media
module.exports =Media

@ -1,5 +1,5 @@
import path from 'path'
import parseMarkdownFile from './../parsers/markdown.js'
const path = require('path')
const parseMarkdownFile = require('./../parsers/markdown.js')
/**
* Block
@ -31,4 +31,4 @@ class Block {
}
}
export default Block
module.exports =Block

@ -1,9 +1,9 @@
import path from 'path'
import slugify from 'slugify'
import merge from 'lodash.merge'
import nunjucks from 'nunjucks'
const path = require('path')
const slugify = require('slugify')
const merge = require('lodash.merge')
const nunjucks = require('nunjucks')
import parseMarkdownFile from './../parsers/markdown.js'
const parseMarkdownFile = require('./../parsers/markdown.js')
/**
* Page
@ -68,7 +68,7 @@ class Page {
}
/**
* create html-filename from filename
* create html-filename = filename
*
* @param {string} file
* @return {string}
@ -92,7 +92,7 @@ class Page {
}
/**
* pathname from parent
* pathname = parent
*
* @param {string} parent
* @return {string}
@ -109,4 +109,4 @@ class Page {
}
}
export default Page
module.exports =Page

@ -1,5 +1,5 @@
import yaml from 'js-yaml'
import { marked } from 'marked'
const yaml = require('js-yaml')
const { marked } = require('marked')
/**
* parse string of file, parse yaml and parse markdown
@ -39,4 +39,4 @@ function parseMarkdownFile(fileString) {
return result
}
export default parseMarkdownFile
module.exports =parseMarkdownFile

@ -1,4 +1,4 @@
import yaml from 'js-yaml'
const yaml = require('js-yaml')
/**
* parse string of file and only parse yaml
@ -16,10 +16,10 @@ function parseYamlFile(file) {
try {
config = yaml.load(file)
} catch (error) {
throw new Error('Yaml has errors!')
throw new Error('parseYamlFile: Yaml has errors!')
}
return config
}
export default parseYamlFile
module.exports = parseYamlFile

@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'
const fs = require('fs')
const path = require('path')
import Block from './../models/block.js'
const Block = require('./../models/block.js')
/**
* search, filter and find pages
@ -92,7 +92,7 @@ class Blocks {
}
/**
* remove '.md' and also ordering number from filename
* remove '.md' and also ordering number = filename
*
* @param {string} filename
* @return {string}
@ -128,4 +128,4 @@ class Blocks {
}
export default Blocks
module.exports =Blocks

@ -1,8 +1,8 @@
import fs from 'fs'
import path from 'path'
const fs = require('fs')
const path = require('path')
import Page from './../models/page.js'
import Blocks from './../queries/blocks.js'
const Page = require('./../models/page.js')
const Blocks = require('./../queries/blocks.js')
/**
* Pages - search, filter and find pages
@ -155,4 +155,4 @@ class Pages {
}
export default Pages
module.exports =Pages

@ -1,5 +1,5 @@
import { XMLParser, XMLBuilder, XMLValidator} from 'fast-xml-parser'
import dayjs from 'dayjs'
const { XMLParser, XMLBuilder, XMLValidator} = require('fast-xml-parser')
const dayjs = require('dayjs')
/**
*
@ -103,4 +103,4 @@ class Sitemap {
}
}
export default Sitemap
module.exports =Sitemap

@ -1,4 +1,4 @@
import HappySite from './src/happySite.js'
const happySite = new HappySite('./resources/site', './public', './resources/views')
const happySite = new HappySite('./resources/site', './resources/views', )
happySite.run()
Loading…
Cancel
Save