<commit_before>use Cro::Tools::Template::HTTPService;

class Cro::Tools::Template::ReactReduxSPA is Cro::Tools::Template::HTTPService {
    method id(--> Str) { 'react-redux-spa' }

    method name(--> Str) { 'React/Redux Single Page Application' }

    method generate(IO::Path $where, Str $id, Str $name,
                    %options, $generated-links, @links) {
        my %dir = self.make-directories($where);
        self.write-static-index(%dir<static>.add('index.html'), $name);
        self.write-frontend-index(%dir<frontend>.add('index.js'));
        self.write-frontend-actions(%dir<frontend>.add('actions.js'));
        self.write-frontend-reducer(%dir<frontend>.add('reducer.js'));
        self.write-npm-package-config($where.add('package.json'));
        self.write-webpack-config($where.add('webpack.config.js'));
        self.write-babelrc($where.add('.babelrc'));
        nextsame;
    }

    method new-directories($where) {
        my $static = $where.add('static');
        |callsame,
        static    => $static,
        static-js => $static.add('js'),
        frontend  => $where.add('frontend')
    }

    method write-static-index($file, $name) {
        $file.spurt(self.static-index-contents($name));
    }

    method static-index-contents($name) {
        q:c:to/HTML/;
            <html>
              <head>
                <title>{$name}</title>
              </head>
              <body>
                <h1>{$name}</h1>
                <div id="app"></div>
                <script src="js/bundle.js"></script>
              </body>
            </html>
            HTML
    }

    method write-frontend-index($file) {
        $file.spurt(self.frontend-index-contents);
    }

    method frontend-index-contents() {
        'TODO'
    }

    method write-frontend-actions($file) {
        $file.spurt(self.frontend-actions-contents);
    }

    method frontend-actions-contents() {
        'TODO'
    }

    method write-frontend-reducer($file) {
        $file.spurt(self.frontend-reducer-contents);
    }

    method frontend-reducer-contents() {
        'TODO'
    }

    method write-npm-package-config($file) {
        $file.spurt(self.npm-package-config-contents);
    }

    method npm-package-config-contents() {
        'TODO'
    }

    method write-webpack-config($file) {
        $file.spurt(self.webpack-config-contents);
    }

    method webpack-config-contents() {
        q:to/CODE/;<commit_msg>Fill in ReactReduxSPA.npm-package-config-contents<commit_after>use Cro::Tools::Template::HTTPService;

class Cro::Tools::Template::ReactReduxSPA is Cro::Tools::Template::HTTPService {
    method id(--> Str) { 'react-redux-spa' }

    method name(--> Str) { 'React/Redux Single Page Application' }

    method generate(IO::Path $where, Str $id, Str $name,
                    %options, $generated-links, @links) {
        my %dir = self.make-directories($where);
        self.write-static-index(%dir<static>.add('index.html'), $name);
        self.write-frontend-index(%dir<frontend>.add('index.js'));
        self.write-frontend-actions(%dir<frontend>.add('actions.js'));
        self.write-frontend-reducer(%dir<frontend>.add('reducer.js'));
        self.write-npm-package-config($where.add('package.json'), $id);
        self.write-webpack-config($where.add('webpack.config.js'));
        self.write-babelrc($where.add('.babelrc'));
        nextsame;
    }

    method new-directories($where) {
        my $static = $where.add('static');
        |callsame,
        static    => $static,
        static-js => $static.add('js'),
        frontend  => $where.add('frontend')
    }

    method write-static-index($file, $name) {
        $file.spurt(self.static-index-contents($name));
    }

    method static-index-contents($name) {
        q:c:to/HTML/;
            <html>
              <head>
                <title>{$name}</title>
              </head>
              <body>
                <h1>{$name}</h1>
                <div id="app"></div>
                <script src="js/bundle.js"></script>
              </body>
            </html>
            HTML
    }

    method write-frontend-index($file) {
        $file.spurt(self.frontend-index-contents);
    }

    method frontend-index-contents() {
        'TODO'
    }

    method write-frontend-actions($file) {
        $file.spurt(self.frontend-actions-contents);
    }

    method frontend-actions-contents() {
        'TODO'
    }

    method write-frontend-reducer($file) {
        $file.spurt(self.frontend-reducer-contents);
    }

    method frontend-reducer-contents() {
        'TODO'
    }

    method write-npm-package-config($file, $id) {
        $file.spurt(self.npm-package-config-contents($id));
    }

    method npm-package-config-contents($id) {
        q:s:to/CODE/;
            {
              "name": "$id",
              "version": "1.0.0",
              "description": "Write me!",
              "main": "index.js",
              "scripts": {
                "build": "webpack",
                "test": "echo \"Error: no test specified\" && exit 1"
              },
              "author": "",
              "license": "UNLICENSED",
              "private": true,
              "devDependencies": {
                "babel-core": "^6.26.0",
                "babel-loader": "^7.1.2",
                "babel-plugin-transform-object-rest-spread": "^6.26.0",
                "babel-preset-env": "^1.6.0",
                "babel-preset-es2015": "^6.24.1",
                "babel-preset-react": "^6.24.1",
                "webpack": "^3.6.0"
              },
              "dependencies": {
                "jquery": "^3.2.1",
                "react": "^16.0.0",
                "react-dom": "^16.0.0",
                "react-redux": "^5.0.6",
                "redux": "^3.7.2",
                "redux-thunk": "^2.2.0",
                "redux-websocket-action": "^1.0.5"
              }
            }
            CODE
    }

    method write-webpack-config($file) {
        $file.spurt(self.webpack-config-contents);
    }

    method webpack-config-contents() {
        q:to/CODE/;
{'fraction_non_alphanumeric': 0.17434804001968182, 'fraction_numerical': 0.009840905363293424, 'mean_word_length': 1.841565703634669, 'pattern_counts': {'":': 26, '<': 39, '<?xml version=': 0, '>': 49, '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': '1355115', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1900, 'n_words': 261}