<commit_before>/**
 * Blocks library installer
 */

exports.description = 'Installs common CSS/JS block.';

exports.template = function(grunt, init, done) {
	var path = require('path'),
		fs = require('fs');

	grunt.helper('prompt', {}, [
		{
			name: 'block',
			message: 'Block name'
		}
	], function(err, props) {
		var block = props.block;

		if (!block) {
			printBlocksList();
			done();
		}

		// Copy files

		var folder = grunt.task.getFile(path.join('init/_blocks', block));
		if (!folder) {
			printBlocksList();
			grunt.fatal('Block "' + block + '" not found.');
		}
		
		var blockFiles = grunt.file.expandFiles(path.join(folder, '*'));

		var files = {};
		blockFiles.forEach(function(filepath) {
			files[path.join('blocks', block, path.basename(filepath))] = filepath;
		});

		init.copyAndProcess(files, props);

		// Update index.styl
		var stylusIndex = grunt.file.read('styles/index.styl');
		if (stylusIndex) {
			stylusIndex = stylusIndex.replace(/(@import ['"]shugar['"];?)/, '$1\n@import "../blocks/' + block + '";');<commit_msg>Changes for new grunt-stylus.<commit_after>/**
 * Blocks library installer
 */

exports.description = 'Installs common CSS/JS block.';

exports.template = function(grunt, init, done) {
	var path = require('path');

	grunt.helper('prompt', {}, [
		{
			name: 'block',
			message: 'Block name'
		}
	], function(err, props) {
		var block = props.block;

		if (!block) {
			printBlocksList();
			done();
		}

		// Copy files

		var folder = grunt.task.getFile(path.join('init/_blocks', block));
		if (!folder) {
			printBlocksList();
			grunt.fatal('Block "' + block + '" not found.');
		}
		
		var blockFiles = grunt.file.expandFiles(path.join(folder, '*'));

		var files = {};
		blockFiles.forEach(function(filepath) {
			files[path.join('blocks', block, path.basename(filepath))] = filepath;
		});

		init.copyAndProcess(files, props);

		// Update index.styl
		var stylusIndex = grunt.file.read('styles/index.styl');
		if (stylusIndex) {
			stylusIndex = stylusIndex.replace(/(@import ['"]shugar['"];?)/, '$1\n@import "' + block + '";');
{'fraction_non_alphanumeric': 0.19330143540669856, 'fraction_numerical': 0.0009569377990430622, 'mean_word_length': 3.7200902934537248, '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': '4593494', 'n_tokens_mistral': 810, 'n_tokens_neox': 714, 'n_words': 142}