Skip to content
This repository was archived by the owner on Sep 13, 2021. It is now read-only.
Open
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
7 changes: 7 additions & 0 deletions community-core-plugins/generate/.mintbean
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"title": "Generate",
"namespaces": ["generate"],
"files": ["src/commands/*.js"],
"exclude": ["node_modules"],
"protected": true
}
18 changes: 17 additions & 1 deletion community-core-plugins/generate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,21 @@
"mintbean"
],
"author": "Kyle Barnett <kmbarnett94@gmail.com> (https://kylebar.net/)",
"license": "MIT"
"license": "MIT",
"dependencies": {
"cfonts": "2.8.6",
"chalk": "4.1.0",
"ejs": "3.1.5",
"enquirer": "2.3.6",
"execa": "4.0.3",
"fs-extra": "9.0.1",
"listr": "0.14.3",
"moment": "2.29.1",
"ncp": "2.0.0",
"path": "0.12.7",
"pkg-install": "1.0.0",
"term-size": "2.2.0",
"terminal-link": "2.1.1",
"util": "0.12.3"
}
}
10 changes: 10 additions & 0 deletions community-core-plugins/generate/src/commands/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { newProject } from "../handlers/index";

// Command Definition
const generate = {
command: "mint generate [projectName]",
description: "This command will walk you through project creation. Run mint generate --help for project type specific commands",
handler: newProject,
};

export default generate;
16 changes: 16 additions & 0 deletions community-core-plugins/generate/src/commands/templates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import fs from 'fs-extra'
import path from 'path'
import { newProject } from "../handlers/index";

const TEMPLATE_CHOICES = fs.readdirSync(path.resolve(__dirname, "../../templates"));

const commandCreator = (templateName) => {
return {
command: `mint generate ${templateName} [projectName]`,
description: `This command will generate a new ${templateName} project. If a project name is not given one will be generated for you`,
handler: (argv) => newProject(argv, templateName),
};
}


export default [...TEMPLATE_CHOICES.map(commandCreator)]
75 changes: 75 additions & 0 deletions community-core-plugins/generate/src/handlers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import fs from "fs-extra";
import path from "path";
import { prompt } from "enquirer";
import chalk from "chalk";
import moment from "moment";
import { createProject } from "../services/templatingService";
import banner from '../util/banner'

// grab all folder names in teh Template Dir
const TEMPLATE_CHOICES = fs.readdirSync(path.resolve(__dirname, "../../templates"));

const generateProjectName = (templateName) => {
const month = moment().format("MM");
const day = moment().format("DD");
const year = moment().format("YYYY");
return `mintbean-${templateName}-${year}-${month}-${day}`;
};

const getProjectOptions = async (argv, templateName) => {
const QUESTIONS = [
{
name: "template",
type: "select",
message: "Choose a template for new project:",
choices: TEMPLATE_CHOICES,
skip: () => templateName,
},
{
name: "packagemgr",
type: "select",
message: "Which package manager will you use:",
choices: ["yarn", "npm"],
},
];

const answers = await prompt(QUESTIONS);

templateName = templateName || answers.template;
const packageManager = answers.packagemgr;
const projectName = argv.projectName || generateProjectName(templateName);

return {
projectName,
templateName,
packageManager,
};
};

export const newProject = async (argv, templateName) => {

banner.mintbean();
banner.sponsor();

let options = await getProjectOptions(argv, templateName);
if (argv.projectName) {
const potentialFile = path.resolve(process.cwd(), options.projectName);
const conflict = fs.pathExistsSync(potentialFile);
if (conflict) {
const clobber = await prompt([
{
name: "confirm",
type: "confirm",
message: `Whoops! Project with name '${options.projectName}' already exists. Do you want to replace it?`,
default: false,
},
]);
options.clobber = clobber.confirm;
}
if (options.clobber === false) {
console.log(chalk.red("Try again with a new project name"));
process.exit(1);
}
}
createProject({ ...options });
};
97 changes: 97 additions & 0 deletions community-core-plugins/generate/src/services/templatingService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import chalk from "chalk";
import fs from "fs-extra";
import ncp from "ncp";
import path from "path";
import { promisify } from "util";
import execa from "execa";
import Listr from "listr";
import ejs from "ejs";
import { projectInstall } from "pkg-install";

const access = promisify(fs.access);
const copy = promisify(ncp);

const copyTemplateFiles = async (options) => {
if (options.clobber) {
fs.removeSync(options.targetDir);
}
const needsEjs = [];
const transform = (read, write, file) => {
const isEjsTemplatable = fs.readFileSync(file.name).toString("utf-8");

read.pipe(write);

if (isEjsTemplatable.match(/(<%= (.*?) %>)/) !== null) {
needsEjs.push(write.path);
}

if (file.name.includes("gitignore")) {
const parentDir = path.resolve(write.path, "..");
const newPath = path.join(parentDir, ".gitignore");
fs.renameSync(write.path, newPath);
}
};

await copy(options.templateDir, options.targetDir, {
transform: transform,
});

needsEjs.forEach((file) => {
const ejsTemplatable = fs.readFileSync(file);
const ejsTemplated = ejs.compile(ejsTemplatable.toString("utf-8"))(options);
fs.writeFileSync(file, ejsTemplated);
});
}

const initGit = async (options) => {
const result = await execa("git", ["init"], {
cwd: options.targetDir,
});
if (result.failed) {
return Promise.reject(new Error("Failed to initialize git"));
}
return;
}

export async function createProject(options) {
options = {
...options,
targetDir: options.targetDir || path.join(process.cwd(), options.projectName),
};


const templateDir = path.resolve(
__dirname,
"../../templates",
options.templateName.toLowerCase(),
);

options.templateDir = templateDir;

try {
await access(templateDir, fs.constants.R_OK);
} catch (error) {
console.error(chalk.red.bold("ERR"), error);
process.exit(1);
}

const tasks = new Listr([
{
title: "Copying project files",
task: () => copyTemplateFiles(options),
},
{
title: "Initializing git",
task: () => initGit(options),
},
{
title: "Installing dependencies",
task: () =>
projectInstall({
cwd: options.targetDir,
prefer: options.packageManager,
}),
},
]);
await tasks.run();
}
57 changes: 57 additions & 0 deletions community-core-plugins/generate/src/util/banner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import CFonts from "cfonts";
import termSize from "term-size";
import terminalLink from "terminal-link";

export default {
mintbean: () => {
const { columns } = termSize();
const banner = columns >= 70 ? "Mintbean" : "Mint|Bean";
const startingMsg = "Let mintbean do the hard work... you do the coding \n";

CFonts.say(banner, {
font: "slick", // define the font face
align: "center", // define text alignment
background: "black", // define the background color
letterSpacing: 3,
space: true, // define if the output text should have empty lines on top and on the bottom
gradient: ["#02ed9d", "#009be2"], // define your two gradient colors
transitionGradient: true, // define if this is a transition between colors directly
env: "node", // define the environment CFonts is being executed in
});
CFonts.say(startingMsg, {
font: "console", // define the font face
align: "center", // define text alignment
space: true, // define if the output text should have empty lines on top and on the bottom
env: "node", // define the environment CFonts is being executed in
});
},
sponsor: () => {
const link = terminalLink("FeaturePeek", "https://featurepeek.com/");

const blurb = `FeaturePeek creates supercharged deployment |previews of your frontend that you can share with your team to quickly get feedback on |your implementation in progress. |${link}`;

CFonts.say("Sponsored by:", {
font: "console", // define the font face
align: "center", // define text alignment
space: false, // define if the output text should have empty lines on top and on the bottom
env: "node", // define the environment CFonts is being executed in
});

CFonts.say("Feature|Peek", {
font: "chrome", // define the font face
align: "center", // define text alignment
letterSpacing: 0.5, // define letter spacing
space: false, // define if the output text should have empty lines on top and on the bottom
colors: ["#05c5cc", "#05c5cc", "#05c5cc"], // define your two gradient colors
env: "node", // define the environment CFonts is being executed in
});

CFonts.say(blurb, {
font: "console", // define the font face
align: "center", // define text alignment
space: true, // define if the output text should have empty lines on top and on the bottom
env: "node", // define the environment CFonts is being executed in
maxLength: "45",
});
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# dependencies
/node_modules

# production
/build
/dist
.cache
31 changes: 31 additions & 0 deletions community-core-plugins/generate/templates/bulma-theme/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Mintbean Bulma Theme Template

## What this is

This is a Bulma theme. It is a way for developers to quickly customize Bulma for their own needs. Bulma is great in that it uses very clearly defined variables and overrides to let devs change its look and feel.

## How to use it

`npm start` OR `yarn start` will run the server. You can use it to developer your theme.

You're already set up with `src/_overrides.scss` and `src/_variables.scss` files. You don't need to do anything more to start theming.

## How to use your theme in a new site

### Option A - Just keep using this project (simple)

Delete everything inside the `body` tag of `index.html` and start from scratch.

### Option B - Copy/paste the theme over to your project (advanced)

Simply copy the contents of `src` into your new project and `@import` the `src/bulma-theme.scss` file.

To do this, you'll have to install Bulma and SCSS on your new project.

## About

This is a [Mintbean CLI](https://www.npmjs.com/package/mintbean-cli) generated project.

[Mintbean](https://mintbean.io) does hackathons almost 10 times a month! Come hack with us.

Credit for `index.html` contents goes to `bulmaswatch`.
Binary file not shown.
Loading