<commit_before>var task = require('../../task'),
    path = require('path'),
    fs = require('fs'),
    query = require('../../query'),
    config = require('../../config')();

var addTask = module.exports = function(packageUrl, dir) {
    'use strict';

    if (!packageUrl) {
        throw new Error('No archetype specified');
    }

    if (!dir) {
        throw new Error('No destination directory specified');
    }

    if (fs.existsSync(dir)) {
        throw new Error('Directory already initialized or not empty');
    }

    var manifestFile = path.join(config.cwd, 'pas.json');
    var manifest = require(manifestFile);

    var p;
    return query().then(function(pArg) {
            p = pArg;
            return task({_:['init', packageUrl, dir]});
        })
        .then(function() {
            manifest.modules = manifest.modules || [];

            var modules = [];
            manifest.modules.forEach(function(m) {
                if (modules.indexOf(m) === -1) {
                    modules.push(m);
                }
            });

            if (modules.indexOf(dir) === -1) {
                modules.push(dir);
            }

            manifest.modules = modules;

            fs.writeFileSync(manifestFile, JSON.stringify(manifest, null, 2));
<commit_msg>CHANGED how to rewrite manifest file<commit_after>var task = require('../../task'),
    path = require('path'),
    fs = require('fs'),
    query = require('../../query'),
    config = require('../../config')();

var addTask = module.exports = function(packageUrl, dir) {
    'use strict';

    if (!packageUrl) {
        throw new Error('No archetype specified');
    }

    if (!dir) {
        throw new Error('No destination directory specified');
    }

    if (fs.existsSync(dir)) {
        throw new Error('Directory already initialized or not empty');
    }

    var manifestFile = path.join(config.cwd, 'pas.json');
    var manifest = require(manifestFile);

    var p;
    return query().then(function(pArg) {
            p = pArg;
            return task({_:['init', packageUrl, dir]});
        })
        .then(function() {
            manifest.modules = manifest.modules || [];

            var modules = [];
            manifest.modules.forEach(function(m) {
                if (modules.indexOf(m) === -1) {
                    modules.push(m);
                }
            });

            if (modules.indexOf(dir) === -1) {
                modules.push(dir);
            }

            manifest.modules = modules;

            p.writeManifest(manifest);

{'fraction_non_alphanumeric': 0.1556511536957372, 'fraction_numerical': 0.0019554165037152915, 'mean_word_length': 1.835920177383592, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4703656', 'n_tokens_mistral': 717, 'n_tokens_neox': 680, 'n_words': 162}