Skip to content

Commit

Permalink
Merge pull request #10 from jvmn/feature/2.2.0-rc
Browse files Browse the repository at this point in the history
Feature/2.2.0 rc
  • Loading branch information
xeyefex authored Jan 19, 2021
2 parents a3ab3c0 + 7024e54 commit 69146a3
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 137 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ In charge of running the dev / build / release / deploy / newpattern toolchain f
```
npm install @jvmn/groundzero-taskrunner-webpack --save-dev
```

* if you use `Twig` as your template engine you need to install them as peer dependencies
```
npm install @jvmn/groundzero-taskrunner-webpack twig @frctl/twig --save-dev
```
2) get all coomand options by running from the terminal:
```
groundzero help
Expand Down
4 changes: 4 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ case 'release':
require('./cli/release')
break

case 'export':
require('./cli/export')
break

case 'deploy':
require('./cli/deploy')
break
Expand Down
28 changes: 28 additions & 0 deletions cli/export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node
'use strict'

const { spawn } = require('child_process')
const error = require('../lib/error')
// expose project root folder varialbe to load configs in npm
process.env.PROJECT_CWD = process.env.PWD


const child = spawn(`npm explore @jvmn/groundzero-taskrunner-webpack -- npm run fractal:export`, {
stdio: 'inherit',
env: process.env,
shell: true
})

child.on('error', err => {
error(`CLI Export -> ${err}`, true)
})

if (child.stdin) {
process.stdin.pipe(child.stdin)
}

if (child.stdout) {
child.stdout.on('data', (data) => {
console.log(`child stdout:\n${data}`)
})
}
6 changes: 5 additions & 1 deletion config-templates/fractal.hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ module.exports = {
{
key: 'customVar',
cmd: 'customValue'
}
},
// {
// key: 'project.prettyHtmlConfig',
// cmd: { ocd: true, unformatted: ['script', 'style', 'code', 'pre', 'em', 'strong'] }
// }
]
}
}
Expand Down
151 changes: 87 additions & 64 deletions lib/fractal-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,117 @@ const fractal = require(path.resolve(process.env.PWD + '/fractal-config.js'))
const fs = require('fs')
const mkdirp = require('mkdirp')
const pretty = require('pretty')
const prettyHtmlConfig = { ocd: true, unformatted: ['script', 'style', 'code', 'pre', 'em', 'strong', 'span'] }
let objects = []
let objectsVars = []
let components = []
let componentsVars = []
let modules = []
let modulesVars = []
let pages = []

const cliProgress = require('cli-progress')
const prettyHtmlConfig = fractal.get('project.prettyHtmlConfig') || { ocd: true, unformatted: ['script', 'style', 'code', 'pre', 'em', 'strong', 'span'] }
const objects = []
const objectsVars = []
const components = []
const componentsVars = []
const modules = []
const modulesVars = []
const pages = []
const pagesVars = []
// create a new progress bar instance and use shades_classic theme
const progressbar = new cliProgress.SingleBar({
format: 'progress [{bar}] {percentage}% | {value}/{total} | Filename: {filename}'
}, cliProgress.Presets.shades_classic)
/*
* Run a static HTML export of modules and pages
*/
try {
fractal.components.load().then(() => {
for (let item of fractal.components.flatten()) {
fractal.components.load().then(async () => {

const promises = []
for (const item of fractal.components.flatten()) {
// if we want to render only ready cmp/pages add "item.status.label === 'Ready'" to if statement
if (item.hasTag('module')) {
const type = 'modules'
modules.push('1')
mkdirp(`${fractal.get('project.release')}/render/${type}/`).then(() => {
for (let variant of item.variants()) {
modulesVars.push('1')
let filename = variant.handle.replace(/--default$/, '')
variant.render().then(function (html) {
const prettyHtml = pretty(html, prettyHtmlConfig)
fs.writeFile(`${fractal.get('project.release')}/render/${type}/${filename}.html`, prettyHtml, function (err) {
if (err) {
console.log('file could not be written!')
}
})
mkdirp.sync(`${fractal.get('project.release')}/render/${type}/`)
for (const variant of item.variants()) {
modulesVars.push('1')
const filename = variant.handle.replace(/--default$/, '')
const promise = variant.render().then(async function (html) {
progressbar.update({ filename })
const prettyHtml = await pretty(html, prettyHtmlConfig)
await fs.writeFile(`${fractal.get('project.release')}/render/${type}/${filename}.html`, prettyHtml, function (err) {
if (err) {
console.log('file could not be written!')
}
})
}
})
progressbar.increment()
})
promises.push(promise)
}
} else if (item.hasTag('object')) {
const type = 'objects'
objects.push('1')
mkdirp(`${fractal.get('project.release')}/render/${type}/`).then(() => {
for (let variant of item.variants()) {
objectsVars.push('1')
let filename = variant.handle.replace(/--default$/, '')
variant.render().then(function (html) {
const prettyHtml = pretty(html, prettyHtmlConfig)
fs.writeFile(`${fractal.get('project.release')}/render/${type}/${filename}.html`, prettyHtml, function (err) {
if (err) {
console.log('file could not be written!')
}
})
mkdirp.sync(`${fractal.get('project.release')}/render/${type}/`)
for (const variant of item.variants()) {
objectsVars.push('1')
const filename = variant.handle.replace(/--default$/, '')
const promise = variant.render().then(async function (html) {
progressbar.update({ filename })
const prettyHtml = await pretty(html, prettyHtmlConfig)
await fs.writeFile(`${fractal.get('project.release')}/render/${type}/${filename}.html`, prettyHtml, function (err) {
if (err) {
console.log('file could not be written!')
}
})
}
})
progressbar.increment()
})
promises.push(promise)
}
} else if (item.hasTag('component')) {
const type = 'components'
components.push('1')
mkdirp(`${fractal.get('project.release')}/render/${type}/`).then(() => {
for (let variant of item.variants()) {
componentsVars.push('1')
let filename = variant.handle.replace(/--default$/, '')
variant.render().then(function (html) {
const prettyHtml = pretty(html, prettyHtmlConfig)
fs.writeFile(`${fractal.get('project.release')}/render/${type}/${filename}.html`, prettyHtml, function (err) {
if (err) {
console.log('file could not be written!')
}
})
mkdirp.sync(`${fractal.get('project.release')}/render/${type}/`)
for (const variant of item.variants()) {
componentsVars.push('1')
const filename = variant.handle.replace(/--default$/, '')
const promise = variant.render().then(async function (html) {
progressbar.update({ filename })
const prettyHtml = await pretty(html, prettyHtmlConfig)
await fs.writeFile(`${fractal.get('project.release')}/render/${type}/${filename}.html`, prettyHtml, function (err) {
if (err) {
console.log('file could not be written!')
}
})
}
})
progressbar.increment()
})
promises.push(promise)
}
} else if (item.hasTag('page')) {
const type = 'pages'
pages.push('1')
mkdirp(`${fractal.get('project.release')}/render/${type}/`).then(() => {
for (let variant of item.variants()) {
let filename = variant.handle.replace(/--default$/, '')
variant.render(item.config.context).then(function (html) {
const prettyHtml = pretty(html, prettyHtmlConfig)
fs.writeFile(`${fractal.get('project.release')}/render/${type}/${filename}.html`, prettyHtml, function(err){
if (err) {
console.log('file could not be written!')
}
})
mkdirp.sync(`${fractal.get('project.release')}/render/${type}/`)
for (const variant of item.variants()) {
pagesVars.push('1')
const filename = variant.handle.replace(/--default$/, '')
const promise = variant.render(item.config.context).then(async function (html) {
progressbar.update({ filename })
const prettyHtml = await pretty(html, prettyHtmlConfig)
await fs.writeFile(`${fractal.get('project.release')}/render/${type}/${filename}.html`, prettyHtml, function(err){
if (err) {
console.log('file could not be written!')
}
})
}
})
progressbar.increment()
})
promises.push(promise)
}
}
}
const objectsNum = objects.length > 0 ? objects.length + objectsVars.length + ' objects, ' : ''
progressbar.start(promises.length, 0, {
filename: "N/A"
})

console.log(`Exported ${objectsNum} ${components.length + componentsVars.length} components, ${modules.length + modulesVars.length} modules, ${pages.length} pages`)
return await Promise.all(promises).then(() => {
progressbar.stop()
const objectsNum = objects.length > 0 ? objects.length + objectsVars.length + ' objects, ' : ''

console.log(`Exported ${objectsNum} ${components.length + componentsVars.length} components, ${modules.length + modulesVars.length} modules, ${pages.length + pagesVars.length} pages`)
})
})
} catch (e) {
console.log(e)
Expand Down
12 changes: 11 additions & 1 deletion lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ const menus = {
dev ................ start fractal on dev mode
build .............. build fractal standalone for deploying
release ............ build a release
export ............. run a static HTML export of Fractal components, modules and pages
deploy ............. build & deploy fractal via ssh
rsync ............. deploy fractal via ssh
newpattern ......... new moudle / component boilerplate
version ............ show package version
update ............. update taskrunner to latest version
help ............... show help menu for a command`,
help ............... show help menu for a command
`,

deploy: `
groundzero deploy <options>
--stage ....... build + deploy to stage enviorment,
--all ......... build + deploy to dev and stage enviorment,
--feature ..... build + deploy a feature brance, can be combined with an env flag`,
rsync: `
groundzero rsync <options>
--stage ....... deploy to stage enviorment,
--all ......... deploy to dev and stage enviorment,
--feature ..... deploy a feature brance, can be combined with an env flag`,
Expand Down
Loading

0 comments on commit 69146a3

Please sign in to comment.