Skip to content

Commit

Permalink
Add cosmicconfig so folks can define their own tokens etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy-set-studio committed Dec 17, 2019
1 parent f2dfea2 commit cec8ef8
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 6 deletions.
185 changes: 184 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"chalk": "^3.0.0",
"clean-css": "^4.2.1",
"cosmiconfig": "^6.0.0",
"shelljs": "^0.8.3"
}
}
20 changes: 15 additions & 5 deletions src/index.js
@@ -1,19 +1,29 @@
#!/usr/bin/env node

const {cosmiconfig, cosmiconfigSync} = require('cosmiconfig');
const chalk = require('chalk');
const CleanCSS = require('clean-css');
const fs = require('fs');
const shell = require('shelljs');

const config = require('./default/config.js');
const customProperties = require('./components/custom-properties.js');
const generator = require('./components/generator.js');

let config = require('./default/config.js');

// The main organ grinder
const init = () => {
let css = '';
const pathIndex = process.argv.indexOf('-out');
const cleanCSS = new CleanCSS();


// Try to load the user’s config
const userConfig = cosmiconfigSync('goron', {searchPlaces: ['goron.config.js']}).search();

if (userConfig) {
config = userConfig;
}

// Bail out if the path isn't defined
if (pathIndex <= 0 && !config.hasOwnProperty('outputPath')) {
console.log(
Expand All @@ -26,19 +36,19 @@ const init = () => {
}

const outputPath = config.outputPath || process.argv.slice(pathIndex + 1)[0];

// The path has to contain a filename so we need to bail if that's not the case
if (outputPath.indexOf('.css') < 0) {
console.log(chalk.red(`Please add a css file to your path.`));
console.log(chalk.red(`Example: path/to/my/folder/tokens.css`));
console.log(chalk.blue('Exiting.'));
return;
}

// Add the custom props and the media query-less clases
css += customProperties(config);
css += generator(config, ['responsive', 'standard']);

// If there's some breakpoints, generate the classes that are responsive
Object.keys(config.breakpoints).forEach(key => {
css += `
Expand Down

0 comments on commit cec8ef8

Please sign in to comment.