es6 to commonjs

develop
HerrHase 2 years ago
parent 9104d0c702
commit 8c5cebef39

@ -1,27 +1,12 @@
import { validate } from 'schema-utils' const HappySite = require('./src/happySite.js')
import HappySite from './src/happySite.js'
// schema for options object
const schema = {
type: 'object',
properties: {
source: {
type: 'string'
},
destination: {
type: 'string'
},
views: {
type: 'string'
}
}
}
export default class HappySiteWebpackPlugin { class HappySiteWebpackPlugin {
constructor(options = {}) {
validate(schema, options)
this._options = options constructor(source, views) {
this._options = {
source: source,
views: views
}
} }
apply(compiler) { apply(compiler) {
@ -42,6 +27,9 @@ export default class HappySiteWebpackPlugin {
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => { 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. // Tapping to the assets processing pipeline on a specific stage.
compilation.hooks.processAssets.tap({ compilation.hooks.processAssets.tap({
name: pluginName, name: pluginName,
@ -52,10 +40,11 @@ export default class HappySiteWebpackPlugin {
}, },
(assets) => { (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", "name": "happy-site-webpack-plugin",
"version": "0.1.0", "version": "0.1.0",
"type": "module", "build": "webpack",
"author": "Björn Hase <me@herr-hase.wtf>", "author": "Björn Hase <me@herr-hase.wtf>",
"main": "index.js", "main": "index.js",
"description": "Generating a Website from a Markdown Generator", "description": "Generating a Website from a Markdown Generator",

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

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

@ -1,14 +1,14 @@
import fs from 'fs' const fs = require('fs')
import path from 'path' const path = require('path')
import mkdirp from 'mkdirp' const mkdirp = require('mkdirp')
import Engine from './engine.js' const Engine = require('./engine.js')
import Sitemap from './sitemap.js' const Sitemap = require('./sitemap.js')
import PagesQuery from './queries/pages.js' const PagesQuery = require('./queries/pages.js')
import parseYamlFile from './parsers/yaml.js' const parseYamlFile = require('./parsers/yaml.js')
import configStore from './config.js' const configStore = require('./config.js')
/** /**
* Main * Main
@ -29,10 +29,10 @@ class HappySite {
* @param {string} destination * @param {string} destination
* *
*/ */
constructor(source, destination, views) { constructor(source, views, destination) {
this._source = source this._source = source
this._destination = destination
this._views = views this._views = views
this._destination = destination
configStore.set('source', source) configStore.set('source', source)
configStore.set('destination', destination) configStore.set('destination', destination)
@ -76,7 +76,7 @@ class HappySite {
return; return;
} }
// create directories and write file from page // create directories and write file = page
mkdirp(this._destination + page.pathname).then(() => { mkdirp(this._destination + page.pathname).then(() => {
fs.writeFileSync(this._destination + page.pathname + '/' + page.filename, content) 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' const path = require('path')
import * as fs from 'fs' const fs = require('fs')
import Media from './../media.js' const Media = require('./../media.js')
/** /**
* asset - checks manifest.json for given path and return * asset - checks manifest.json for given path and return

@ -1,12 +1,12 @@
import path from 'path' const path = require('path')
import * as fs from 'fs' const fs = require('fs')
import sharp from 'sharp' const sharp = require('sharp')
import mkdirp from 'mkdirp' const mkdirp = require('mkdirp')
import crypto from 'crypto' const crypto = require('crypto')
import slugify from 'slugify' const slugify = require('slugify')
import configStore from './config.js' const configStore = require('./config.js')
/** /**
* *
@ -59,7 +59,7 @@ class Media {
/** /**
* @TODO much nicer to add a hook system so behavior can be change * @TODO much nicer to add a hook system so behavior can be change
* *
* *
* @param {string} extension * @param {string} extension
* *
@ -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 * @param {object} fileBuffer
@ -98,4 +98,4 @@ class Media {
} }
} }
export default Media module.exports =Media

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

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

@ -1,5 +1,5 @@
import yaml from 'js-yaml' const yaml = require('js-yaml')
import { marked } from 'marked' const { marked } = require('marked')
/** /**
* parse string of file, parse yaml and parse markdown * parse string of file, parse yaml and parse markdown
@ -39,4 +39,4 @@ function parseMarkdownFile(fileString) {
return result 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 * parse string of file and only parse yaml
@ -16,10 +16,10 @@ function parseYamlFile(file) {
try { try {
config = yaml.load(file) config = yaml.load(file)
} catch (error) { } catch (error) {
throw new Error('Yaml has errors!') throw new Error('parseYamlFile: Yaml has errors!')
} }
return config return config
} }
export default parseYamlFile module.exports = parseYamlFile

@ -1,7 +1,7 @@
import fs from 'fs' const fs = require('fs')
import path from 'path' const path = require('path')
import Block from './../models/block.js' const Block = require('./../models/block.js')
/** /**
* search, filter and find pages * search, filter and find pages
@ -9,7 +9,7 @@ import Block from './../models/block.js'
* @author Björn Hase <me@herr-hase.wtf> * @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License * @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git * @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git
* *
*/ */
class Blocks { class Blocks {
@ -92,7 +92,7 @@ class Blocks {
} }
/** /**
* remove '.md' and also ordering number from filename * remove '.md' and also ordering number = filename
* *
* @param {string} filename * @param {string} filename
* @return {string} * @return {string}
@ -128,4 +128,4 @@ class Blocks {
} }
export default Blocks module.exports =Blocks

@ -1,8 +1,8 @@
import fs from 'fs' const fs = require('fs')
import path from 'path' const path = require('path')
import Page from './../models/page.js' const Page = require('./../models/page.js')
import Blocks from './../queries/blocks.js' const Blocks = require('./../queries/blocks.js')
/** /**
* Pages - search, filter and find pages * 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' const { XMLParser, XMLBuilder, XMLValidator} = require('fast-xml-parser')
import dayjs from 'dayjs' const dayjs = require('dayjs')
/** /**
* *
@ -7,7 +7,7 @@ import dayjs from 'dayjs'
* @author Björn Hase <me@herr-hase.wtf> * @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License * @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git * @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git
* *
*/ */
class Sitemap { class Sitemap {
@ -103,4 +103,4 @@ class Sitemap {
} }
} }
export default Sitemap module.exports =Sitemap

@ -1,4 +1,4 @@
import HappySite from './src/happySite.js' 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() happySite.run()
Loading…
Cancel
Save