Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ef5d300

Browse files
committedAug 18, 2019
chore: compile vuepress with babel to allow es-modules
- this allows code sharing between vuepress plugins and vuejs-components - replace module.exports by "export" and "require" by "import" - move code without nodejs specific requirements into a shared lib-directory
1 parent 59e26ad commit ef5d300

13 files changed

+77
-70
lines changed
 

‎.babelrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "current"
8+
}
9+
}
10+
]
11+
]
12+
}

‎package-lock.json

+25-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
},
2727
"homepage": "https://github.com/handlebars-lang/docs#readme",
2828
"devDependencies": {
29+
"@babel/core": "^7.5.5",
30+
"@babel/register": "^7.5.5",
2931
"@vue/eslint-config-prettier": "^5.0.0",
3032
"@vuepress/plugin-pwa": "^1.0.3",
3133
"axios": "^0.19.0",

‎src/.vuepress/config.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
const basePath = process.env.VUEPRESS_BASE || "/";
55

6+
// allow es-modules in nodejs libs
7+
require("@babel/register");
8+
69
console.log(`basePath: ${basePath}`);
710
module.exports = {
811
base: basePath,

‎src/.vuepress/plugins/lib/example-parser.js ‎src/.vuepress/lib/example-parser.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
const { prettifyJson } = require("./prettify-json");
2-
const Handlebars = require("handlebars");
1+
import { prettifyJson } from "./prettify-json";
2+
import Handlebars from "handlebars";
33

4-
class ExampleParser {
5-
constructor(originalExample, filePath) {
6-
this.filePath = filePath;
4+
export class ExampleParser {
5+
constructor(originalExample) {
76
this.originalExample = originalExample;
87
this.normalizedExample = null;
98
this.parseError = null;
@@ -79,7 +78,3 @@ class ExampleParser {
7978
});
8079
}
8180
}
82-
83-
module.exports = {
84-
ExampleParser
85-
};
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const axios = require("axios");
2-
const semver = require("semver");
1+
import axios from 'axios'
2+
import semver from 'semver'
33

4-
async function retrieveVersions() {
4+
export async function retrieveHandlebarsVersions() {
55
const npmMetadata = await retrieveHandlebarsMetadataFromNpmjs();
66

77
const allVersions = Object.keys(npmMetadata.versions).filter(version => semver.gte(version, "3.0.0"));
@@ -16,8 +16,4 @@ async function retrieveVersions() {
1616
async function retrieveHandlebarsMetadataFromNpmjs() {
1717
const response = await axios.get("https://registry.npmjs.org/handlebars/");
1818
return response.data;
19-
}
20-
21-
module.exports = {
22-
retrieveVersions
23-
};
19+
}

‎src/.vuepress/lib/prettify-json.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import prettier from "prettier";
2+
3+
export function prettifyJson(object, options = { width: 40 }) {
4+
return prettier.format(JSON.stringify(object), {
5+
parser: "json5",
6+
printWidth: options.width
7+
});
8+
}

‎src/.vuepress/plugins/add-parsed-examples-to-page.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/* eslint-disable no-console */
2+
/* eslint-env node */
23

3-
const { ExampleParser } = require("./lib/example-parser");
4-
const { ErrorCollector } = require("./lib/error-collector");
4+
import { ExampleParser } from "../lib/example-parser";
5+
import { ErrorCollector } from "./lib/error-collector";
56

6-
module.exports = {
7-
addParsedExampleToPage
8-
};
9-
10-
function addParsedExampleToPage() {
7+
export function addParsedExampleToPage() {
118
const errorCollector = new ErrorCollector();
129

1310
return {
@@ -19,7 +16,7 @@ function addParsedExampleToPage() {
1916
return;
2017
}
2118

22-
const exampleParser = new ExampleParser(frontmatter.example, _filePath);
19+
const exampleParser = new ExampleParser(frontmatter.example);
2320
frontmatter.parsedExample = exampleParser.parse();
2421
frontmatter.errorWhileParsingExample = exampleParser.parseError;
2522

‎src/.vuepress/plugins/button-link.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
module.exports = {
2-
buttonLink
3-
};
1+
/* eslint-env node */
42

5-
function buttonLink() {
3+
export function buttonLink() {
64
return {
75
name: "button link",
86
extendMarkdown(md) {

‎src/.vuepress/plugins/ensure-gh-pages-custom-domain.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
const fs = require("fs-extra");
2-
const path = require("path");
1+
/* eslint-env node */
32

4-
module.exports = {
5-
ensureGhPagesCustomDomain
6-
};
3+
import fs from "fs-extra";
4+
import path from "path";
75

8-
function ensureGhPagesCustomDomain(options, ctx) {
6+
export function ensureGhPagesCustomDomain(options, ctx) {
97
return {
108
name: "copy CNAME to ensure custom domain settings on Github-pages",
119
async generated() {

‎src/.vuepress/plugins/inject-handlebars-versions.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
/* eslint-disable no-console */
2+
/* eslint-env node */
23

3-
const handlebarsVersions = require("./lib/handlebars-versions");
4+
import { retrieveHandlebarsVersions } from "../lib/handlebars-versions";
45

5-
module.exports = {
6-
storeHandlebarsVersionAtVuePrototype
7-
};
8-
9-
function storeHandlebarsVersionAtVuePrototype() {
6+
export function storeHandlebarsVersionAtVuePrototype() {
107
return {
118
name: "storeHandlebarsVersionAtVuePrototype",
129
async enhanceAppFiles() {
13-
const versions = await handlebarsVersions.retrieveVersions();
10+
const versions = await retrieveHandlebarsVersions();
1411
console.log("Injecting handlebars versions" + JSON.stringify(versions));
1512
return {
1613
name: "storeHandlebarsVersionAtVuePrototype",

‎src/.vuepress/plugins/lib/error-collector.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/* eslint-disable no-console */
22

3-
const path = require("path");
3+
import path from "path";
44

5-
class ErrorCollector {
6-
constructor() {
5+
export class ErrorCollector {
6+
constructor(workingDir) {
77
this.filesAndErrors = [];
8+
this.workingDir = workingDir;
89
}
910

1011
collectErrorIfNotNull(filePath, error) {
@@ -27,7 +28,3 @@ class ErrorCollector {
2728
console.log("done");
2829
}
2930
}
30-
31-
module.exports = {
32-
ErrorCollector
33-
};

‎src/.vuepress/plugins/lib/prettify-json.js

-12
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.