|
@@ -1,134 +0,0 @@
|
|
|
-var fs = require('fs')
|
|
|
-const sharp = require('sharp');
|
|
|
-
|
|
|
-var utilities = require('./utilities');
|
|
|
-var requirements = require('./check-requirements');
|
|
|
-
|
|
|
-const chalk = require('chalk');
|
|
|
-const logSymbols = require('log-symbols');
|
|
|
-
|
|
|
-const YAML = require('json-to-pretty-yaml');
|
|
|
-const TurndownService = require('turndown');
|
|
|
-var turndownService = new TurndownService()
|
|
|
-
|
|
|
-var list_projects = function(){
|
|
|
- var project_directories = utilities.getDirectories(global.source);
|
|
|
- var projects = []
|
|
|
-
|
|
|
-
|
|
|
- project_directories.forEach(project => {
|
|
|
- try {
|
|
|
- projects.push(JSON.parse(fs.readFileSync(`${global.source}/${project}/project.json`)));
|
|
|
- } catch(err){}
|
|
|
- });
|
|
|
- return projects;
|
|
|
-}
|
|
|
-
|
|
|
-var createProject = async function(project){
|
|
|
- var project_requirements = await requirements.hasRequirements(project);
|
|
|
-
|
|
|
- if(project_requirements.pass == 'no'){
|
|
|
- result[2] += 1;
|
|
|
- console.log(logSymbols.error, `Error creating project \'${chalk.bold(project.permalink)}\'`);
|
|
|
- requirements.requirementMessages(project, project_requirements);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- utilities.createDirectory(`source/_posts/projects/${project.permalink}`)
|
|
|
-
|
|
|
- var cover_path = `${global.source}/${project.permalink}/${project.cover_image}`
|
|
|
- var cover_ext = project.cover_image.split(".")[1];
|
|
|
- var cover_destination = `source/_posts/projects/${project.permalink}/cover.jpg`
|
|
|
- sharp(cover_path).resize(1000, 625).toFile(cover_destination);
|
|
|
- project.cover_image = `/projects/${project.permalink}/cover.jpg`
|
|
|
-
|
|
|
- sharp(cover_path).resize(550, 344).toFile(`source/_posts/projects/${project.permalink}/thumbnail.jpg`);
|
|
|
- project.thumbnail_image = `/projects/${project.permalink}/thumbnail.jpg`
|
|
|
-
|
|
|
- var hero_path, hero_ext, hero_destination;
|
|
|
- if(project.hero_image != undefined){
|
|
|
- hero_path = `${global.source}/${project.permalink}/${project.hero_image}`
|
|
|
- hero_ext = project.hero_image.split(".")[1];
|
|
|
- hero_destination = `source/_posts/projects/${project.permalink}/hero.${hero_ext}`
|
|
|
- utilities.copyFile(hero_path, hero_destination);
|
|
|
- project.hero_image = `/projects/${project.permalink}/hero.${hero_ext}`
|
|
|
- }
|
|
|
-
|
|
|
- var screenshot_data = []
|
|
|
- if(project.screenshots != undefined){
|
|
|
- if(project.screenshots.length > 0) {
|
|
|
- for (let i = 0; i < project.screenshots.length; i++) {
|
|
|
- var screenshot = project.screenshots[i];
|
|
|
- screenshot_path = `${global.source}/${project.permalink}/${screenshot.url}`
|
|
|
- screenshot_ext = project.hero_image.split(".")[1];
|
|
|
- screenshot_destination = `source/_posts/projects/${project.permalink}/screenshot-${i}.${screenshot_ext}`
|
|
|
- utilities.copyFile(screenshot_path, screenshot_destination);
|
|
|
- screenshot.url = `/projects/${project.permalink}/screenshot-${i}.${screenshot_ext}`;
|
|
|
- screenshot_data.push(screenshot)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var file = "";
|
|
|
- file += "---\n";
|
|
|
- file += `title: ${project.title}\n`;
|
|
|
- file += `folder: ${project.permalink}\n`;
|
|
|
- file += `date: ${project.start_date}\n`;
|
|
|
- file += `layout: project\n`
|
|
|
- try {
|
|
|
- var data = JSON.parse(JSON.stringify(project));
|
|
|
- delete data.title;
|
|
|
- delete data.index;
|
|
|
- delete data.status;
|
|
|
- delete data.size
|
|
|
- delete data.local_copies;
|
|
|
- delete data.folder;
|
|
|
- delete data.aws_backups;
|
|
|
- delete data.permalink;
|
|
|
- delete data.backup_folder;
|
|
|
- if(data.repositories == []) delete data.repositories;
|
|
|
- if(data.files == []) delete data.files;
|
|
|
- if(screenshot_data.length > 0) data.screenshots = screenshot_data;
|
|
|
- file += YAML.stringify(data);
|
|
|
- } catch (err){
|
|
|
- if(global.isVerbose) console.log(logSymbols.error, chalk.red('An error occured: '));
|
|
|
- if(global.isVerbose) console.log(err);
|
|
|
- }
|
|
|
- file += "---\n";
|
|
|
- if(project.text == undefined){
|
|
|
- file += project.description;
|
|
|
- } else {
|
|
|
- file += turndownService.turndown(project.text);;
|
|
|
- }
|
|
|
-
|
|
|
- var project_file_path = `source/_posts/projects/${project.permalink}.md`
|
|
|
- try {
|
|
|
- fs.writeFileSync(project_file_path, file);
|
|
|
- if(project_requirements.pass == 'all') {
|
|
|
- result[0] += 1;
|
|
|
- console.log(logSymbols.success, `Created Project \'${chalk.bold(project.permalink)}\'`);
|
|
|
- } else if(project_requirements.pass == 'some') {
|
|
|
- result[1] += 1;
|
|
|
- console.log(logSymbols.warning, `Created Project \'${chalk.bold(project.permalink)}\' with warnings`);
|
|
|
- requirements.requirementMessages(project, project_requirements);
|
|
|
- }
|
|
|
- counter += 1;
|
|
|
- } catch (err){
|
|
|
- if(global.isVerbose) console.log(logSymbols.error, chalk.red('An error occured: '));
|
|
|
- if(global.isVerbose) console.log(err);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-var result = [ 0, 0, 0]
|
|
|
-
|
|
|
-module.exports.all = async function(){
|
|
|
- console.log()
|
|
|
- var projects = list_projects();
|
|
|
- for (let i = 0; i < projects.length; i++) {
|
|
|
- await createProject(projects[i]);
|
|
|
- }
|
|
|
- console.log()
|
|
|
- console.log(chalk.green(`${result[0]} created`) + ", " + chalk.yellow(`${result[1]} created with warnings`) + ", " + chalk.red(`${result[2]} missing requirements`) + ` (TOTAL: ${projects.length})`);
|
|
|
-}
|
|
|
-
|
|
|
-module.exports.list_projects = list_projects;
|