Пример #1
0
export default function( root, callback ) {
	return getModules(root, (err, modules) => {
		if (err) throw err;
		let imports = createImports(modules);
		let exportDefault = `export {\n  ${createExport(modules)}\n};`;
		writeFile(path.join(root, 'module', 'index.js'), `${imports}\n\n${exportDefault}`, callback);
	});
}
Пример #2
0
test('Should be a oneliner', (done) =>
	getModules(join(__dirname, '..'), (err, modules) => {
		if (err) throw err;
		let countTests = 0;

		modules.forEach((file) => {
			if (file === 'index.js') { return }

			readFile(join(__dirname, '..', 'module', file), { encoding: 'utf8', flag: 'r' }, (err, data) => {
				if (err) throw err;
				let count = 0;
				let lines = data.split(/\n/).forEach((l) => {
					if (l.startsWith(' *') || l.startsWith('/')) return;
					if (l.length > 0) count++;
				});

				equal(count, 1, `${file} should be a oneliner`);

				countTests++;
				if (countTests >= modules.length -1 ) done();
			})
		});
	})
Пример #3
0
const joinλ = curry(join);

const filterIndex = filterλ(module => module !== 'index.js');

getModules(path.join(__dirname, '..'), (err, modules) => {
	if (err) throw err;

	const docs = composeAll(
		joinλ('\n'),
		mapλ(renderTpl),
		mapλ(parseComments),
		mapλ(fileName => readFileSync(fileName, { encoding: 'utf8' })),
		mapλ(fileName => `./module/${fileName}`),
	  filterIndex
	)(modules);

	const README = `&nbsp;<p align="center"><img src="https://cdn.rawgit.com/stoeffel/1-liners/66775c8/logo.png" width="382px" height="125px" /></p>&nbsp;
# Documentation

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<!-- END doctoc generated TOC please keep comment here to allow auto update -->

${docs}
	`;
	writeFile('./documentation/README.md', README, onFileWritten);
})


function onFileWritten(err) {
	if (err) {
Пример #4
0
import getModules from 'get-modules';
import { readFile, writeFile } from 'fs';
import { join } from 'path';
import curry from '../module/curry';
import replace from '../module/replace';

const replaceCount = curry(replace)(/\d+ one-liner functions/);

getModules(join(__dirname, '..'), (err, modules) => {
	if (err) throw err;
	readFile(join(__dirname, '..', 'README.md'), { encoding: 'utf8' }, (err, data) =>
			err? onError(err):
			writeFile('./README.md', replaceCount(modules.length + ' one-liner functions', data), onFileWritten));
})

function onError(err) {
	if (err) {
		console.log(err);
		process.exit(1);
	}
}

function onFileWritten(err) {
	if (err) onError(err);
	console.log('updated function count');
	process.exit(0);
}