Skip to content

Instantly share code, notes, and snippets.

@delebash
Last active November 19, 2018 09:27
Show Gist options
  • Save delebash/df7a9249d034e2573057 to your computer and use it in GitHub Desktop.
Save delebash/df7a9249d034e2573057 to your computer and use it in GitHub Desktop.
outputs kss to json string
//install kss and fs-extra: npm install kss fs-extra
var kss = require('kss'),
options = {
markdown: false
};
var fs = require('fs-extra');
var file = './docs/kss.json';
kss.traverse('.', options, function (err, styleguide) {
if (err) throw err;
var mySections = styleguide.section();
var myJsonSections = []
for (var i = 0, tot = mySections.length; i < tot; i++) {
myJsonSections.push(mySections[i].JSON());
}
fs.outputJson(file, myJsonSections, function (err) {
console.log(err) // => null
})
});
@airtonix
Copy link

airtonix commented Mar 23, 2018

import {join} from 'path';
import kss from 'kss';
import fs from 'fs-extra';

const CWD = process.cwd();
const KSSPLUGIN_DEFAULTS = {
  on: 'done',
  source: join(CWD, 'client', 'src'),
  destination: join(CWD, 'dist')
};

export class KssJsonWebpackPlugin {

  constructor(options) {
    this.options = Object.assign(
        {},
        options,
        {markdown: false},
        KSSPLUGIN_DEFAULTS);
  }

  apply(compiler) {
    compiler.plugin(this.options.on, () => {
      kss.traverse('.', this.options, (error, styleguide) => {
        if (error) throw error;
        fs.outputJson(
          join(this.options.destination, 'kss.json'),
          styleguide.section().map(section => section.JSON()),
          (err) => {
            console.log(err);
          });
      });
    });
  };
};
import Config from 'webpack-config';
import debug from 'debug';
import {join} from 'path';

import {KssJsonWebpackPlugin} from './kss--plugin.js';

const log = debug('build/settings/documentation');

export default new Config()
  .merge({
    plugins: [
      new KssJsonWebpackPlugin(),
    ]
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment