Skip to content

Commit

Permalink
cli: enable single marklet file
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Oct 21, 2018
1 parent bed1083 commit 52274ac
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/cli/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { DEFAULT_PORT } = require('@marklet/dev-server')

const JS_TYPES = ['.json', '.js']
const YAML_TYPES = ['.yml', '.yaml']
const MARK_TYPES = ['.mkl', '.md']
const ALL_TYPES = [
...JS_TYPES,
...YAML_TYPES,
Expand Down Expand Up @@ -53,19 +54,23 @@ Object.assign(Object.getPrototypeOf(program), {
getOptions(filepath = '', forced = true) {
filepath = path.resolve(filepath)
let basePath = path.resolve(process.cwd(), filepath)
let options = {}
let options = { sourceType: 'project' }
try {
util.tryFindFile(filepath)
if (fs.statSync(basePath).isFile()) {
options = loadFromFile(basePath)
if (!MARK_TYPES.includes(path.extname(basePath))) {
Object.assign(options, loadFromFile(basePath))
} else {
options.sourceType = 'file'
}
} else {
let matchFound = false
basePath = path.join(basePath, 'marklet')
for (const type of ALL_TYPES) {
const filename = basePath + type
if (!fs.existsSync(filename)) continue
if (fs.statSync(filename).isFile()) {
options = loadFromFile(filename)
Object.assign(options, loadFromFile(filename))
matchFound = true
break
}
Expand Down

0 comments on commit 52274ac

Please sign in to comment.