UNPKG

@jorgeucanorg/init

Version:

Add scully to your angular app

76 lines (75 loc) 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const schematics_1 = require("@angular-devkit/schematics"); const core_1 = require("@angular-devkit/core"); const utils_1 = require("../utils/utils"); function default_1(options) { return (host, context) => { try { options.name = options.name ? options.name : 'blog'; const name = options.name; const date = new Date(); const fullDay = `${date.getMonth() + 1}-${date.getDate()}-${date.getFullYear()}`; const path = `./${name}/${fullDay}-${name}.md`; if (!host.exists(path)) { host.create(path, `--- title: This is the ${name} description: ${name} description publish: false --- # Page ${name} example `); context.logger.info(`✅ ${fullDay}-${name} file created`); } let scullyJson; try { scullyJson = (host.read('/scully.config.js')).toString(); } catch (e) { // for test in schematics scullyJson = `exports.config = { routes: { '/demo/:id': { type: 'fake', numberOfPages: 100 }, }, };`; } const slug = options.slug ? options.slug : 'id'; const newScullyJson = utils_1.addRouteToScullyConfig(scullyJson, { name, slug, type: 'contentFolder' }); host.overwrite(`/scully.config.js`, newScullyJson); context.logger.info('✅️ Update scully.config.js'); options.path = options.path ? options.path : core_1.strings.dasherize(`./src/app/${name}`); const templateSource = applyWithOverwrite(schematics_1.url('../files/markdown-module'), [ schematics_1.applyTemplates({ classify: core_1.strings.classify, dasherize: core_1.strings.dasherize, name: options.name }), schematics_1.move(core_1.normalize(options.path)) ]); return schematics_1.chain([ templateSource ]); } catch (e) { } }; } exports.default = default_1; function applyWithOverwrite(source, rules) { return (tree, context) => { const rule = schematics_1.mergeWith(schematics_1.apply(source, [ ...rules, schematics_1.forEach((fileEntry) => { if (tree.exists(fileEntry.path)) { tree.overwrite(fileEntry.path, fileEntry.content); return null; } return fileEntry; }), ])); return rule(tree, context); }; } //# sourceMappingURL=index.js.map