<commit_before>#!/usr/bin/env node

var fs = require("fs");
var mkdirp = require("mkdirp");
var _ = require("underscore");
var ncp = require('ncp').ncp;

var opts = JSON.parse(fs.readFileSync(__dirname + "/../package.json", "utf8"));

if (process.argv.length < 3) {
	console.log("Please enter an id.");
	return false;
}

if (process.argv.length > 3) {
	var app_dir = process.argv[3];
} else {
	var app_dir = "./";
}

var data = {
		interactive_id: process.argv[2],
		version: opts.version || "*"
	};

var index = _.template(fs.readFileSync(__dirname + "/prototype/index.html", "utf8")),
	debug = _.template(fs.readFileSync(__dirname + "/prototype/debug.js", "utf8")),
	styles = _.template(fs.readFileSync(__dirname + "/prototype/src/styles.less", "utf8")),
	pkg = _.template(fs.readFileSync(__dirname + "/prototype/package.json", "utf8"));

var path = app_dir + data.interactive_id;

mkdirp(path, function() {
	fs.writeFileSync(path + "/index.html", index(data));
	fs.writeFileSync(path + "/debug.js", debug(data));
	fs.writeFileSync(path + "/package.json", pkg(data));

	mkdirp(path + "/src", function() {
		fs.writeFileSync(path + "/src/styles.less", styles(data));

		ncp(__dirname + "/prototype/src/base.html", path + "/src/base.html", function (err) {
		 	if (err) {
		   		return console.error(err);
		 	}

		 	/*
		 	// test the bundling
			var browserify = require('browserify');		 

			var b = browserify();
			b.add(path + "/debug.js");
			b.bundle();	

			console.log("Successfully created a new app named " + data.interactive_id + " in " + app_dir);<commit_msg>Fixed using . as a second parameter, checking whether a directory already exists and aborts execution with an error message<commit_after>#!/usr/bin/env node

var fs = require("fs");
var mkdirp = require("mkdirp");
var _ = require("underscore");
var ncp = require('ncp').ncp;

var opts = JSON.parse(fs.readFileSync(__dirname + "/../package.json", "utf8"));

if (process.argv.length < 3) {
	console.log("Please enter an id.");
	return false;
}
var app_dir = "./";  // default to the the current directory
if (process.argv.length > 3) {
	app_dir = process.argv[3];
    // make sure app_dir ends with a / delimiter
    if (app_dir.slice(-1) != '/') {
        app_dir += '/';
    }
}

var data = {
		interactive_id: process.argv[2],
		version: opts.version || "*"
	};

var index = _.template(fs.readFileSync(__dirname + "/prototype/index.html", "utf8")),
	debug = _.template(fs.readFileSync(__dirname + "/prototype/debug.js", "utf8")),
	styles = _.template(fs.readFileSync(__dirname + "/prototype/src/styles.less", "utf8")),
	pkg = _.template(fs.readFileSync(__dirname + "/prototype/package.json", "utf8"));


var path = app_dir + data.interactive_id;

if (fs.existsSync(path)) {
    console.error("The path "+path+ " already exists!");
    console.error("Program execution aborted!");
}

mkdirp(path, function() {
	fs.writeFileSync(path + "/index.html", index(data));
	fs.writeFileSync(path + "/debug.js", debug(data));
	fs.writeFileSync(path + "/package.json", pkg(data));

	mkdirp(path + "/src", function() {
		fs.writeFileSync(path + "/src/styles.less", styles(data));

		ncp(__dirname + "/prototype/src/base.html", path + "/src/base.html", function (err) {
		 	if (err) {
		   		return console.error(err);
		 	}

		 	/*
		 	// test the bundling
			var browserify = require('browserify');		 

			var b = browserify();
			b.add(path + "/debug.js");
			b.bundle();	

			console.log("Successfully created a new app named " + data.interactive_id + " in " + app_dir);
{'fraction_non_alphanumeric': 0.18647425014148275, 'fraction_numerical': 0.005376344086021506, 'mean_word_length': 3.855769230769231, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5725915', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1201, 'n_words': 263}