Comparing version 1.0.4-alpha-3 to 1.0.5-alpha-1
@@ -37,7 +37,21 @@ 'use strict'; | ||
var CREATE_MENU = app.STAGES.CREATE_MENU; | ||
var _app$STAGES = app.STAGES, | ||
GET_CHANGED_FILES = _app$STAGES.GET_CHANGED_FILES, | ||
GET_CHANGED_ENTRY_FILES = _app$STAGES.GET_CHANGED_ENTRY_FILES, | ||
AFTER_FILE_PROCESS = _app$STAGES.AFTER_FILE_PROCESS, | ||
CREATE_MENU = _app$STAGES.CREATE_MENU; | ||
on(CREATE_MENU, function () { | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(menu, updateEntryInfos) { | ||
var metaInfos, entryPaths, keyMap; | ||
var isMetaChange = void 0; | ||
var isEntryFileChange = void 0; | ||
on(GET_CHANGED_FILES, function (fileInfos) { | ||
isMetaChange = fileInfos.some(function (info) { | ||
return (/meta\.json$/.test(info.path) | ||
); | ||
}); | ||
}); | ||
on(GET_CHANGED_ENTRY_FILES, function () { | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(entryInfos) { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
@@ -47,21 +61,64 @@ while (1) { | ||
case 0: | ||
_context.next = 2; | ||
isEntryFileChange = !!entryInfos.length; | ||
case 1: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, _this); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
on(AFTER_FILE_PROCESS, (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (!(isMetaChange && !isEntryFileChange)) { | ||
_context2.next = 3; | ||
break; | ||
} | ||
_context2.next = 3; | ||
return app.module.menu.generateAndStore(); | ||
case 3: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, _this); | ||
}))); | ||
on(CREATE_MENU, function () { | ||
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(menu, updateEntryInfos) { | ||
var metaInfos, entryPaths, keyMap; | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.next = 2; | ||
return app.getFileInfos(/meta\.json$/); | ||
case 2: | ||
metaInfos = _context.sent; | ||
metaInfos = _context3.sent; | ||
if ((0, _utils.isValidArray)(metaInfos)) { | ||
_context.next = 5; | ||
_context3.next = 5; | ||
break; | ||
} | ||
return _context.abrupt('return'); | ||
return _context3.abrupt('return'); | ||
case 5: | ||
_context.next = 7; | ||
_context3.next = 7; | ||
return app.getEntryPaths(); | ||
case 7: | ||
entryPaths = _context.sent; | ||
entryPaths = _context3.sent; | ||
keyMap = entryPaths.reduce(function (map, path) { | ||
@@ -71,3 +128,3 @@ map[(0, _utils.removeExt)(path, '.md')] = true; | ||
}, {}); | ||
return _context.abrupt('return', metaInfos.reduce(function (menu, info) { | ||
return _context3.abrupt('return', metaInfos.reduce(function (menu, info) { | ||
var meta = void 0; | ||
@@ -109,10 +166,10 @@ | ||
case 'end': | ||
return _context.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee, _this); | ||
}, _callee3, _this); | ||
})); | ||
return function (_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
return function (_x2, _x3) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
@@ -119,0 +176,0 @@ }()); |
@@ -92,3 +92,3 @@ 'use strict'; | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(sourceName) { | ||
var _module, loader, file, parser, menu, hook, sources, _ref2, _ref2$change, change, _ref2$remove, remove, docInfos, menuInfo; | ||
var _module, loader, file, parser, menu, hook, sources, _ref2, _ref2$change, change, _ref2$remove, remove; | ||
@@ -123,3 +123,3 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
if (!(change.length + remove.length > 0)) { | ||
_context.next = 25; | ||
_context.next = 19; | ||
break; | ||
@@ -129,26 +129,16 @@ } | ||
_context.next = 17; | ||
return parser.parse(change); | ||
return parser.parseAndStore(change, remove); | ||
case 17: | ||
docInfos = _context.sent; | ||
_context.next = 20; | ||
return parser.store(docInfos, remove); | ||
_context.next = 19; | ||
return menu.generateAndStore(); | ||
case 20: | ||
_context.next = 22; | ||
return menu.generate(); | ||
case 22: | ||
menuInfo = _context.sent; | ||
_context.next = 25; | ||
return menu.store(menuInfo); | ||
case 25: | ||
_context.next = 27; | ||
case 19: | ||
_context.next = 21; | ||
return hook.exec(hook.STAGES.DONE); | ||
case 27: | ||
case 21: | ||
this.logger.info('[kram] execution done.'); | ||
case 28: | ||
case 22: | ||
case 'end': | ||
@@ -155,0 +145,0 @@ return _context.stop(); |
@@ -46,3 +46,3 @@ 'use strict'; | ||
exist = _context.sent; | ||
type = !exist ? 'add' : exist.md5 === info.md5 ? 'modify' : 'nochange'; | ||
type = !exist ? 'add' : exist.md5 === info.md5 ? 'nochange' : 'modify'; | ||
return _context.abrupt('return', Object.assign({}, info, { type: type })); | ||
@@ -487,3 +487,3 @@ | ||
_context10.next = 18; | ||
return hook.exec(_stage.GET_CHANGE_ENTRY_FILES, entryInfos); | ||
return hook.exec(_stage.GET_CHANGED_ENTRY_FILES, entryInfos); | ||
@@ -490,0 +490,0 @@ case 18: |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.STAGE_SET = exports.STAGES = exports.RENDER_STAGES = exports.DONE = exports.RENDER_PREFIX = exports.CREATE_MENU = exports.CREATE_DOC_STORE_OBJECT = exports.AFTER_PARSE = exports.BEFORE_PARSE = exports.AFTER_FILE_PROCESS = exports.GET_CHANGE_ENTRY_FILES = exports.GET_CHANGED_FILES = exports.GET_ORIGINAL_FILES = exports.AFTER_LOAD = exports.BEFORE_LOAD = exports.START = undefined; | ||
exports.STAGE_SET = exports.STAGES = exports.RENDER_STAGES = exports.DONE = exports.RENDER_PREFIX = exports.CREATE_MENU = exports.CREATE_DOC_STORE_OBJECT = exports.AFTER_PARSE = exports.BEFORE_PARSE = exports.AFTER_FILE_PROCESS = exports.GET_CHANGED_ENTRY_FILES = exports.GET_CHANGED_FILES = exports.GET_ORIGINAL_FILES = exports.AFTER_LOAD = exports.BEFORE_LOAD = exports.START = undefined; | ||
@@ -21,3 +21,3 @@ var _renderer = require('../parser/renderer'); | ||
var GET_CHANGED_FILES = exports.GET_CHANGED_FILES = 'getChangedFiles'; | ||
var GET_CHANGE_ENTRY_FILES = exports.GET_CHANGE_ENTRY_FILES = 'getChangedEntryFiles'; | ||
var GET_CHANGED_ENTRY_FILES = exports.GET_CHANGED_ENTRY_FILES = 'getChangedEntryFiles'; | ||
var AFTER_FILE_PROCESS = exports.AFTER_FILE_PROCESS = 'afterFileProcess'; | ||
@@ -48,3 +48,3 @@ | ||
GET_CHANGED_FILES: GET_CHANGED_FILES, | ||
GET_CHANGE_ENTRY_FILES: GET_CHANGE_ENTRY_FILES, | ||
GET_CHANGED_ENTRY_FILES: GET_CHANGED_ENTRY_FILES, | ||
AFTER_FILE_PROCESS: AFTER_FILE_PROCESS, | ||
@@ -51,0 +51,0 @@ |
@@ -184,2 +184,31 @@ 'use strict'; | ||
return store; | ||
}(), | ||
generateAndStore: function () { | ||
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() { | ||
var menuInfo; | ||
return _regenerator2.default.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
_context6.next = 2; | ||
return menuModule.generate(); | ||
case 2: | ||
menuInfo = _context6.sent; | ||
_context6.next = 5; | ||
return menuModule.store(menuInfo); | ||
case 5: | ||
case 'end': | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee6, this); | ||
})); | ||
function generateAndStore() { | ||
return _ref6.apply(this, arguments); | ||
} | ||
return generateAndStore; | ||
}() | ||
@@ -214,2 +243,4 @@ }; | ||
return obj; | ||
}).sort(function (a, b) { | ||
return a.path.localeCompare(b); | ||
}).reduce(function (tree, info) { | ||
@@ -216,0 +247,0 @@ return appendToTree(tree, info.levels, info); |
@@ -214,2 +214,31 @@ 'use strict'; | ||
}(), | ||
parseAndStore: function () { | ||
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(change, remove) { | ||
var docInfos; | ||
return _regenerator2.default.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context5.next = 2; | ||
return parser.parse(change); | ||
case 2: | ||
docInfos = _context5.sent; | ||
_context5.next = 5; | ||
return parser.store(docInfos, remove); | ||
case 5: | ||
case 'end': | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
})); | ||
function parseAndStore(_x5, _x6) { | ||
return _ref5.apply(this, arguments); | ||
} | ||
return parseAndStore; | ||
}(), | ||
get: function get(path) { | ||
@@ -216,0 +245,0 @@ return app.store.get('doc', path); |
@@ -19,4 +19,26 @@ /** | ||
apply(on, app) { | ||
const CREATE_MENU = app.STAGES.CREATE_MENU; | ||
const { | ||
GET_CHANGED_FILES, | ||
GET_CHANGED_ENTRY_FILES, | ||
AFTER_FILE_PROCESS, | ||
CREATE_MENU | ||
} = app.STAGES; | ||
let isMetaChange; | ||
let isEntryFileChange; | ||
on(GET_CHANGED_FILES, fileInfos => { | ||
isMetaChange = fileInfos.some(info => /meta\.json$/.test(info.path)); | ||
}); | ||
on(GET_CHANGED_ENTRY_FILES, async entryInfos => { | ||
isEntryFileChange = !!entryInfos.length; | ||
}); | ||
on(AFTER_FILE_PROCESS, async () => { | ||
if (isMetaChange && !isEntryFileChange) { | ||
await app.module.menu.generateAndStore(); | ||
} | ||
}); | ||
on(CREATE_MENU, async (menu, updateEntryInfos) => { | ||
@@ -23,0 +45,0 @@ let metaInfos = await app.getFileInfos(/meta\.json$/); |
@@ -58,7 +58,4 @@ /** | ||
if (change.length + remove.length > 0) { | ||
let docInfos = await parser.parse(change); | ||
await parser.store(docInfos, remove); | ||
let menuInfo = await menu.generate(); | ||
await menu.store(menuInfo); | ||
await parser.parseAndStore(change, remove); | ||
await menu.generateAndStore(); | ||
} | ||
@@ -65,0 +62,0 @@ |
@@ -30,3 +30,3 @@ /** | ||
GET_CHANGED_FILES, | ||
GET_CHANGE_ENTRY_FILES, | ||
GET_CHANGED_ENTRY_FILES, | ||
AFTER_FILE_PROCESS | ||
@@ -50,3 +50,3 @@ } from './hook/stage'; | ||
: exist.md5 === info.md5 | ||
? 'modify' : 'nochange'; | ||
? 'nochange' : 'modify'; | ||
@@ -194,15 +194,10 @@ return Object.assign({}, info, {type}); | ||
let infos = await getFileInfos(sources); | ||
infos = await hook.exec(GET_ORIGINAL_FILES, infos); | ||
infos = await getChangeFileInfos(infos); | ||
infos = await hook.exec(GET_CHANGED_FILES, infos); | ||
await update(FILE_INFOS, FILE_PATHS, infos); | ||
let entryInfos = infos.filter(info => path.extname(info.path) === '.md'); | ||
entryInfos = await hook.exec(GET_CHANGE_ENTRY_FILES, entryInfos); | ||
entryInfos = await hook.exec(GET_CHANGED_ENTRY_FILES, entryInfos); | ||
await update(ENTRY_INFOS, ENTRY_PATHS, entryInfos); | ||
@@ -209,0 +204,0 @@ |
@@ -14,3 +14,3 @@ /** | ||
export const GET_CHANGED_FILES = 'getChangedFiles'; | ||
export const GET_CHANGE_ENTRY_FILES = 'getChangedEntryFiles'; | ||
export const GET_CHANGED_ENTRY_FILES = 'getChangedEntryFiles'; | ||
export const AFTER_FILE_PROCESS = 'afterFileProcess'; | ||
@@ -44,3 +44,3 @@ | ||
GET_CHANGED_FILES, | ||
GET_CHANGE_ENTRY_FILES, | ||
GET_CHANGED_ENTRY_FILES, | ||
AFTER_FILE_PROCESS, | ||
@@ -47,0 +47,0 @@ |
@@ -49,2 +49,6 @@ /** | ||
await app.store.set('menu', 'all', menu); | ||
}, | ||
async generateAndStore() { | ||
let menuInfo = await menuModule.generate(); | ||
await menuModule.store(menuInfo); | ||
} | ||
@@ -72,2 +76,3 @@ }; | ||
}) | ||
.sort((a, b) => a.path.localeCompare(b)) | ||
.reduce((tree, info) => appendToTree(tree, info.levels, info), []); | ||
@@ -74,0 +79,0 @@ |
@@ -112,2 +112,7 @@ /** | ||
async parseAndStore(change, remove) { | ||
let docInfos = await parser.parse(change); | ||
await parser.store(docInfos, remove); | ||
}, | ||
get(path) { | ||
@@ -114,0 +119,0 @@ return app.store.get('doc', path); |
{ | ||
"name": "kram", | ||
"version": "1.0.4-alpha-3", | ||
"version": "1.0.5-alpha-1", | ||
"description": "基于 marked、highlight.js 的文档编译系统", | ||
@@ -5,0 +5,0 @@ "author": { |
221533
5893