<commit_before>// @flow
import path from 'path';

import json from 'rollup-plugin-json';
import alias from 'rollup-plugin-alias';
import babel from 'rollup-plugin-babel';
import eslint from 'rollup-plugin-eslint';
import nodeResolve from 'rollup-plugin-node-resolve';
import { rollup } from 'rollup';

import { BACKSLASH } from '../../constants';
import { rmrf, readdir, readdirRec, isJSFile } from '../fs';
import template from '../template';

import normalizePath from './utils/normalize-path';
import createManifest from './utils/create-manifest';
import createBootScript from './utils/create-boot-script';
import { default as onwarn } from './utils/handle-warning';

/**
 * @private
 */
export async function compile(dir: string, env: string, {
  useStrict = false
}: {
  useStrict: boolean
} = {}): Promise<void> {
  let banner;

  const local = path.join(__dirname, '..', 'src', 'index.js');
  const entry = path.join(dir, 'dist', 'index.js');

  const nodeModules = path.join(dir, 'node_modules');
  const luxNodeModules = path.join(__dirname, '..', 'node_modules');
  const sourceMapSupport = path.join(luxNodeModules, 'source-map-support');

  const external = await Promise.all([
    readdir(nodeModules),
    readdir(luxNodeModules)
  ]).then(([a, b]: [Array<string>, Array<string>]) => (
    a.concat(b).filter(name => name !== 'lux-framework')
  ));

  const assets = await Promise.all([
    readdir(path.join(dir, 'app', 'models')),
    readdir(path.join(dir, 'db', 'migrate')),
    readdirRec(path.join(dir, 'app', 'controllers')),
    readdirRec(path.join(dir, 'app', 'serializers'))
  ]).then(types => {
    let [
      models,
      migrations,
      controllers,
      serializers
    ] = types;

    models = models.filter(isJSFile);
    migrations = migrations.filter(isJSFile);
    controllers = controllers.filter(isJSFile);
    serializers = serializers.filter(isJSFile);

    return new Map([
      ['Application', path.join('app', 'index.js')],
      ['config', path.join('config', 'environments', `${env}.js`)],
      ['controllers', controllers],
      ['database', path.join('config', 'database.js')],
      ['migrations', migrations],
      ['models', models],
      ['routes', path.join('app', 'routes.js')],
      ['seed', path.join('db', 'seed.js')],
      ['serializers', serializers]
    ]);
  });

  await Promise.all([
    createManifest(dir, assets, {
      useStrict
    }),

    createBootScript(dir, {
      useStrict
    })
  ]);

  const bundle = await rollup({
    entry,
    onwarn,
    external,

    plugins: [
      alias({
        resolve: ['.js'],
        app: normalizePath(path.join(dir, 'app')),
        LUX_LOCAL: normalizePath(local)
      }),

      json(),

      nodeResolve({
        preferBuiltins: true
      }),

      eslint({
        include: [
          path.join(dir, 'app', '**'),
        ],

        exclude: [
          path.join(dir, 'package.json'),
          path.join(__dirname, '..', 'src', '**')
        ]
      }),

      babel()
    ]
  });

  await rmrf(entry);
<commit_msg>fix: eslint config in compiler inherits from lux .eslintrc.json (#469)<commit_after>// @flow
import path from 'path';

import json from 'rollup-plugin-json';
import alias from 'rollup-plugin-alias';
import babel from 'rollup-plugin-babel';
import eslint from 'rollup-plugin-eslint';
import nodeResolve from 'rollup-plugin-node-resolve';
import { rollup } from 'rollup';

import { BACKSLASH } from '../../constants';
import { rmrf, readdir, readdirRec, isJSFile } from '../fs';
import template from '../template';

import normalizePath from './utils/normalize-path';
import createManifest from './utils/create-manifest';
import createBootScript from './utils/create-boot-script';
import { default as onwarn } from './utils/handle-warning';

/**
 * @private
 */
export async function compile(dir: string, env: string, {
  useStrict = false
}: {
  useStrict: boolean
} = {}): Promise<void> {
  let banner;

  const local = path.join(__dirname, '..', 'src', 'index.js');
  const entry = path.join(dir, 'dist', 'index.js');

  const nodeModules = path.join(dir, 'node_modules');
  const luxNodeModules = path.join(__dirname, '..', 'node_modules');
  const sourceMapSupport = path.join(luxNodeModules, 'source-map-support');

  const external = await Promise.all([
    readdir(nodeModules),
    readdir(luxNodeModules)
  ]).then(([a, b]: [Array<string>, Array<string>]) => (
    a.concat(b).filter(name => name !== 'lux-framework')
  ));

  const assets = await Promise.all([
    readdir(path.join(dir, 'app', 'models')),
    readdir(path.join(dir, 'db', 'migrate')),
    readdirRec(path.join(dir, 'app', 'controllers')),
    readdirRec(path.join(dir, 'app', 'serializers'))
  ]).then(types => {
    let [
      models,
      migrations,
      controllers,
      serializers
    ] = types;

    models = models.filter(isJSFile);
    migrations = migrations.filter(isJSFile);
    controllers = controllers.filter(isJSFile);
    serializers = serializers.filter(isJSFile);

    return new Map([
      ['Application', path.join('app', 'index.js')],
      ['config', path.join('config', 'environments', `${env}.js`)],
      ['controllers', controllers],
      ['database', path.join('config', 'database.js')],
      ['migrations', migrations],
      ['models', models],
      ['routes', path.join('app', 'routes.js')],
      ['seed', path.join('db', 'seed.js')],
      ['serializers', serializers]
    ]);
  });

  await Promise.all([
    createManifest(dir, assets, {
      useStrict
    }),

    createBootScript(dir, {
      useStrict
    })
  ]);

  const bundle = await rollup({
    entry,
    onwarn,
    external,

    plugins: [
      alias({
        resolve: ['.js'],
        app: normalizePath(path.join(dir, 'app')),
        LUX_LOCAL: normalizePath(local)
      }),

      json(),

      nodeResolve({
        preferBuiltins: true
      }),

      eslint({
        cwd: dir,
        parser: 'babel-eslint',
        useEslintrc: false,
        include: [
          path.join(dir, 'app', '**'),
        ],
        exclude: [
          path.join(dir, 'package.json'),
          path.join(__dirname, '..', 'src', '**')
        ]
      }),

      babel()
    ]
  });

  await rmrf(entry);

{'fraction_non_alphanumeric': 0.1777813401731324, 'fraction_numerical': 0.0004809233728759218, 'mean_word_length': 3.035575679172057, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '4308394', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1991, 'n_words': 435}