浏览代码

Added check-locle

zhixin 6 年之前
父节点
当前提交
1ccdffbdcb
共有 6 个文件被更改,包括 86 次插入44 次删除
  1. 5 5
      site/docs/api/column-options.md
  2. 7 2
      tools/README.md
  3. 6 3
      tools/check-api.js
  4. 53 0
      tools/check-locale.js
  5. 0 34
      tools/loader.mjs
  6. 15 0
      tools/package.json

+ 5 - 5
site/docs/api/column-options.md

@@ -180,8 +180,8 @@ The column options is defined in `jQuery.fn.bootstrapTable.columnDefaults`.
 - **Detail:**
 
   Set `true` to show a radio. The radio column has fixed width.
-  
-  If a value is given the Checkbox is automatically checked.  
+
+  If a value is given the Checkbox is automatically checked.
   Its also possible to check/uncheck the radio by use an formatter (return `true` to check, return `false` to uncheck).
 
 - **Default:** `false`
@@ -195,9 +195,9 @@ The column options is defined in `jQuery.fn.bootstrapTable.columnDefaults`.
 - **Detail:**
 
   Set `true` to show a checkbox. The checkbox column has fixed width.
-  
-  If a value is given the Checkbox is automatically checked.  
-  Its also possible to check/uncheck the checkbox by use an formatter (return `true` to check, return `false` to uncheck). 
+
+  If a value is given the Checkbox is automatically checked.
+  Its also possible to check/uncheck the checkbox by use an formatter (return `true` to check, return `false` to uncheck).
 
 - **Default:** `false`
 

+ 7 - 2
tools/README.md

@@ -1,7 +1,12 @@
 # Tools
 
-## check-api
+## Install
 
 ```
-node --experimental-modules --loader ./loader.mjs check-api.js
+yarn install
 ```
+
+## List
+
+* check-api: Check the docs API
+* check-locale: Check the src locale

+ 6 - 3
tools/check-api.js

@@ -1,5 +1,8 @@
-import fs from 'fs'
-import Constants from '../src/constants/index.js'
+// eslint-disable-next-line no-global-assign
+require = require('esm')(module)
+const fs = require('fs')
+const chalk = require('chalk')
+const Constants = require('../src/constants/index.js').default
 
 class API {
   constructor () {
@@ -34,7 +37,7 @@ class API {
             continue
           }
           if (!details[i + 1] || details[i + 1].indexOf(`**${name}:**`) === -1) {
-            console.log(`${key} missing ${name}`)
+            console.log(chalk.red(`[${key}] missing '${name}'`))
           }
         }
       } else {

+ 53 - 0
tools/check-locale.js

@@ -0,0 +1,53 @@
+const fs = require('fs')
+const safeEval = require('safe-eval')
+const _ = require('lodash')
+const chalk = require('chalk')
+
+const DIR = '../src/locale/'
+const readObj = text => {
+  return safeEval(text.replace('($ => {', '')
+    .replace('})(jQuery)', '')
+    .replace(/\$\.fn\.bootstrapTable\.locales\['.*'\] = /, '')
+    .replace(/\$\.extend.*/, '').trim())
+}
+const readString = (obj, text) => {
+  const lines = text.split('\n')
+  for (const key in obj) {
+    if (obj[key]) {
+      const index = _.findIndex(lines, line => line.includes(key))
+      if (Object.keys(obj).pop() === key) {
+        lines[index + 2] += ','
+      }
+      obj[key] = lines.slice(index, index + 3).join('\n')
+    }
+  }
+  return obj
+}
+const baseText = fs.readFileSync(DIR + 'bootstrap-table-en-US.js').toString()
+const baseObj = readString(readObj(baseText), baseText)
+
+fs.readdir(`${DIR}`, (err, files) => {
+  for (const file of files) {
+    if (!/\.js$/.test(file) || file === 'bootstrap-table-en-US.js') {
+      continue
+    }
+
+    console.log('-------------------------')
+    console.log(`Checking file: ${file}`)
+    console.log('-------------------------')
+
+    const text = fs.readFileSync(DIR + file).toString()
+    const obj = readString(readObj(text), text)
+    const keys = Object.keys(obj)
+    let offset = 0
+
+    for (const [i, key] of Object.keys(baseObj).entries()) {
+      if (!keys.includes(key)) {
+        console.log(chalk.red(`Missing key: '${key}'`))
+        offset++
+      } else if (keys[i - offset] !== key) {
+        console.log(chalk.red(`Order error: '${key}'`))
+      }
+    }
+  }
+})

+ 0 - 34
tools/loader.mjs

@@ -1,34 +0,0 @@
-import path from 'path'
-import process from 'process'
-import Module from 'module'
-
-const builtins = Module.builtinModules
-const JS_EXTENSIONS = new Set(['.js', '.mjs'])
-
-const baseURL = new URL('file://')
-baseURL.pathname = `${process.cwd()}/`
-
-export function resolve (specifier, parentModuleURL = baseURL, defaultResolve) {
-  if (builtins.includes(specifier)) {
-    return {
-      url: specifier,
-      format: 'builtin'
-    }
-  }
-  if (/^\.{0,2}[/]/.test(specifier) !== true && !specifier.startsWith('file:')) {
-    // For node_modules support:
-    // return defaultResolve(specifier, parentModuleURL);
-    throw new Error(
-      `imports must begin with '/', './', or '../'; '${specifier}' does not`)
-  }
-  const resolved = new URL(specifier, parentModuleURL)
-  const ext = path.extname(resolved.pathname)
-  if (!JS_EXTENSIONS.has(ext)) {
-    throw new Error(
-      `Cannot load file with non-JavaScript file extension ${ext}.`)
-  }
-  return {
-    url: resolved.href,
-    format: 'esm'
-  }
-}

+ 15 - 0
tools/package.json

@@ -0,0 +1,15 @@
+{
+  "name": "tools",
+  "version": "1.0.0",
+  "main": "index.js",
+  "license": "MIT",
+  "dependencies": {
+    "chalk": "^2.4.2",
+    "esm": "^3.2.25",
+    "safe-eval": "^0.4.1"
+  },
+  "scripts": {
+    "check-api": "node check-api",
+    "check-locale": "node check-locale"
+  }
+}