<commit_before>'use strict';

const Bluebird = require('bluebird');
const express = require('express');
const Observable = require('rx').Observable;
const R = require('ramda');
const Functional = require('./util/Functional');
const Assets = require('./util/Assets');
const File = require('./util/File');
const Playground = require('./util/Playground');
const ServeAssets = require('./ServeAssets').ServeAssets;

const CONST = require('../lib/CONST');

module.exports = (opts) => {
  const serveAssets = new ServeAssets();

  const app = express();
  app.use(serveAssets.router);
  app.listen(opts.port);

  const bs = require('browser-sync').create();
  bs.init({
    proxy: `http://localhost:${opts.port}`,
    ui: false,
    notify: false,
    ghostMode: false,
    open: opts.openBrowser,
  });

  File.watch('playground.*')
    .flatMap(R.converge(Bluebird.join, R.identity, File.readFile))
    .map(R.adjust(Playground.getExt, 0))
    .map(R.apply(Playground.parse))
    .doOnNext(R.pipe(
      R.converge(
        (title, cssBase, stylesheets, scripts) => ({title, cssBase, stylesheets, scripts}),
        R.prop('title'),
        R.path(['css', 'base']),
        R.path(['css', 'external']),
        R.path(['js', 'external'])
      ),
      Functional.defaultToProps(CONST.DEFAULT_PLAYGROUND_CONTENT),
      serveAssets.setLocals
    ))
    .flatMapLatest(R.converge(
      Observable.combineLatest,
      (playground) => File.watch(`html.{${Assets.getHtmlExts(playground).join(',')}}`)
        .flatMap(File.readFile)
        .flatMap(Assets.getHtmlRenderer(playground))
        .doOnNext(serveAssets.updateAsset('html')),
      (playground) => File.watch(`js.{${Assets.getJsExts(playground).join(',')}}`)
        .flatMap(File.readFile)
        .flatMap(Assets.getJsRenderer(playground))
        .doOnNext(serveAssets.updateAsset('js')),
      (playground) => File.watch(`css.{${Assets.getCssExts(playground).join(',')}}`)
        .flatMap(File.readFile)
        .flatMap(Assets.getCssRenderer(playground))
        .flatMap(Assets.postProcessorForCss(playground))
        .doOnNext(serveAssets.updateAsset('css'))<commit_msg>start use baseDir<commit_after>'use strict';

const path = require('path');
const Bluebird = require('bluebird');
const express = require('express');
const Observable = require('rx').Observable;
const R = require('ramda');
const Functional = require('./util/Functional');
const Assets = require('./util/Assets');
const File = require('./util/File');
const Playground = require('./util/Playground');
const ServeAssets = require('./ServeAssets').ServeAssets;

const CONST = require('../lib/CONST');

module.exports = (opts) => {
  const joinBase = R.partial(path.join, opts.baseDir);

  const serveAssets = new ServeAssets();

  const app = express();
  app.use(serveAssets.router);
  app.listen(opts.port);

  const bs = require('browser-sync').create();
  bs.init({
    proxy: `http://localhost:${opts.port}`,
    ui: false,
    notify: false,
    ghostMode: false,
    open: opts.openBrowser,
  });

  File.watch(joinBase('playground.*'))
    .flatMap(R.converge(Bluebird.join, R.identity, File.readFile))
    .map(R.adjust(Playground.getExt, 0))
    .map(R.apply(Playground.parse))
    .doOnNext(R.pipe(
      R.converge(
        (title, cssBase, stylesheets, scripts) => ({title, cssBase, stylesheets, scripts}),
        R.prop('title'),
        R.path(['css', 'base']),
        R.path(['css', 'external']),
        R.path(['js', 'external'])
      ),
      Functional.defaultToProps(CONST.DEFAULT_PLAYGROUND_CONTENT),
      serveAssets.setLocals
    ))
    .flatMapLatest(R.converge(
      Observable.combineLatest,
      (playground) => File.watch(joinBase(`html.{${Assets.getHtmlExts(playground).join(',')}}`))
        .flatMap(File.readFile)
        .flatMap(Assets.getHtmlRenderer(playground))
        .doOnNext(serveAssets.updateAsset('html')),
      (playground) => File.watch(joinBase(`js.{${Assets.getJsExts(playground).join(',')}}`))
        .flatMap(File.readFile)
        .flatMap(Assets.getJsRenderer(playground))
        .doOnNext(serveAssets.updateAsset('js')),
      (playground) => File.watch(joinBase(`css.{${Assets.getCssExts(playground).join(',')}}`))
        .flatMap(File.readFile)
        .flatMap(Assets.getCssRenderer(playground))
        .flatMap(Assets.postProcessorForCss(playground))
        .doOnNext(serveAssets.updateAsset('css'))
{'fraction_non_alphanumeric': 0.18227272727272728, 'fraction_numerical': 0.00045454545454545455, 'mean_word_length': 3.825657894736842, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7166809', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1451, 'n_words': 210}