-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.DS_Store | ||
.idea | ||
.vscode | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const pagesEntry = require( './pagesEntry' ) | ||
module.exports = { | ||
pagesEntry | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict' | ||
const fs = require('fs') | ||
const path = require( 'path' ) | ||
const { walk4Obj } = require('./util') | ||
const exp4parse = /\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\/|\/\/[^\r\n]*|\s/g | ||
|
||
// 获取指定目录下符合glob的所有文件 | ||
module.exports = function pagesEntry(file) { | ||
let entries = {}, | ||
txt = '', | ||
mainObj = {}, | ||
pages, | ||
subpackages | ||
|
||
try { | ||
txt = fs.readFileSync(file,'utf8') | ||
txt = txt.replace(exp4parse,'') | ||
mainObj = walk4Obj(txt,'exportdefault')['config'] || {} | ||
|
||
pages = mainObj.pages || [] | ||
subpackages = mainObj.subpackages || mainObj.subPackages || [] | ||
|
||
pages.forEach(p=>{ | ||
entries[p] = path.resolve(`src/${p}.js`) | ||
}) | ||
subpackages.forEach(sp=>{ | ||
let {root, pages} = sp | ||
if(root && pages.length>0){ | ||
pages.forEach(p=>{ | ||
entries[`${root}/${p}`] = path.resolve(`src/${root}/${p}.js`) | ||
}) | ||
} | ||
}) | ||
|
||
} catch (e) { | ||
console.log(e) | ||
} | ||
|
||
return entries | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const path = require( 'path' ) | ||
const json5 = require('json5') | ||
|
||
function resolve (...args) { | ||
return path.resolve( __dirname, '../', ...args) | ||
} | ||
|
||
function walk4Obj (txt, startStr) { | ||
if(typeof txt !== 'string' || typeof startStr !== 'string'){ | ||
return console.log('Props error') | ||
} | ||
let index = txt.indexOf(startStr), | ||
resault = {}, | ||
begin = index + startStr.length, | ||
end = begin | ||
|
||
try{ | ||
if(index>0){ | ||
for(let _i = begin, _l=txt.length, _a=0;_i<_l;_i++) { | ||
switch(txt.charAt(_i) || '') { | ||
case '{': _a ++ | ||
break | ||
case '}': _a -- | ||
break | ||
default : break | ||
} | ||
if(_a <= 0) { | ||
end = _i | ||
break | ||
} | ||
} | ||
resault = json5.parse(txt.substring(begin,end+1)) | ||
} | ||
|
||
} catch (e) { | ||
console.log(e) | ||
} | ||
return resault | ||
} | ||
|
||
module.exports = { | ||
resolve, | ||
walk4Obj | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@megalo/entry", | ||
"version": "0.0.1", | ||
"description": "", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/megalojs/megalo-entry.git" | ||
}, | ||
"keywords": [ | ||
"megalo" | ||
], | ||
"files": [ | ||
"lib" | ||
], | ||
"author": "zwwill <https://github.com/zwwill>", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/megalojs/megalo-entry/issues" | ||
}, | ||
"homepage": "https://github.com/megalojs/megalo-entry#readme", | ||
"dependencies": { | ||
"json5": "^2.1.0" | ||
} | ||
} |