<commit_before>/* jshint node: true */
'use strict';

var path      = require('path');
var fs        = require('fs');
var RSVP      = require('rsvp');
var Promise   = RSVP.Promise;
var denodeify = RSVP.denodeify;

var readFile  = denodeify(fs.readFile);
var writeFile = denodeify(fs.writeFile);

var createHtmlManifest = require('./lib/utilities/create-html-manifest');
var replaceHtmlManifest = require('./lib/utilities/replace-html-manifest');
var DeployPluginBase = require('ember-cli-deploy-plugin');

module.exports = {
  name: 'ember-cli-deploy-html-manifest',

  createDeployPlugin: function(options) {
    var DeployPlugin = DeployPluginBase.extend({
      name: options.name,

      defaultConfig: {
        distDir: function(context) {
          return context.distDir;
        },

        filename: 'manifest.appcache',

        manifestRoot: function(context) {
          var revisionKey = context.revisionData && context.revisionData.revisionKey;

          return '/revisions/' + revisionKey;
        },

        prependPath: '',

        excludePaths: ['index.html'],

        includePaths: [],

        network: ['*'],

        fallback: [],

        distFiles: function(context) {
          return context.distFiles || [];
        }
      },

      didPrepare: function(context) {
        this._createManifestFile(context);

        var distDir      = this.readConfig('distDir');
        var htmlPagePath = path.join(distDir, 'index.html');

        var manifestRoot = this.readConfig('manifestRoot');
        var filename     = this.readConfig('filename');
        var manifestPath = path.join(manifestRoot, filename);

        this.log('Adding manifest attribute to html tag with value of "' + manifestPath + '".');

        this.log('distDir => ' + distDir, { verbose: true });
        this.log('htmlPagePath => ' + htmlPagePath, { verbose: true });
        this.log('manifestRoot => ' + manifestRoot, { verbose: true });
        this.log('filename => ' + filename, { verbose: true });
        this.log('manifestPath => ' + manifestPath, { verbose: true });

        return readFile(htmlPagePath)
          .then(function(data) {
            return replaceHtmlManifest(data, manifestPath);
          })
          .then(function(html) {
            return writeFile(htmlPagePath, html);
          })
          .then(function() {
            this.log('Successfully added manifest attribute to html tag.', { color: 'green' });
            return { distFiles: [manifestPath] };
          }.bind(this),
          function() {
            this.log('Faild to add manifest attribute to html tag.', { color: 'red' });
            return Promise.reject;
          }.bind(this));
      },

      _createManifestFile: function(context) {
        var version  = context.revisionData && context.revisionData.revisionKey;
        var filename = this.readConfig('filename');
        var distDir  = this.readConfig('distDir');
        var manifestDistPath = path.join(distDir, filename);

        this.log('Build manifest file `'+ filename + '`');

        var options = {
          prependPath: this.readConfig('prependPath'),
          excludePaths: this.readConfig('excludePaths'),
          includePaths: this.readConfig('includePaths'),
          network: this.readConfig('network'),
          fallback: this.readConfig('fallback'),
          version: version
        };

        var distFiles = this.readConfig('distFiles');

        var manifest = createHtmlManifest(distFiles, options);

        writeFile(manifestDistPath, manifest).then(
          function() {
            this.log('Successfully created manifest file.', { color: 'green' });
          },
          function() {
            this.log('Faild to create manifest file.', { color: 'red' });
          }
        );
      }
    });

    return new DeployPlugin();
  }
};
<commit_msg>Change hook to fire on willUpload() and concat()'d manifest to distFiles<commit_after>/* jshint node: true */
'use strict';

var path      = require('path');
var fs        = require('fs');
var RSVP      = require('rsvp');
var Promise   = RSVP.Promise;
var denodeify = RSVP.denodeify;

var readFile  = denodeify(fs.readFile);
var writeFile = denodeify(fs.writeFile);

var createHtmlManifest = require('./lib/utilities/create-html-manifest');
var replaceHtmlManifest = require('./lib/utilities/replace-html-manifest');
var DeployPluginBase = require('ember-cli-deploy-plugin');

module.exports = {
  name: 'ember-cli-deploy-html-manifest',

  createDeployPlugin: function(options) {
    var DeployPlugin = DeployPluginBase.extend({
      name: options.name,

      defaultConfig: {
        distDir: function(context) {
          return context.distDir;
        },

        filename: 'manifest.appcache',

        manifestRoot: function(context) {
          var revisionKey = context.revisionData && context.revisionData.revisionKey;

          return '/revisions/' + revisionKey;
        },

        prependPath: '',

        excludePaths: ['index.html'],

        includePaths: [],

        network: ['*'],

        fallback: [],

        distFiles: function(context) {
          return context.distFiles || [];
        }
      },

      willUpload: function(context) {
        this._createManifestFile(context);

        var distDir      = this.readConfig('distDir');
        var distFiles    = this.readConfig('distFiles');
        var htmlPagePath = path.join(distDir, 'index.html');

        var manifestRoot = this.readConfig('manifestRoot');
        var filename     = this.readConfig('filename');
        var manifestPath = path.join(manifestRoot, filename);

        this.log('Adding manifest attribute to html tag with value of "' + manifestPath + '".');

        this.log('distDir => ' + distDir, { verbose: true });
        this.log('htmlPagePath => ' + htmlPagePath, { verbose: true });
        this.log('manifestRoot => ' + manifestRoot, { verbose: true });
        this.log('filename => ' + filename, { verbose: true });
        this.log('manifestPath => ' + manifestPath, { verbose: true });

        return readFile(htmlPagePath)
          .then(function(data) {
            return replaceHtmlManifest(data, manifestPath);
          })
          .then(function(html) {
            return writeFile(htmlPagePath, html);
          })
          .then(function() {
            this.log('Successfully added manifest attribute to html tag.', { color: 'green' });
            return { distFiles: distFiles.concat([manifestPath]) };
          }.bind(this),
          function() {
            this.log('Faild to add manifest attribute to html tag.', { color: 'red' });
            return Promise.reject;
          }.bind(this));
      },

      _createManifestFile: function(context) {
        var version  = context.revisionData && context.revisionData.revisionKey;
        var filename = this.readConfig('filename');
        var distDir  = this.readConfig('distDir');
        var manifestDistPath = path.join(distDir, filename);

        this.log('Build manifest file `'+ filename + '`');

        var options = {
          prependPath: this.readConfig('prependPath'),
          excludePaths: this.readConfig('excludePaths'),
          includePaths: this.readConfig('includePaths'),
          network: this.readConfig('network'),
          fallback: this.readConfig('fallback'),
          version: version
        };

        var distFiles = this.readConfig('distFiles');

        var manifest = createHtmlManifest(distFiles, options);

        writeFile(manifestDistPath, manifest).then(
          function() {
            this.log('Successfully created manifest file.', { color: 'green' });
          },
          function() {
            this.log('Faild to create manifest file.', { color: 'red' });
          }
        );
      }
    });

    return new DeployPlugin();
  }
};

{'fraction_non_alphanumeric': 0.1347526772055074, 'fraction_numerical': 0.0, 'mean_word_length': 2.4287587412587412, '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': '386555', 'n_tokens_mistral': 2172, 'n_tokens_neox': 2087, 'n_words': 455}