Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
898eaa1
fix pretty print
shigma Oct 22, 2018
82300b1
add some bindings
shigma Oct 22, 2018
8c1cf2c
merge edit and watch into marklet.env
shigma Oct 22, 2018
7138b39
bump version
shigma Oct 22, 2018
3d603a2
initialize values
shigma Oct 22, 2018
9c6324c
marklet handling event bus
shigma Oct 22, 2018
b325aaa
server framework
shigma Oct 22, 2018
f362533
tiny improvement
jjyyxx Oct 23, 2018
cc73038
add some adjustments
shigma Oct 23, 2018
3a78f15
fix no editor error when watching
shigma Oct 23, 2018
a7428b1
mnemonic
shigma Oct 23, 2018
c271c7e
structure change to menus.json
shigma Oct 24, 2018
d0c8a25
add some adjustments
shigma Oct 24, 2018
9c41872
cli options support filepath
shigma Oct 24, 2018
7b775ef
path fix
jjyyxx Oct 24, 2018
5b77714
Relatively comprehensive file watch mode
jjyyxx Oct 24, 2018
28a83a4
split code
jjyyxx Oct 24, 2018
f755233
menubar
shigma Oct 24, 2018
c3b1038
almost done
shigma Oct 24, 2018
07ee5ae
some structural change
shigma Oct 24, 2018
fde21c8
add some adjustments
shigma Oct 24, 2018
d4a234d
Merge branch 'menu' into dev
shigma Oct 24, 2018
abb9470
upfate structure
shigma Oct 24, 2018
c2e0107
project framework
shigma Oct 24, 2018
87c1a4c
trying to add mnemonic support
shigma Oct 25, 2018
964473d
add some adjustments
shigma Oct 25, 2018
1a9c353
simple proj impl
jjyyxx Oct 25, 2018
56fe695
refactor
shigma Oct 25, 2018
c5a7541
add some adjustments
shigma Oct 25, 2018
1ab4e0b
Merge branch 'menu' into dev
shigma Oct 25, 2018
8e64282
Merge pull request #17 from obstudio/menu-refactor
jjyyxx Oct 25, 2018
4c5e2e5
add some adjustments
shigma Oct 26, 2018
a7a5626
tried to set colors on editor
shigma Oct 26, 2018
32967bb
Merge branch 'menu' into dev
shigma Oct 26, 2018
b256b42
lazy content
jjyyxx Oct 27, 2018
797a8dd
merge
jjyyxx Oct 27, 2018
8ad5d0a
fix entries
shigma Oct 27, 2018
fcdec72
cli into server
shigma Oct 27, 2018
754abcc
parse config
shigma Oct 27, 2018
8d697c4
add some adjustments
shigma Oct 27, 2018
c662e22
fix test & check parse options
shigma Oct 27, 2018
a72056a
Merge pull request #18 from obstudio/project-config
jjyyxx Oct 28, 2018
9b75c8e
fix some bugs
shigma Oct 28, 2018
dda77a9
Merge branch 'project-config' into dev
shigma Oct 28, 2018
2b9e3c4
file init
shigma Oct 28, 2018
84f0783
fix a critical typo
jjyyxx Oct 28, 2018
fe35b1e
Merge branch 'dev' of https://github.com/obstudio/Marklet into dev
jjyyxx Oct 28, 2018
37d5599
explorer
shigma Oct 28, 2018
76500db
path in title
shigma Oct 29, 2018
74be6b2
switch document
shigma Oct 30, 2018
f8eaaf4
using obui
shigma Oct 30, 2018
dbbac47
abstract manager
shigma Oct 31, 2018
97c4bc2
client refactor
shigma Oct 31, 2018
67b7d3d
save
shigma Oct 31, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ temp
*.tgz
*.cache.*
packages/app/main.js
packages/app/index.html
packages/monaco/index.css
packages/dev-server/themes/*.json
packages/app/index.html
32 changes: 17 additions & 15 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,25 @@ const bundle = (name, options) => new Promise((resolve, reject) => {
entry: util.resolve(name, options.entry),
resolve: {
alias: {
'@': util.resolve(name, 'temp')
'@': util.resolve(name, 'temp'),
'@@': util.resolve('..'),
}
},
output: {
path: util.resolve(name, 'dist'),
filename: options.output,
library: 'Marklet',
library: 'marklet',
libraryTarget: 'umd',
libraryExport: options.libraryExport,
globalObject: 'typeof self !== \'undefined\' ? self : this'
}
})

new webpack.ProgressPlugin().apply(compiler)

new webpack.DefinePlugin({
'process.env.MARKLET_ENV': JSON.stringify(env),
}).apply(compiler)

compiler.run((error, stat) => {
if (error) {
Expand Down Expand Up @@ -104,14 +109,15 @@ Promise.resolve().then(() => {
}).then(() => {
if (!program.server) return
mkdirIfNotExists('dev-server/dist')
mkdirIfNotExists('dev-server/dist/themes')

if (program.tsc) {
util.exec('tsc -p packages/dev-server')
}

function minifyHTML(type) {
const srcPath = util.resolve(`dev-server/src/${type}.html`)
const distPath = util.resolve(`dev-server/dist/${type}.html`)
function minifyHTML(src, dist) {
const srcPath = util.resolve(`dev-server/${src}/index.html`)
const distPath = util.resolve(`dev-server/${dist}/index.html`)
if (program.prod) {
fs.writeFileSync(
distPath,
Expand All @@ -125,14 +131,9 @@ Promise.resolve().then(() => {
}
}

minifyHTML('edit')
minifyHTML('watch')
minifyHTML('server', 'dist')

let css = ''
themes.forEach(({ key }) => {
const options = yaml.safeLoad(fs.readFileSync(util.resolve(`dev-server/themes/${key}.yaml`)))
fs.writeFileSync(util.resolve(`dev-server/themes/${key}.json`), JSON.stringify(options))
})

return sfc2js.transpile({
...sfc2jsOptions,
Expand All @@ -143,10 +144,11 @@ Promise.resolve().then(() => {
if (result.errors.length) throw result.errors.join('\n')
return Promise.all(themes.map(({ key }) => new Promise((resolve, reject) => {
const filepath = util.resolve('dev-server/themes/' + key)
const distpath = util.resolve('dev-server/dist/themes/' + key)

try {
const options = yaml.safeLoad(fs.readFileSync(filepath + '.yaml'))
fs.writeFileSync(filepath + '.json', JSON.stringify(options))
fs.writeFileSync(distpath + '.json', JSON.stringify(options))
} catch (error) {
reject(error)
}
Expand All @@ -167,7 +169,7 @@ Promise.resolve().then(() => {
fs.writeFileSync(util.resolve('dev-server/dist/themes.min.css'), css)
return new Promise((resolve, reject) => {
sass.render({
data: fs.readFileSync(util.resolve('dev-server/src/monaco.scss')).toString(),
data: fs.readFileSync(util.resolve('dev-server/client/monaco.scss')).toString(),
outputStyle: 'compressed',
}, (error, result) => {
if (error) reject(error)
Expand All @@ -176,9 +178,9 @@ Promise.resolve().then(() => {
})
})
}).then(() => bundle('dev-server', {
entry: 'dist/client.js',
entry: 'dist/client/index.js',
output: 'client.min.js',
libraryExport: 'Marklet',
libraryExport: 'default',
}))
}).catch((error) => {
console.log(error)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@sfc2js/sass": "^2.0.0",
"@types/cheerio": "^0.22.9",
"@types/js-yaml": "^3.11.2",
"@types/lodash.debounce": "^4.0.4",
"@types/node": "^10.12.0",
"@types/ws": "^6.0.1",
"ajv": "^6.5.4",
Expand Down
6 changes: 3 additions & 3 deletions packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@marklet/app",
"version": "1.0.11",
"version": "1.0.12",
"private": true,
"main": "main.js",
"author": "shigma <1700011071@pku.edu.cn>",
Expand All @@ -18,8 +18,8 @@
},
"dependencies": {
"@marklet/monaco": "^1.3.0",
"@marklet/parser": "^1.5.1",
"@marklet/renderer": "^1.3.1",
"@marklet/parser": "^1.5.2",
"@marklet/renderer": "^1.3.2",
"js-yaml": "^3.12.0",
"neat-scroll": "^2.0.1",
"vue": "^2.5.17"
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ Parse a marklet file into marklet AST.

Options:
(support config options)
-B, --no-bound prevent from recording token bounds
-f, --format [format] the output format (default: "json")
-i, --indent [length] set the indent length (default: 2)
-p, --pretty pretty printed (it overrides all other options)
```

### edit
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const path = require('path')

module.exports = program => program
.command('build [filepath|dirpath]')
.description('Build a marklet project into a website.')
Expand All @@ -6,6 +8,7 @@ module.exports = program => program
// .option('-d, --dest [path]', 'Write parsed data to file instead of stdin')
.allowConfig()
.action(function(filepath = '') {
const options = this.getOptions(filepath)
const options = this.getOptions()
options.filepath = path.resolve(process.cwd(), filepath)
console.log(options)
})
8 changes: 6 additions & 2 deletions packages/cli/commands/edit.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const open = require('opn')
const util = require('../util')
const server = require('@marklet/dev-server')

module.exports = program => program
.command('edit [filepath|dirpath]')
.description('Edit a marklet file or project.')
.allowPort()
.allowConfig()
.action(function(filepath = '') {
const options = this.getOptions(filepath, false)
.action(function(filepath) {
const options = this.getOptions()
if (filepath) {
options.filepath = util.fullPath(filepath)
}
server.edit(options)
if (this.open) {
open(`http://localhost:${options.port || 8080}`)
Expand Down
79 changes: 35 additions & 44 deletions packages/cli/commands/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,42 @@ const yaml = require('js-yaml')
const chalk = require('chalk')
const parser = require('@marklet/parser')

function printNode(node, indent = 2, back = 1) {
const space = ' '.repeat(indent - 2 * back)
const prefix = '- '.repeat(back)
if (typeof node === 'string') {
return console.log(prefix + chalk.yellow(node))
function isObject(node) {
return node === null || typeof node !== 'object'
}

function prettyPrint(node, indent = 0) {
const space = ' '.repeat(indent)
if (isObject(node)) {
if (typeof node === 'string') {
console.log(chalk.yellowBright(node))
} else {
console.log(chalk.cyanBright(node))
}
} else if (node instanceof Array) {
return node.forEach((node, index) => {
if (node instanceof Array) {
printNode(node, indent + 2, back + 1)
} else {
process.stdout.write(space + ' '.repeat(index ? back : 1))
printNode(node, indent + 2, index ? 1 : back)
}
node.forEach((node, index) => {
if (index) process.stdout.write(space)
process.stdout.write('- ')
prettyPrint(node, indent + 1)
})
}
let firstLine = !node.type
if (node.type) {
console.log(chalk.greenBright('# ' + node.type))
}
for (const key in node) {
if (key === 'type') continue
if (firstLine) {
process.stdout.write(prefix)
firstLine = false
} else {
process.stdout.write(space + ' ')
} else {
let firstLine = !node.type
if (node.type) {
console.log(chalk.redBright('\b\b# ' + node.type))
}
process.stdout.write(chalk`{cyanBright ${key}}: `)
if (typeof node[key] === 'string') {
console.log(chalk.yellow(node[key]))
} else if (typeof node[key] !== 'object') {
console.log(chalk.magentaBright(node[key]))
} else {
process.stdout.write('\n')
if (node[key] instanceof Array) {
printNode(node[key], indent + 2 * back, 1)
for (const key in node) {
if (key === 'type') continue
if (!firstLine) {
process.stdout.write(space)
} else {
process.stdout.write(space + ' ')
printNode(node[key], indent + 2 * back - 2, 0)
firstLine = false
}
process.stdout.write(chalk.magentaBright(key) + ': ')
if (!isObject(node[key])) {
process.stdout.write('\n' + space)
if (node[key] instanceof Array) process.stdout.write(' ')
}
prettyPrint(node[key], indent + 1)
}
}
}
Expand All @@ -69,17 +65,12 @@ module.exports = program => program
},
})
if (this.pretty) {
result.forEach(node => printNode(node))
return
}
switch (this.format || 'json') {
case 'json':
prettyPrint(result)
} else if (this.format === 'json' || !this.format) {
console.log(JSON.stringify(result, null, indent))
break
case 'yaml':
} else if (this.format === 'yaml') {
console.log(yaml.safeDump(result, { indent }))
break
default:
} else {
util.handleError(this.format + ' is not a supported format.')
}
})
6 changes: 4 additions & 2 deletions packages/cli/commands/watch.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const open = require('opn')
const util = require('../util')
const server = require('@marklet/dev-server')

module.exports = program => program
.command('watch [filepath|dirpath]')
.description('Watch a marklet file or project.')
.allowPort()
.allowConfig()
.action(function(filepath = '') {
const options = this.getOptions(filepath)
.action(function(filepath) {
const options = this.getOptions()
options.filepath = util.fullPath(filepath)
server.watch(options)
if (this.open) {
open(`http://localhost:${options.port || 8080}`)
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@marklet/cli",
"version": "2.0.1",
"version": "2.0.2",
"description": "A command line interface for marklet.",
"author": "jjyyxx <1449843302@qq.com>",
"contributors": [
Expand All @@ -19,11 +19,10 @@
"url": "https://github.com/obstudio/Marklet/issues"
},
"dependencies": {
"@marklet/dev-server": "^1.1.2",
"@marklet/parser": "^1.5.1",
"@marklet/dev-server": "^1.1.3",
"@marklet/parser": "^1.5.2",
"chalk": "^2.4.1",
"commander": "^2.18.0",
"js-yaml": "^3.12.0",
"opn": "^5.4.0"
}
}
Loading