Skip to content

Commit

Permalink
Merge pull request #1 from Sunny-fr/feat/addTemplates
Browse files Browse the repository at this point in the history
Adding Templates
  • Loading branch information
Sunny-fr authored Jul 7, 2020
2 parents b9d74fd + d46ab25 commit fc734e7
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 33 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chimp-cli",
"version": "1.0.0",
"version": "2.0.0",
"description": "Purpose Chimp cli will make your life easier to edit your chimp recipes This cli will allow you to use your own IDE to edit your recipe. It will also allow you use others tools (sass / js bundle and so on) It includes a live reload tool",
"main": "src/index.js",
"bin": {
Expand All @@ -26,7 +26,7 @@
"devDependencies": {},
"homepage": "https://github.com/sunny-fr/chimp-cli",
"repository": {
"type" : "git",
"url" : "https://github.com/sunny-fr/chimp-cli"
"type": "git",
"url": "https://github.com/sunny-fr/chimp-cli"
}
}
48 changes: 28 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const chalk = require('chalk')
const cliSelect = require('cli-select');
const cliSelect = require('cli-select')
const showWelcomeMessage = require('./messages/welcome')

const cli = () => {
Expand All @@ -10,21 +10,31 @@ const cli = () => {

const deploy = () => require('./deploy')
const watch = () => require('./watch')
const simple = () => require('./templates/simple')
const rollup = () => require('./templates/rollup')

const dispatch = (task) => {
if (task === 'deploy') {
return deploy()
}
if (task === 'watch') {
return watch()
}

if (args.length < 1) {
console.log('')
console.log('')
console.log('no available command for ' + task)
console.log('')
console.log('')
switch (task) {
case 'deploy': {
return deploy()
}
case 'watch': {
return watch()
}
case 'generate simple template': {
return simple()
}
case 'generate rollup template': {
return rollup()
}
default: {
console.log('')
console.log('')
console.log('no available command for ' + task)
console.log('')
console.log('')
}
}


Expand All @@ -37,17 +47,17 @@ const cli = () => {
console.log('What do you want to do ?')
console.log('')
cliSelect({
values: ['watch', 'deploy'],
values: ['watch', 'deploy', 'generate simple template', 'generate rollup template'],
valueRenderer: (value, selected) => {
if (selected) {
return chalk.underline(value);
return chalk.underline(value)
}

return value;
return value
},
}).then((response) => {
dispatch(response.value)
});
dispatch(response.value)
})

return
}
Expand All @@ -56,8 +66,6 @@ const cli = () => {
dispatch(args[0])




}

cli()
Expand Down
6 changes: 3 additions & 3 deletions src/messages/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
const boxen = require('boxen')
const chalk = require("chalk");

const greeting = chalk.white.bold('ITS DONE !!')
const greeting = chalk.white(' 🐵 \n It\'s done! \n Happy Coding!')

const boxenOptions = {
padding: 1,
margin: 1,
borderStyle: 'round',
borderColor: 'yellow',
backgroundColor: '#555555'
borderColor: '#18acff',
backgroundColor: '#555555',
}

const showSuccessMessage = () => console.log(boxen(greeting, boxenOptions))
Expand Down
4 changes: 2 additions & 2 deletions src/messages/welcome.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const boxen = require('boxen')
const chalk = require("chalk");

const greeting = chalk.white.bold(' 🐵 Welcome chimp cli 🐵️ ')
const greeting = chalk.white(' 🐵 \n chimp cli welcome! \n https://chimp.fr')

const boxenOptions = {
padding: 1,
margin: 1,
borderStyle: 'round',
borderColor: '#18acff',
backgroundColor: '#555555'
backgroundColor: '#555555',
}

const showWelcomeMessage = () => console.log(boxen(greeting, boxenOptions))
Expand Down
66 changes: 66 additions & 0 deletions src/templates/rollup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const config = require('../config')
const {configExistAndValid} = require('../core/management')
const Generate = require('../utils/Generate')
const path = require('path')
const fs = require('fs')
const chalk = require('chalk')
const execSync = require('child_process').execSync
const showSuccess = require('../messages/success')


function start() {
configExistAndValid({config})
.then(chimpConfig => {
let packagePath = path.dirname(require.resolve('./rollup/.chimp-cfg'));


console.log('')
console.log('')
console.log(chalk.green(' Generating Files for Rollup + Sass Template... '))
console.log('')
console.log('')


new Generate({
templatePath: packagePath,
targetPath: process.cwd(),
chimpConfig
}).build().then(() => {
fs.unlinkSync(process.cwd() + '/.chimp-config')
fs.renameSync('.chimp-cfg', '.chimp-config')

console.log('')
console.log('')
console.log(chalk.green(' Installing dependencies '))
console.log(chalk.green(' running npm install for you '))
console.log(chalk.green(' '))
console.log(chalk.green(' please wait... '))
console.log('')
console.log('')

execSync('npm install',{stdio:[0,1,2]})

console.log('')
console.log('')

showSuccess()

console.log('')
console.log('')
console.log(chalk.green(' You can now run again : chimp '))
console.log(chalk.green(' and choose the option of watching or deploying '))
console.log(chalk.green(' you recipe ! '))
console.log('')
console.log('')



})
})
.catch(e => {
console.log('Main error')
console.log(e)
})
}

start()
18 changes: 18 additions & 0 deletions src/templates/rollup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.DS_Store

# IDE Files
#-------------------------
.idea*


## Sublime Text cache files
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
*.sublime-workspace
*.sublime-project
package-lock.json

build
node_modules
.chimp-cfg
30 changes: 30 additions & 0 deletions src/templates/rollup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "{recipe-slug}",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "chimp",
"chimp:watch": "chimp watch",
"chimp:deploy": "chimp deploy",
"rollup:bundle": "rollup -c ./rollup.config.js",
"rollup:watch": "rollup -c ./rollup.config.js -w",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@babel/core": "^7.10.0",
"animate.css": "^4.1.0",
"rollup": "^2.6.1",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-peer-deps-external": "^2.2.2",
"rollup-plugin-sass": "^1.2.2"
},
"devDependencies": {
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-postcss": "^3.1.1",
"rollup-plugin-terser": "^6.1.0"
}
}
37 changes: 37 additions & 0 deletions src/templates/rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import postcss from 'rollup-plugin-postcss';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import {terser} from 'rollup-plugin-terser'

export default {
input: './src/main.js',

output: [
{
name: 'comlib',
sourcemap: false,
file: './build/bundle.js',
format: 'umd',
globals: { react: 'React' },
},
],

plugins: [
peerDepsExternal(),
postcss({
output: './build/bundle.css',
extract: true,
modules: true,
use: ['sass'],
minimize: true
}),
babel({ exclude: 'node_modules/**' }),
resolve(),
commonjs(),
terser()
],

external: ['react', 'react-dom'],
};
7 changes: 7 additions & 0 deletions src/templates/rollup/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import styles from './style.scss'

function main() {
console.log('hello world')
}

main()
Empty file.
47 changes: 47 additions & 0 deletions src/templates/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const config = require('../config')
const {configExistAndValid} = require('../core/management')
const Generate = require('../utils/Generate')
const path = require('path')
const fs = require('fs')
const chalk = require('chalk')

function start() {
configExistAndValid({config})
.then(chimpConfig => {
let packagePath = path.dirname(require.resolve('./simple/.chimp-cfg'));


console.log('')
console.log('')
console.log(chalk.green(' Generating Files for Simple Template... '))
console.log('')
console.log('')


new Generate({
templatePath: packagePath,
targetPath: process.cwd(),
chimpConfig
}).build().then(() => {
fs.unlinkSync(process.cwd() + '/.chimp-config')
fs.renameSync('.chimp-cfg', '.chimp-config')

console.log('')
console.log('')
console.log(chalk.green(' --- I T \' S D O N E ---' ))
console.log(chalk.green(' happy coding !'))
console.log(chalk.green(''))
console.log(chalk.green(' You can now run again : chimp '))
console.log(chalk.green(' and choose the option of watching or deploying '))
console.log(chalk.green(' you recipe ! '))
console.log('')
console.log('')
})
})
.catch(e => {
console.log('Main error')
console.log(e)
})
}

start()
18 changes: 18 additions & 0 deletions src/templates/simple/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.DS_Store

# IDE Files
#-------------------------
.idea*


## Sublime Text cache files
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
*.sublime-workspace
*.sublime-project
package-lock.json

build
node_modules
.chimp-cfg
Empty file.
Empty file.
Loading

0 comments on commit fc734e7

Please sign in to comment.