Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 2 deletions packages/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const _ = {};
_.isBoolean = require('lodash/isBoolean');

const { Site } = require('@markbind/core');
const fsUtil = require('@markbind/core/src/utils/fsUtil');
const utils = require('@markbind/core/src/utils');
const fsUtil = require('@markbind/core/built/src/utils/fsUtil');
const utils = require('@markbind/core/built/src/utils');
const {
INDEX_MARKDOWN_FILE,
INDEX_MARKBIND_FILE,
Expand Down
10,654 changes: 6,383 additions & 4,271 deletions packages/cli/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cli/src/util/cliUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const findUp = require('find-up');
const fs = require('fs-extra');
const path = require('path');

const { SITE_CONFIG_NAME } = require('@markbind/core/src/Site/constants');
const { SITE_CONFIG_NAME } = require('@markbind/core/built/src/Site/constants');

module.exports = {
findRootFolder: (userSpecifiedRoot, siteConfigPath = SITE_CONFIG_NAME) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/util/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const figlet = require('figlet');
const DailyRotateFile = require('winston-daily-rotate-file');
const winston = require('winston');

const coreLogger = require('@markbind/core/src/utils/logger');
const coreLogger = require('@markbind/core/built/src/utils/logger');

// @markbind/core's consoleTransport but with level: info
const consoleTransport = new (winston.transports.Console)({
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/unit/cliUtil.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const path = require('path');

const { SITE_JSON_DEFAULT } = require('@markbind/core/test/unit/utils/data');
const { SITE_JSON_DEFAULT } = require('@markbind/core/built/test/unit/utils/data');
const cliUtil = require('../../src/util/cliUtil');

jest.mock('fs');
Expand Down
1 change: 1 addition & 0 deletions packages/core/built/__mocks__/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('memfs');
9 changes: 9 additions & 0 deletions packages/core/built/__mocks__/gh-pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// spy on gh-pages
var ghpages = {};
ghpages.publish = function (dir, options, callback) {
// record arguments
ghpages.dir = dir;
ghpages.options = options;
callback();
};
module.exports = ghpages;
136 changes: 136 additions & 0 deletions packages/core/built/__mocks__/walk-sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/* eslint-disable */
// Mock specific functions of walk-sync module
// copied from node modules but inject mocked fs module
var fs = require('fs-extra');
var MatcherCollection = require('matcher-collection');
var ensurePosix = require('ensure-posix-path');
var path = require('path');
function handleOptions(_options) {
var options = {};
if (Array.isArray(_options)) {
options.globs = _options;
}
else if (_options) {
options = _options;
}
return options;
}
function handleRelativePath(_relativePath) {
if (_relativePath == null) {
return '';
}
else if (_relativePath.slice(-1) !== '/') {
return _relativePath + '/';
}
else {
return _relativePath;
}
}
module.exports = walkSync;
function walkSync(baseDir, _options) {
var options = handleOptions(_options);
var mapFunct;
if (options.includeBasePath) {
mapFunct = function (entry) {
return entry.basePath.split(path.sep).join('/') + '/' + entry.relativePath;
};
}
else {
mapFunct = function (entry) {
return entry.relativePath;
};
}
return _walkSync(baseDir, options).map(mapFunct);
}
module.exports.entries = function entries(baseDir, _options) {
var options = handleOptions(_options);
return _walkSync(ensurePosix(baseDir), options);
};
function _walkSync(baseDir, options, _relativePath) {
// Inside this function, prefer string concatenation to the slower path.join
// https://github.com/joyent/node/pull/6929
var relativePath = handleRelativePath(_relativePath);
var globs = options.globs;
var ignorePatterns = options.ignore;
var globMatcher, ignoreMatcher;
var results = [];
if (ignorePatterns) {
ignoreMatcher = new MatcherCollection(ignorePatterns);
}
if (globs) {
globMatcher = new MatcherCollection(globs);
}
if (globMatcher && !globMatcher.mayContain(relativePath)) {
return results;
}
var names = fs.readdirSync(baseDir + '/' + relativePath);
var entries = names.map(function (name) {
var entryRelativePath = relativePath + name;
if (ignoreMatcher && ignoreMatcher.match(entryRelativePath)) {
return;
}
var fullPath = baseDir + '/' + entryRelativePath;
var stats = getStat(fullPath);
if (stats && stats.isDirectory()) {
return new Entry(entryRelativePath + '/', baseDir, stats.mode, stats.size, stats.mtime.getTime());
}
else {
return new Entry(entryRelativePath, baseDir, stats && stats.mode, stats && stats.size, stats && stats.mtime.getTime());
}
}).filter(Boolean);
var sortedEntries = entries.sort(function (a, b) {
var aPath = a.relativePath;
var bPath = b.relativePath;
if (aPath === bPath) {
return 0;
}
else if (aPath < bPath) {
return -1;
}
else {
return 1;
}
});
for (var i = 0; i < sortedEntries.length; ++i) {
var entry = sortedEntries[i];
if (entry.isDirectory()) {
if (options.directories !== false && (!globMatcher || globMatcher.match(entry.relativePath))) {
results.push(entry);
}
results = results.concat(_walkSync(baseDir, options, entry.relativePath));
}
else {
if (!globMatcher || globMatcher.match(entry.relativePath)) {
results.push(entry);
}
}
}
return results;
}
function Entry(relativePath, basePath, mode, size, mtime) {
this.relativePath = relativePath;
this.basePath = basePath;
this.mode = mode;
this.size = size;
this.mtime = mtime;
}
Object.defineProperty(Entry.prototype, 'fullPath', {
get: function () {
return this.basePath + '/' + this.relativePath;
}
});
Entry.prototype.isDirectory = function () {
return (this.mode & 61440) === 16384;
};
function getStat(path) {
var stat;
try {
stat = fs.statSync(path);
}
catch (error) {
if (error.code !== 'ENOENT') {
throw error;
}
}
return stat;
}
4 changes: 4 additions & 0 deletions packages/core/built/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var Site = require('./src/Site');
module.exports = {
Site: Site,
};
115 changes: 115 additions & 0 deletions packages/core/built/src/External/External.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var fs = require('fs-extra');
var path = require('path');
var htmlBeautify = require('js-beautify').html;
var PageSources = require('../Page/PageSources').PageSources;
var NodeProcessor = require('../html/NodeProcessor').NodeProcessor;
var fsUtil = require('../utils/fsUtil');
/**
* Represents external files (e.g. files referenced by <panel src="...">)
* not directly included inside the generated page
*/
var External = /** @class */ (function () {
function External(externalManager, sourceFilePath) {
/**
* @type {ExternalManager}
*/
this.externalManager = externalManager;
/**
* @type {string}
*/
this.sourceFilePath = sourceFilePath;
/**
* @type {Set<string>}
*/
this.includedFiles = new Set([sourceFilePath]);
}
/**
* Generates the content of this External instance
* @param asIfAtFilePath
* @param resultPath
* @param config
* @return {Promise<External>}
*/
External.prototype.resolveDependency = function (asIfAtFilePath, resultPath, config) {
return __awaiter(this, void 0, void 0, function () {
var fileConfig, variableProcessor, pluginManager, pageSources, docId, nodeProcessor, nunjucksProcessed, mdHtmlProcessed, pluginPostRendered, outputContentHTML;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
fileConfig = __assign(__assign({}, config), { headerIdMap: {} });
variableProcessor = config.variableProcessor, pluginManager = config.pluginManager;
pageSources = new PageSources();
docId = "ext-" + fsUtil.removeExtension(path.basename(asIfAtFilePath));
nodeProcessor = new NodeProcessor(fileConfig, pageSources, variableProcessor, pluginManager, docId);
nunjucksProcessed = variableProcessor.renderWithSiteVariables(this.sourceFilePath, pageSources);
return [4 /*yield*/, nodeProcessor.process(this.sourceFilePath, nunjucksProcessed, asIfAtFilePath)];
case 1:
mdHtmlProcessed = _a.sent();
pluginPostRendered = pluginManager.postRender(nodeProcessor.frontMatter, mdHtmlProcessed);
outputContentHTML = config.disableHtmlBeautify
? pluginPostRendered
: htmlBeautify(pluginPostRendered, pluginManager.htmlBeautifyOptions);
return [4 /*yield*/, fs.outputFile(resultPath, outputContentHTML)];
case 2:
_a.sent();
pageSources.addAllToSet(this.includedFiles);
return [4 /*yield*/, this.externalManager.generateDependencies(pageSources.getDynamicIncludeSrc(), this.includedFiles)];
case 3:
_a.sent();
return [2 /*return*/, this];
}
});
});
};
return External;
}());
module.exports = {
External: External,
};
Loading