Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yago committed Jun 15, 2018
2 parents f493c8f + 87a418c commit bab9f02
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 5,786 deletions.
66 changes: 35 additions & 31 deletions generators/app/index.js
Expand Up @@ -4,6 +4,8 @@ const chalk = require('chalk');
const slug = require('slug');
const curl = require('curlrequest');

const checkUpdate = require('../check-update');

/* eslint-disable */
const toolboxSay = function() {
return ' '+'\n'+
Expand All @@ -26,13 +28,9 @@ const toolboxSay = function() {
/* eslint-enable */

module.exports = class extends Generator {
initializing() {
notifyUpdates: () => {
require('update-notifier')({ pkg: require(path.resolve(__dirname, '../../package.json')), updateCheckInterval: 1}).notify({ defer: false });
}
}
async prompting() {
await checkUpdate().then(res => this.log(res));

prompting() {
// Have Yeoman greet the user.
this.log(toolboxSay());

Expand Down Expand Up @@ -69,17 +67,18 @@ module.exports = class extends Generator {
checked: true
}]
}, {
type: 'list',
name: 'icons',
message: 'How should your icons be generated?',
default: 'svg',
choices: [{
name: 'I want the SVG icons goodness',
value: 'svg'
}, {
name: 'Gimme good old font icons.',
value: 'font'
}]
type: 'input',
name: 'atomic',
message: 'What kind of components hierarchy do you want to use ?\n Separated by a less-than sign (<)',
store: true,
default: 'atoms<molecules<organisms',
validate: (input) => {
if (!input.includes('<') || input.includes(' ')) {
this.log(`\n${chalk.red(' Please enter a valid hierarchy using "<" and no spaces')}\n`);
return false;
}
return true;
}
}, {
type: 'input',
name: 'src',
Expand All @@ -90,7 +89,7 @@ module.exports = class extends Generator {
type: 'input',
name: 'dest',
message: 'Where would you like to put your build?',
default: function (answers) {
default: (answers) => {
return answers.src.indexOf('assets') !== -1 ? answers.src.replace(/assets\/?$/, 'build/') : 'build/'; // eslint-disable-line
},
store: true
Expand Down Expand Up @@ -154,7 +153,7 @@ module.exports = class extends Generator {
src: this.props.src,
dest: this.props.dest,
assets: this.props.src,
remote: this.props.remote,
remote: this.props.remote
}
);

Expand All @@ -163,12 +162,21 @@ module.exports = class extends Generator {
this.destinationPath('.editorconfig')
);

this.fs.copyTpl(
this.templatePath('_publish.sh'),
this.destinationPath('publish.sh'),
{
dest: this.props.dest
}
);

this.fs.copyTpl(
this.templatePath('assets/base.scss'),
this.destinationPath(`${this.props.src}components/base.scss`),
{
bootstrap: this.props.bootstrap,
icons: this.props.icons,
atomic: this.props.atomic.split('<'),
icons: 'svg',
}
);
this.fs.write(this.destinationPath(`${this.props.src}config/variables.scss`), '@charset \'utf-8\';\n');
Expand All @@ -179,7 +187,7 @@ module.exports = class extends Generator {
this.destinationPath(`${this.props.src}components/base.js`),
{
bootstrap: this.props.bootstrap,
svgIcons: this.props.icons === 'svg',
svgIcons: true,
}
);

Expand All @@ -195,12 +203,10 @@ module.exports = class extends Generator {
this.fs.write(this.destinationPath(`${this.props.src}favicons/README.md`), '# Favicons\n\nGo on [realfavicongenerator.net](https://realfavicongenerator.net) to generate your favicon kit! (and remove this file when done)\n');

// Icons
if (this.props.icons === 'svg') {
this.fs.copy(
this.templatePath('assets/svg-icons.js'),
this.destinationPath(`${this.props.src}icons/svg-icons.js`)
);
}
this.fs.copy(
this.templatePath('assets/svg-icons.js'),
this.destinationPath(`${this.props.src}icons/svg-icons.js`)
);

// WE WANT BOOTSTRAP
if (this.props.bootstrap) {
Expand All @@ -218,9 +224,7 @@ module.exports = class extends Generator {
this.fs.write(this.destinationPath(`${this.props.src}config/colors.json`), '{\n "Black": "#000",\n "White": "#fff"\n}\n');

emptyDirs.push(
'components/atoms/',
'components/molecules/',
'components/organisms/',
...this.props.atomic.split('<').map(item => `components/${item}/`),
'components/pages/'
);

Expand All @@ -232,7 +236,7 @@ module.exports = class extends Generator {
this.fs.write(this.destinationPath('docs/index.md'), `# ${this.props.name}\n\nThis is the homepage content.`);

// Others
this.fs.write(this.destinationPath('README.md'), `# ${this.props.name}\n\nPlease document your project here!`);
this.fs.write(this.destinationPath('README.md'), `# ${this.props.name}\n\nPlease document your project here!\n\n## To start\n- **serve** your project : \`$ yarn start\`\n- **build** your project : \`$ yarn build\`\n- **deploy** your gh-pages : \`$ yarn deploy\`\n- **publish** your frontend build : \`$ sh ./publish.sh VERSION<0.0.0> ON_NPM<true>\`\n`);
if (this.props.changelog) {
this.fs.write(this.destinationPath('CHANGELOG.md'), `# CHANGELOG\n\n## 0.0.0 (${new Date().toLocaleDateString()})\n\n - init project\n`);
this.fs.write(this.destinationPath('VERSION'), '0.0.0');
Expand Down
64 changes: 64 additions & 0 deletions generators/app/templates/_publish.sh
@@ -0,0 +1,64 @@
#!/bin/sh

DIRECTORY="<%= dest.replace(/\/$/, "") %>"
BRANCH="dist/frontend"
CURRENT_BRANCH=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')

# Check if the environment is ready for publishing ===========================
if [ "$CURRENT_BRANCH" != "master" ]
then
echo "⚠️ Please run this script from master branch"
exit 1;
fi

if [[ $(git status -s) ]]
then
echo "⚠️ The working directory is dirty. Please commit any pending changes."
exit 1;
fi

if [ $2 ]
then
npm whoami || { echo "⚠️ You must be logged in to NPM to push a new release" ; exit 1; }
fi

jq --version || { echo "⚠️ You have jq installed on your machine (brew install jq)" ; exit 1; }

# Proceed =====================================================================
echo "rebuild frontend assets"
yarn build

echo "update package.json version to $1 and write a copy for publishing"
npm version $1
cp package.json $DIRECTORY/package.json
jq -e ".dependencies = {} | .devDependencies = {}" $DIRECTORY/package.json > $DIRECTORY/package.json.tmp && cp $DIRECTORY/package.json.tmp $DIRECTORY/package.json && rm $DIRECTORY/package.json.tmp

echo "backup dist content"
mkdir "$DIRECTORY-tmp"
cp -r $DIRECTORY/* "$DIRECTORY-tmp/"

echo "Deleting dist"
rm -rf $DIRECTORY
mkdir $DIRECTORY
git worktree prune
rm -rf .git/worktrees/$DIRECTORY/

echo "Checking out $BRANCH branch into dist"
git worktree add -B $BRANCH $DIRECTORY

echo "Removing existing files"
rm -rf $DIRECTORY/*

echo "Generating dist using the backup"
cp -r "$DIRECTORY-tmp"/* $DIRECTORY/
rm -rf "$DIRECTORY-tmp"

echo "Updating $BRANCH branch"
if [ $2 ]
then
cd $DIRECTORY && git add --all && git commit -m "Publishing to $BRANCH (publish.sh)"
git push --force origin $BRANCH --tags && npm publish
else
cd $DIRECTORY && git add --all && git commit -m "Publishing to $BRANCH (publish.sh)"
git push --force origin $BRANCH --tags
fi
10 changes: 3 additions & 7 deletions generators/app/templates/assets/base.scss
Expand Up @@ -9,11 +9,7 @@
// line and have exactly those names for the `$ yo toolbox:generate` command
// to work

<% atomic.forEach(function (item) { %>
//
// atoms:

//
// molecules:

//
// organisms:
// <%= item %>:
<% }) %>
24 changes: 24 additions & 0 deletions generators/check-update.js
@@ -0,0 +1,24 @@
const latestVersion = require('latest-version');
const chalk = require('chalk');
const pkg = require('./../package.json');

// Display update notification if it's not the last version
module.exports = () => latestVersion('generator-toolbox').then(version => {
try {
if (version !== pkg.version) {
const msg = ` Version ${version} (current ${pkg.version}) of generator-toolbox is available ! `;
return `
${chalk.white.bgRed.bold(` ${' '.repeat(msg.length)} \n ${msg} \n${' '.repeat(msg.length)} `)}
To update your beloved generator, do :
$ ${chalk.green('yarn global upgrade generator-toolbox')} (recommended)
or
$ ${chalk.green('npm -g install generator-toolbox')}
`;
}
return '';
} catch (error) {
console.error('The NPM is unavailable to check for updates.');
return '';
}
});
58 changes: 38 additions & 20 deletions generators/generate/index.js
@@ -1,10 +1,34 @@
'use strict';
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const slug = require('slug');
const pathExists = require('path-exists');
const fs = require('fs');

const checkUpdate = require('../check-update');

const defaultStructure = [
{
name: 'Atom',
value: 'atoms'
}, {
name: 'Molecule',
value: 'molecules'
}, {
name: 'Organism',
value: 'organisms'
}
];

const pages = [
{
name: 'Page',
value: 'pages'
}, {
name: 'Doc Page',
value: 'doc'
}
];

module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);
Expand All @@ -18,29 +42,23 @@ module.exports = class extends Generator {
}
}

prompting() {
async prompting() {
await checkUpdate().then(res => this.log(res));

let fileStructure = [...defaultStructure, ...pages];
if (this.promptValues.atomic) {
const currentStructure = this.promptValues.atomic.split('<').map((item) => ({
name: item,
value: item,
}));
fileStructure = [...currentStructure, ...pages];
}

return this.prompt([{
type: 'list',
name: 'type',
message: 'What kind of component do you want?',
choices: [
{
name: 'Atom',
value: 'atoms'
}, {
name: 'Molecule',
value: 'molecules'
}, {
name: 'Organism',
value: 'organisms'
}, {
name: 'Page',
value: 'pages'
}, {
name: 'Doc Page',
value: 'doc'
}
]
choices: fileStructure
}, {
type: 'input',
name: 'name',
Expand Down
50 changes: 50 additions & 0 deletions generators/tools/index.js
@@ -0,0 +1,50 @@
'use strict';
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const pathExists = require('path-exists');
const fs = require('fs');

const checkUpdate = require('../check-update');

module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);
this.promptValues = this.config.getAll().promptValues;
}

async prompting() {
await checkUpdate().then(res => this.log(res));

return this.prompt([{
type: 'list',
name: 'tools',
message: 'What kind of tool do you need',
choices: [
{
name: `The ${chalk.yellow('publisher')} to create dist tagged branchs and to publish those dist to NPM`,
value: 'publisher'
}
]
}]).then(answers => {
this.props = answers;
});
}

async writing() {
switch (this.props.tools) {
case 'publisher':
this.fs.copyTpl(
this.templatePath('_publish.sh'),
this.destinationPath('publish.sh'),
{
dest: this.promptValues.dest
}
);
break;

default:
break;
}
}

};

0 comments on commit bab9f02

Please sign in to comment.