Create Domain Driven typescript modules

Date: 2018-10-22
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');

const createDir = (dir) => {
	if (!fs.existsSync(dir)){
		fs.mkdirSync(dir);
	}
}

const run = async (cmd, dir) => {
	return await new Promise((resolve, reject) => {
		console.log('>>>', `cd '${dir}'`)
		console.log('>>>', cmd);
		const r = exec(cmd, { cwd: dir, shell: true });
		r.stdout.pipe(process.stdout);
		r.on('exit', function (code) {
			if (code == 0) {
				resolve();
			} else {
				reject(code);
			}
		});
	})
};

const createProject = async (scope, dir, devDeps) => {
	createDir(dir);
	await run(`npm init -y --scope ${scope}`, dir);
	await run(`npm install --save-dev ${devDeps.join(' ')}`, dir);
}


const main = async () => {
	const scope = '@crm';

	await createProject(scope, `./app-domain`, ['typescript']);

	await createDir(path.resolve(`./primary-adapters`));
	await createProject(scope, `./primary-adapters/app-domain-tests`, ['typescript', 'jasmine']);
	await createProject(scope, `./primary-adapters/web`, ['typescript', 'jasmine']);

	await createDir(path.resolve(`./secondary-adapters`));
	await createProject(scope, `./secondary-adapters/http`, ['typescript', 'jasmine']);
	await createProject(scope, `./secondary-adapters/pouchdb`, ['typescript', 'jasmine']);

	console.log('finished');
	process.exit(0);
};

main();

 

15270cookie-checkCreate Domain Driven typescript modules