You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2019/11/04 17:54:18 UTC
[airflow-site] branch aip-11 updated: Lint all JS files (#113)
This is an automated email from the ASF dual-hosted git repository.
kamilbregula pushed a commit to branch aip-11
in repository https://gitbox.apache.org/repos/asf/airflow-site.git
The following commit(s) were added to refs/heads/aip-11 by this push:
new 6a565a5 Lint all JS files (#113)
6a565a5 is described below
commit 6a565a502df1af16c4566a50a88b7a9b447a39fb
Author: Kamil BreguĊa <mi...@users.noreply.github.com>
AuthorDate: Mon Nov 4 18:54:10 2019 +0100
Lint all JS files (#113)
---
.pre-commit-config.yaml | 1 -
landing-pages/.eslintignore | 19 ++++++
landing-pages/create-index.js | 130 ++++++++++++++++++++--------------------
landing-pages/package.json | 2 +-
landing-pages/webpack.common.js | 2 +-
landing-pages/webpack.dev.js | 4 +-
6 files changed, 89 insertions(+), 69 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 1da206a..1fedc24 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -109,7 +109,6 @@ repos:
entry: ./site.sh lint-js
language: system
files: \.js$
- exclude: "webpack.common.js|webpack.dev.js|create-index.js"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
diff --git a/landing-pages/.eslintignore b/landing-pages/.eslintignore
new file mode 100644
index 0000000..44fe4bf
--- /dev/null
+++ b/landing-pages/.eslintignore
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+dist/*
+site/themes/*
diff --git a/landing-pages/create-index.js b/landing-pages/create-index.js
index 4231697..69ec28f 100644
--- a/landing-pages/create-index.js
+++ b/landing-pages/create-index.js
@@ -17,94 +17,96 @@
* under the License.
*/
-const fs = require('fs').promises;
-const path = require('path');
-const { promisify } = require('util');
-const frontMatterParser = require('parser-front-matter');
+/* eslint-disable no-console */
+
+const fs = require("fs").promises;
+const path = require("path");
+const {promisify} = require("util");
+const frontMatterParser = require("parser-front-matter");
const parse = promisify(frontMatterParser.parse.bind(frontMatterParser));
-const lunrjs = require('lunr');
+const lunrjs = require("lunr");
const contentDirectory = `${__dirname}/site/content`;
const outputtDirectory = `${__dirname}/site/static/indexes`;
async function isDirectoryExists(dirPath) {
- try {
- if ((await fs.stat(dirPath)).isDirectory()) {
- return true;
- }
- }catch (err) {
- return false
+ try {
+ if ((await fs.stat(dirPath)).isDirectory()) {
+ return true;
}
- return false
+ } catch (err) {
+ return false;
+ }
+ return false;
}
async function loadPostsWithFrontMatter(postsDirectoryPath) {
- const fileNames = await fs.readdir(postsDirectoryPath);
- const posts = await Promise.all(
- fileNames.map(async fileName => {
- const fileContent = await fs.readFile(
- `${postsDirectoryPath}/${fileName}`,
- 'utf8'
- );
- const {content, data} = await parse(fileContent);
- return {
- content: content.slice(0, 3000),
- url: path.parse(fileName).name,
- ...data
- };
- })
- );
- return posts;
+ const fileNames = await fs.readdir(postsDirectoryPath);
+ const posts = await Promise.all(
+ fileNames.map(async(fileName) => {
+ const fileContent = await fs.readFile(
+ `${postsDirectoryPath}/${fileName}`,
+ "utf8"
+ );
+ const {content, data} = await parse(fileContent);
+ return {
+ content: content.slice(0, 3000),
+ url: path.parse(fileName).name,
+ ...data
+ };
+ })
+ );
+ return posts;
}
function makeIndex(posts) {
- return lunrjs(function() {
- this.ref('title');
- this.field('title');
- this.field("description");
- this.field("author");
- this.field('content');
- this.field('tags');
- this.field('url');
- posts.forEach(p => {
- this.add(p);
- });
+ return lunrjs(function() {
+ this.ref("title");
+ this.field("title");
+ this.field("description");
+ this.field("author");
+ this.field("content");
+ this.field("tags");
+ this.field("url");
+ posts.forEach((p) => {
+ this.add(p);
});
+ });
}
async function writeJson(filePath, index) {
- await fs.writeFile(filePath, JSON.stringify(index));
- console.log(`Saved ${path.parse(filePath).base} file.`)
+ await fs.writeFile(filePath, JSON.stringify(index));
+ console.log(`Saved ${path.parse(filePath).base} file.`);
}
async function processLanguage(language) {
- console.log(`Proccessing "${language}" language.`)
- const currentDirectory = `${contentDirectory}/${language}/blog`;
- if (!await isDirectoryExists(currentDirectory)) {
- console.log("No blog posts. Skipping.")
- return
- }
- const posts = await loadPostsWithFrontMatter(currentDirectory);
- const index = makeIndex(posts);
- const currentOutputDirectory = `${outputtDirectory}/${language}`;
- if (!await isDirectoryExists(currentOutputDirectory)) {
- await fs.mkdir(currentOutputDirectory)
- }
- await writeJson(`${currentOutputDirectory}/blog-index.json`, index);
- await writeJson(`${currentOutputDirectory}/blog-posts.json`, posts)
+ console.log(`Proccessing "${language}" language.`);
+ const currentDirectory = `${contentDirectory}/${language}/blog`;
+ if (!await isDirectoryExists(currentDirectory)) {
+ console.log("No blog posts. Skipping.");
+ return;
+ }
+ const posts = await loadPostsWithFrontMatter(currentDirectory);
+ const index = makeIndex(posts);
+ const currentOutputDirectory = `${outputtDirectory}/${language}`;
+ if (!await isDirectoryExists(currentOutputDirectory)) {
+ await fs.mkdir(currentOutputDirectory);
+ }
+ await writeJson(`${currentOutputDirectory}/blog-index.json`, index);
+ await writeJson(`${currentOutputDirectory}/blog-posts.json`, posts);
}
async function run() {
- const directoryNames = await fs.readdir(contentDirectory);
- for (const directoryName of directoryNames){
- await processLanguage(directoryName)
- }
+ const directoryNames = await fs.readdir(contentDirectory);
+ for (const directoryName of directoryNames) {
+ await processLanguage(directoryName);
+ }
}
run()
- .then(() => process.exit(0))
- .catch(error => {
- console.error(error.stack);
- process.exit(1);
- });
+ .then(() => process.exit(0))
+ .catch((error) => {
+ console.error(error.stack);
+ process.exit(1);
+ });
diff --git a/landing-pages/package.json b/landing-pages/package.json
index d760d0c..751449f 100644
--- a/landing-pages/package.json
+++ b/landing-pages/package.json
@@ -14,7 +14,7 @@
"build:webpack": "cross-env NODE_ENV=production webpack --config webpack.prod.js",
"lint": "run-p lint:**",
"lint:css": "stylelint \"site/assets/scss/**/*.scss\"",
- "lint:js": "eslint src",
+ "lint:js": "eslint .",
"prebuild": "rimraf dist",
"preview": "run-p preview:**",
"preview:hugo": "npm run start:hugo -- -D -F",
diff --git a/landing-pages/webpack.common.js b/landing-pages/webpack.common.js
index c473345..2d236e5 100644
--- a/landing-pages/webpack.common.js
+++ b/landing-pages/webpack.common.js
@@ -30,7 +30,7 @@ module.exports = {
output: {
path: path.join(__dirname, "dist"),
- publicPath: '/'
+ publicPath: "/"
},
module: {
diff --git a/landing-pages/webpack.dev.js b/landing-pages/webpack.dev.js
index cbab2c0..5373895 100644
--- a/landing-pages/webpack.dev.js
+++ b/landing-pages/webpack.dev.js
@@ -19,7 +19,7 @@
const merge = require("webpack-merge");
const path = require("path");
-const { CleanWebpackPlugin } = require('clean-webpack-plugin');
+const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const common = require("./webpack.common");
@@ -33,7 +33,7 @@ module.exports = merge(common, {
},
devServer: {
- host: '0.0.0.0',
+ host: "0.0.0.0",
port: process.env.PORT || 3000,
contentBase: path.join(process.cwd(), "./dist"),
watchContentBase: true,