@jorgeucanorg/init
Version:
Add scully to your angular app
80 lines (79 loc) • 3.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils/utils");
const core_1 = require("@angular-devkit/core");
// @ts-ignore
function default_1(options) {
return (host, context) => {
try {
const name = options.title ? options.title : 'blog-X';
const date = new Date();
const fullDay = `${date.getMonth() + 1}-${date.getDate()}-${date.getFullYear()}`;
if (!host.exists(`./blog/${fullDay}-${name}.md`)) {
host.create(`./blog/${fullDay}-${name}.md`, `---
title: This is the blog title
description: blog description
publish: false
---
# Page X example
`);
context.logger.info(`✅️Blog ${fullDay}-${name} file created`);
}
/*
// add into scully config
try {
const content: Buffer | null = host.read(`/scully.json`);
let jsonContent;
if (content) { jsonContent = JSON.parse(content.toString()); }
/* tslint:disable:no-string-literal
jsonContent.routes['/blog/:slug'] = {
type: 'contentFolder',
slug: {
folder: './blog'
}
};
host.overwrite(`/scully.json`, JSON.stringify(jsonContent, undefined, 2));
context.logger.info('✅️ Update scully.json');
} catch (e) {
context.logger.error('Cant update scully.json');
}
*/
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 newScullyJson = utils_1.addRouteToScullyConfig(scullyJson, { name: 'blog', slug: '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}`);
// test schematics
let path = './src/files/blog-module/';
if (!host.getDir('./src').subdirs.find(x => x === 'add-component')) {
// prod
path = './node_modules/@herodevs/init/src/files/blog-module/';
}
// create blog module and files
const files = host.getDir(path).subfiles;
// read file and create
files.forEach((fileName) => {
const src = `${path}${fileName}`;
const file = (host.read(src)).toString();
host.overwrite(`./src/app/blog/${fileName}`, file);
});
}
catch (e) { }
};
}
exports.default = default_1;
//# sourceMappingURL=index.js.map