Skip to content

Commit

Permalink
Merge pull request #17 from maizzle/make-commands
Browse files Browse the repository at this point in the history
Make commands
  • Loading branch information
cossssmin authored Feb 23, 2020
2 parents c3bd539 + 037c813 commit 99c34e0
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 2 deletions.
75 changes: 73 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const fs = require('fs-extra')
const path = require('path')
const cli = require('commander')
const importCwd = require('import-cwd')
const Project = require('./commands/new')
Expand All @@ -9,9 +11,78 @@ module.exports = () => {
.option('-d, --no-deps', `Don't install NPM dependencies`)
.action((path, repo, cmdObj) => Project.scaffold(path, repo, cmdObj))

cli
.command('make:layout <filename>')
.option('-d, --directory <dir>', 'directory where the file should be output')
.description('scaffold a new Layout')
.action((filename, cmdObj) => {
if (path.parse(filename).ext === '') {
throw(`Error: <filename> argument must have an extension, i.e. ${filename}.html`)
}

try {
const layout = fs.readFileSync(`${__dirname}/stubs/layout.njk`, 'utf-8')
const destination = cmdObj.directory ? path.resolve(`${cmdObj.directory}/${filename}`) : path.resolve(`${process.cwd()}/src/layouts/${filename}`)

if (fs.existsSync(destination)) {
throw(`Error: ${destination} already exists.`)
}

fs.outputFileSync(destination, layout)
console.log(`✔ Successfully created new Layout in ${destination}`)
} catch (error) {
throw error
}
})

cli
.command('make:template <filename>')
.option('-d, --directory <dir>', 'directory where the file should be output')
.description('scaffold a new Template')
.action((filename, cmdObj) => {
if (path.parse(filename).ext === '') {
throw(`Error: <filename> argument must have an extension, i.e. ${filename}.html`)
}

try {
const template = fs.readFileSync(`${__dirname}/stubs/template.njk`, 'utf-8')
const destination = cmdObj.directory ? path.resolve(`${cmdObj.directory}/${filename}`) : path.resolve(`${process.cwd()}/src/templates/${filename}`)

if (fs.existsSync(destination)) {
throw(`Error: ${destination} already exists.`)
}

fs.outputFileSync(destination, template)
console.log(`✔ Successfully created new Template in ${destination}`)
} catch (error) {
throw error
}
})

cli
.command('make:config <env>')
.option('-f, --full', 'scaffold a full config')
.description('scaffold a new Config')
.action((env, cmdObj) => {
try {
const config = fs.readFileSync(`${__dirname}/stubs/config/${cmdObj.full ? 'full' : 'base'}.js`, 'utf-8')
const destination = path.resolve(`${process.cwd()}/config.${env}.js`)

if (fs.existsSync(destination)) {
throw(`Error: ${destination} already exists.`)
}

const configString = config.replace('build_local', `build_${env}`)
fs.outputFileSync(destination, configString)
console.log(`✔ Successfully created new Config in ${destination}`)
} catch (error) {
throw error
}
})

cli
.command('build [env]')
.description(`compile email templates and output them to disk`)
.description('compile email templates and output them to disk')
.action(env => {
try {
const Maizzle = importCwd('./bootstrap')
Expand All @@ -23,7 +94,7 @@ module.exports = () => {

cli
.command('serve')
.description(`start a local development server and watch for file changes`)
.description('start a local development server and watch for file changes')
.action(() => {
try {
const Maizzle = importCwd('./bootstrap')
Expand Down
7 changes: 7 additions & 0 deletions src/stubs/config/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
build: {
destination: {
path: 'build_local',
},
},
}
108 changes: 108 additions & 0 deletions src/stubs/config/full.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
module.exports = {
doctype: 'html',
language: 'en',
charset: 'utf-8',
googleFonts: '',
baseImageURL: '',
inlineCSS: {
enabled: false,
styleToAttribute: {
'background-color': 'bgcolor',
'background-image': 'background',
'text-align': 'align',
'vertical-align': 'valign',
},
applySizeAttribute: {
width: [],
height: [],
},
excludedProperties: null,
},
cleanup: {
purgeCSS: {
content: [
'src/layouts/**/*.*',
'src/partials/**/*.*',
'src/components/**/*.*',
],
whitelist: [],
whitelistPatterns: [],
},
removeUnusedCSS: {
enabled: false,
},
replaceStrings: false,
keepOnlyAttributeSizes: {
width: [],
height: [],
},
preferBgColorAttribute: false,
},
applyExtraAttributes: {
table: {
cellpadding: 0,
cellspacing: 0,
role: 'presentation',
},
img: {
alt: ''
}
},
urlParameters: {},
prettify: {
enabled: false,
indent_inner_html: false,
ocd: true,
},
minify: {
enabled: false,
},
browsersync: {
directory: true,
notify: false,
open: false,
port: 3000,
tunnel: false,
watch: [
'src/layouts/**/*.*',
'src/partials/**/*.*',
'src/components/**/*.*',
],
},
markdown: {
baseUrl: null,
breaks: false,
gfm: true,
headerIds: false,
headerPrefix: '',
highlight: null,
langPrefix: 'language-',
mangle: true,
pendantic: false,
sanitize: false,
sanitizer: null,
silent: false,
smartLists: false,
smartypants: false,
tables: true,
xhtml: false
},
build: {
destination: {
path: 'build_local',
extension: 'html',
},
templates: {
source: 'src/templates',
filetypes: 'html|njk|nunjucks',
},
tailwind: {
css: 'src/assets/css/main.css',
config: 'tailwind.config.js',
},
assets: {
source: 'src/assets/images',
destination: 'images',
},
},
}
32 changes: 32 additions & 0 deletions src/stubs/layout.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE {{ page.doctype or 'html' }}>
<html {% if page.htmlClass %}class="{{ page.htmlClass }}"{% endif %} lang="{{ page.language or 'en' }}" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta charset="{{ page.charset or 'utf-8' }}">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="x-apple-disable-message-reformatting">
{% if page.title %}<title>{{ page.title }}</title>{% endif %}
{% if page.googleFonts %}<link href="https://fonts.googleapis.com/css?family={{ page.googleFonts }}" rel="stylesheet" media="screen">{%- endif %}
<!--[if mso]>
<xml>
<o:OfficeDocumentSettings>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<style>
table {border-collapse: collapse;}
td,th,div,p,a,h1,h2,h3,h4,h5,h6 {font-family: "Segoe UI", sans-serif; mso-line-height-rule: exactly;}
</style>
<![endif]-->
{% if css %}<style>{{ css }}</style>{% endif %}
{% block head %}{% endblock %}
</head>
<body {% if page.bodyClass %}class="{{ page.bodyClass }}"{% endif %}>
{% if page.preheader %}
<div class="hidden">{{ page.preheader }}</div>
{% endif %}

{% block template %}{% endblock %}
</body>
</html>

9 changes: 9 additions & 0 deletions src/stubs/template.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "Example title"
---

{% extends "src/layouts/default.njk" %}

{% block template %}

{% endblock %}

0 comments on commit 99c34e0

Please sign in to comment.