Skip to content

Commit

Permalink
style(test/ir/package.json): 增加babel模块,将test和ir中代码改为es6规范
Browse files Browse the repository at this point in the history
  • Loading branch information
Blore-lzn authored and Thysrael committed Apr 30, 2023
1 parent 76886fc commit c2c4857
Show file tree
Hide file tree
Showing 29 changed files with 699 additions and 388 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [
[
"@babel/preset-env"
]
]
}
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test": "mocha --recursive --exit --colors",
"test:coverage": "nyc --reporter=text mocha --recursive --exit --colors",
"test": "mocha --recursive --exit --colors --require @babel/register",
"test:coverage": "nyc --reporter=text mocha --recursive --exit --colors --require @babel/register",
"commit": "git-cz",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"eslint": "eslint . --fix",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps",
"build:tailwind": "tailwind build src/renderer/assets/index.css -o src/renderer/assets/tailwind.css"
"build:tailwind": "tailwind build src/renderer/assets/index.css -o src/renderer/assets/tailwind.css",
"babel-node": "./node_modules/.bin/babel-node"
},
"main": "background.js",
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/cli": "^7.21.5",
"@babel/core": "^7.21.5",
"@babel/eslint-parser": "^7.12.16",
"@babel/node": "^7.20.7",
"@babel/preset-env": "^7.21.5",
"@popperjs/core": "^2.11.7",
"@tailwindcss/forms": "0.2.1",
"@tailwindcss/postcss7-compat": "^2.2.17",
Expand Down
56 changes: 18 additions & 38 deletions src/IR/block/base/content/base.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
const {
rootTypeName,
tableTypeName,
headingTypeName,
quoteTypeName,
mathblockTypeName,
frontmatterTypeName
} = require('../type/constant.js')

import { rootTypeName, tableTypeName, headingTypeName, quoteTypeName, mathblockTypeName, frontmatterTypeName } from '../type/constant.js'
import yaml from 'js-yaml'
class Content {
constructor (typename, text) {
this.typename = typename
Expand Down Expand Up @@ -52,9 +45,6 @@ class Content {
this.spacePreix = prefix
}
}

const yaml = require('js-yaml')

class FrontmatterContent extends Content {
constructor (text, lang, style) {
super(frontmatterTypeName, text)
Expand All @@ -77,7 +67,9 @@ class FrontmatterContent extends Content {

addTag (tagname) {
if (this.data.tags === undefined) {
this.data = { tags: [tagname] }
this.data = {
tags: [tagname]
}
} else if (!this.data.tags.includes(tagname)) {
this.data.tags.push(tagname)
}
Expand Down Expand Up @@ -105,7 +97,6 @@ class FrontmatterContent extends Content {
}
}
}

class RootContent extends Content {
constructor () {
super(rootTypeName, '')
Expand All @@ -124,7 +115,6 @@ class RootContent extends Content {
}
}
}

class ParagraphContent extends Content {
// constructor (typename, text) {
// super(typename, text)
Expand All @@ -134,7 +124,6 @@ class ParagraphContent extends Content {
return super.toMarkdown() + this.spacePreix + '\n'
}
}

class HeadingContent extends Content {
// private depth
constructor (text, depth) {
Expand All @@ -143,8 +132,7 @@ class HeadingContent extends Content {
}

toMarkdown () {
return this.normalPrefix + '#'.repeat(+this.depth) + ' ' + this.text + '\n' +
this.spacePreix + '\n'
return this.normalPrefix + '#'.repeat(+this.depth) + ' ' + this.text + '\n' + this.spacePreix + '\n'
}

getOutlineJson () {
Expand All @@ -165,7 +153,6 @@ class HeadingContent extends Content {
this.depth = depth
}
}

class CodeContent extends Content {
// private type
// private lang
Expand All @@ -191,7 +178,6 @@ class CodeContent extends Content {
return mindJson
}
}

class MathContent extends Content {
constructor (text, style) {
super(mathblockTypeName, text)
Expand All @@ -208,7 +194,6 @@ class MathContent extends Content {
return mindJson
}
}

class QuoteContent extends Content {
constructor () {
super(quoteTypeName, '')
Expand All @@ -226,7 +211,6 @@ class QuoteContent extends Content {
return '> '
}
}

class ListContent extends Content {
constructor (typename, loose, start, delimiter, marker) {
super(typename, '')
Expand Down Expand Up @@ -257,7 +241,6 @@ class ListContent extends Content {
return this.marker === undefined ? ' ' : ' '
}
}

class ListItemContent extends Content {
constructor (typename, checked) {
super(typename, '')
Expand All @@ -271,7 +254,9 @@ class ListItemContent extends Content {
getOneNormalPrefix () {
if (this.checked === undefined) {
return ''
} else { return `[${this.checked ? 'x' : ' '}] ` }
} else {
return `[${this.checked ? 'x' : ' '}] `
}
}

getMindJson () {
Expand All @@ -280,7 +265,6 @@ class ListItemContent extends Content {
return mindJson
}
}

class TableContent extends Content {
constructor (cells) {
super(tableTypeName, 'table')
Expand All @@ -293,16 +277,15 @@ class TableContent extends Content {
const row = this.cells.length
const column = this.cells[0].children.length
const tableData = []

for (const rowState of this.cells) {
tableData.push(rowState.children.map(cell => this.escapeText(cell.text.trim())))
}

const columnWidth = this.cells[0].children.map(th => ({ width: 5, align: th.meta.align }))

const columnWidth = this.cells[0].children.map(th => ({
width: 5,
align: th.meta.align
}))
let i
let j

for (i = 0; i < row; i++) {
for (j = 0; j < column; j++) {
columnWidth[j].width = Math.max(columnWidth[j].width, tableData[i][j].length + 2) // add 2, because have two space around text
Expand All @@ -312,36 +295,34 @@ class TableContent extends Content {
tableData.forEach((r, i) => {
const rs = indent + '|' + r.map((cell, j) => {
const raw = ` ${cell + ' '.repeat(columnWidth[j].width)}`

return raw.substring(0, columnWidth[j].width)
}).join('|') + '|'
result.push(rs)
if (i === 0) {
const cutOff = indent + '|' + columnWidth.map(({ width, align }) => {
const cutOff = indent + '|' + columnWidth.map(({
width,
align
}) => {
let raw = '-'.repeat(width - 2)
switch (align) {
case 'left':
raw = `:${raw} `
break

case 'center':
raw = `:${raw}:`
break

case 'right':
raw = ` ${raw}:`
break
default:
raw = ` ${raw} `
break
}

return raw
}).join('|') + '|'
result.push(cutOff)
}
})

return result.join('\n') + '\n'
}

Expand All @@ -356,8 +337,7 @@ class TableContent extends Content {
return str.replace(/([^\\])\|/g, '$1\\|')
}
}

module.exports = {
export {
Content,
RootContent,
HeadingContent,
Expand Down
23 changes: 11 additions & 12 deletions src/IR/block/base/content/file.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const { folderTypeName, tagTypeName, fileTypeName } = require('../type/constant')
const { Content } = require('./base')

const folderCategory = 0
const fileCategory = 1
const tagCategory = 2
import { folderTypeName, tagTypeName, fileTypeName } from '../type/constant'
import { Content } from './base'
const category = {
folder: 0,
file: 1,
tag: 2
}

class FileContent extends Content {
constructor (id, name, path, content) {
Expand All @@ -25,11 +26,10 @@ class FileContent extends Content {
return {
id: `${this.id}`,
name: this.name,
category: fileCategory
category: category.file
}
}
}

class FolderContent extends Content {
constructor (id, name, path) {
super(folderTypeName, name)
Expand All @@ -50,11 +50,10 @@ class FolderContent extends Content {
return {
id: `${this.id}`,
name: this.name,
category: folderCategory
category: category.folder
}
}
}

class TagContent extends Content {
constructor (id, name) {
super(tagTypeName, name)
Expand All @@ -66,12 +65,12 @@ class TagContent extends Content {
return {
id: `${this.id}`,
name: this.name,
category: tagCategory
category: category.tag
}
}
}

module.exports = {
export {
FileContent,
FolderContent,
TagContent
Expand Down
3 changes: 1 addition & 2 deletions src/IR/block/base/linkedList/linkedList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class LinkedList {
export default class LinkedList {
constructor () {
this.head = this.tail = null
this.length = 0
Expand Down Expand Up @@ -112,4 +112,3 @@ class LinkedList {
return [...this.iterator()].reduce(callback, initialValue)
}
}
module.exports = LinkedList
5 changes: 2 additions & 3 deletions src/IR/block/base/linkedList/linkedNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const LinkedList = require('./linkedList')
class LinkedNode {
import LinkedList from './linkedList'
export default class LinkedNode {
constructor () {
this.prev = this.next = null
this.parent = null
Expand Down Expand Up @@ -35,4 +35,3 @@ class LinkedNode {
return this.children.head
}
}
module.exports = LinkedNode
7 changes: 3 additions & 4 deletions src/IR/block/base/treeNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const LinkedNode = require('./linkedList/linkedNode.js')
const { headingTypeName, listTypeName, listItemTypeName, frontmatterTypeName } = require('./type/constant.js')
class TreeNode extends LinkedNode {
import LinkedNode from './linkedList/linkedNode.js'
import { headingTypeName, listTypeName, listItemTypeName, frontmatterTypeName } from './type/constant.js'
export default class TreeNode extends LinkedNode {
/**
*
* @param {string} nodeType
Expand Down Expand Up @@ -94,4 +94,3 @@ class TreeNode extends LinkedNode {
return this.content.getNodeJson()
}
}
module.exports = TreeNode
2 changes: 1 addition & 1 deletion src/IR/block/base/type/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const fileTypeName = 'file'
const folderTypeName = 'folder'
const tagTypeName = 'tag'

module.exports = {
export {
rootTypeName,
headingTypeName,
paragraphTypeName,
Expand Down
40 changes: 5 additions & 35 deletions src/IR/block/factory/buildNode.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,7 @@
const {
CodeContent,
HeadingContent,
ListContent,
ListItemContent,
MathContent,
QuoteContent,
RootContent,
TableContent,
ParagraphContent,
FrontmatterContent
} = require('../base/content/base')
const {
FolderContent,
FileContent,
TagContent
} = require('../base/content/file')
const TreeNode = require('../base/treeNode')
const {
paragraphTypeName,
quoteTypeName,
thematicBreakTypeName,
codeblockTypeName,
diagramTypeName,
htmlblockTypeName,
rootTypeName,
frontmatterTypeName,
headingTypeName,
listItemTypeName,
listTypeName,
fileTypeName,
folderTypeName,
tagTypeName
} = require('../base/type/constant')
import { CodeContent, HeadingContent, ListContent, ListItemContent, MathContent, QuoteContent, RootContent, TableContent, ParagraphContent, FrontmatterContent } from '../base/content/base'
import { FolderContent, FileContent, TagContent } from '../base/content/file'
import TreeNode from '../base/treeNode'
import { paragraphTypeName, quoteTypeName, thematicBreakTypeName, codeblockTypeName, diagramTypeName, htmlblockTypeName, rootTypeName, frontmatterTypeName, headingTypeName, listItemTypeName, listTypeName, fileTypeName, folderTypeName, tagTypeName } from '../base/type/constant'

function buildRootNode () {
return new TreeNode(rootTypeName, new RootContent())
Expand Down Expand Up @@ -97,7 +67,7 @@ function buildTagNode (id, name) {
return new TreeNode(tagTypeName, new TagContent(id, name))
}

module.exports = {
export {
buildCodeBlock,
buildDiagramBlock,
buildFrontMatter,
Expand Down
Loading

0 comments on commit c2c4857

Please sign in to comment.