@mdfriday/foundry
Version:
The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.
134 lines • 3.88 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mount = void 0;
exports.newMount = newMount;
exports.newMountFromConfig = newMountFromConfig;
exports.createDefaultMounts = createDefaultMounts;
const path = __importStar(require("path"));
class Mount {
constructor(sourcePath, targetPath, language = '') {
this.sourcePath = sourcePath;
this.targetPath = targetPath;
this.language = language;
}
/**
* Get source path
*/
source() {
return this.sourcePath;
}
/**
* Get target path
*/
target() {
return this.targetPath;
}
/**
* Get language
*/
lang() {
return this.language;
}
/**
* Get component name from target path
*/
component() {
const parts = this.targetPath.split(path.sep);
return parts[0] || '';
}
/**
* Get component and name from target path
*/
componentAndName() {
const parts = this.targetPath.split(path.sep);
const component = parts[0] || '';
const name = parts.slice(1).join(path.sep);
return { component, name };
}
/**
* Create a copy of this mount
*/
copy() {
return new Mount(this.sourcePath, this.targetPath, this.language);
}
/**
* Check if this mount is equal to another
*/
equals(other) {
return this.sourcePath === other.sourcePath &&
this.targetPath === other.targetPath &&
this.language === other.language;
}
/**
* Convert to plain object
*/
toConfig() {
const config = {
sourcePath: this.sourcePath,
targetPath: this.targetPath,
};
if (this.language) {
config.language = this.language;
}
return config;
}
/**
* String representation
*/
toString() {
return `${this.sourcePath} -> ${this.targetPath} (${this.language})`;
}
}
exports.Mount = Mount;
/**
* Creates a new Mount instance
*/
function newMount(sourcePath, targetPath) {
return new Mount(sourcePath, targetPath);
}
/**
* Creates a Mount from config
*/
function newMountFromConfig(config) {
return new Mount(config.sourcePath, config.targetPath, config.language || '');
}
/**
* Creates default component mounts
*/
function createDefaultMounts(componentFolders) {
return componentFolders.map(folder => new Mount(folder, folder));
}
//# sourceMappingURL=mount.js.map