{"id":1527,"date":"2018-10-22T16:26:18","date_gmt":"2018-10-22T15:26:18","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=1527"},"modified":"2018-10-22T16:26:18","modified_gmt":"2018-10-22T15:26:18","slug":"create-domain-driven-typescript-modules","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/create-domain-driven-typescript-modules\/","title":{"rendered":"Create Domain Driven typescript modules"},"content":{"rendered":"<pre class=\"lang:js decode:true \">const fs = require('fs');\r\nconst path = require('path');\r\nconst { exec } = require('child_process');\r\n\r\nconst createDir = (dir) =&gt; {\r\n\tif (!fs.existsSync(dir)){\r\n\t\tfs.mkdirSync(dir);\r\n\t}\r\n}\r\n\r\nconst run = async (cmd, dir) =&gt; {\r\n\treturn await new Promise((resolve, reject) =&gt; {\r\n\t\tconsole.log('&gt;&gt;&gt;', `cd '${dir}'`)\r\n\t\tconsole.log('&gt;&gt;&gt;', cmd);\r\n\t\tconst r = exec(cmd, { cwd: dir, shell: true });\r\n\t\tr.stdout.pipe(process.stdout);\r\n\t\tr.on('exit', function (code) {\r\n\t\t\tif (code == 0) {\r\n\t\t\t\tresolve();\r\n\t\t\t} else {\r\n\t\t\t\treject(code);\r\n\t\t\t}\r\n\t\t});\r\n\t})\r\n};\r\n\r\nconst createProject = async (scope, dir, devDeps) =&gt; {\r\n\tcreateDir(dir);\r\n\tawait run(`npm init -y --scope ${scope}`, dir);\r\n\tawait run(`npm install --save-dev ${devDeps.join(' ')}`, dir);\r\n}\r\n\r\n\r\nconst main = async () =&gt; {\r\n\tconst scope = '@crm';\r\n\r\n\tawait createProject(scope, `.\/app-domain`, ['typescript']);\r\n\r\n\tawait createDir(path.resolve(`.\/primary-adapters`));\r\n\tawait createProject(scope, `.\/primary-adapters\/app-domain-tests`, ['typescript', 'jasmine']);\r\n\tawait createProject(scope, `.\/primary-adapters\/web`, ['typescript', 'jasmine']);\r\n\r\n\tawait createDir(path.resolve(`.\/secondary-adapters`));\r\n\tawait createProject(scope, `.\/secondary-adapters\/http`, ['typescript', 'jasmine']);\r\n\tawait createProject(scope, `.\/secondary-adapters\/pouchdb`, ['typescript', 'jasmine']);\r\n\r\n\tconsole.log('finished');\r\n\tprocess.exit(0);\r\n};\r\n\r\nmain();\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>const fs = require(&#8216;fs&#8217;); const path = require(&#8216;path&#8217;); const { exec } = require(&#8216;child_process&#8217;); const createDir = (dir) =&gt; { if (!fs.existsSync(dir)){ fs.mkdirSync(dir); } } const run = async (cmd, dir) =&gt; { return await new Promise((resolve, reject) =&gt; { console.log(&#8216;&gt;&gt;&gt;&#8217;, `cd &#8216;${dir}&#8217;`) console.log(&#8216;&gt;&gt;&gt;&#8217;, cmd); const r = exec(cmd, { cwd: dir, shell: true }); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1527","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1527","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=1527"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1527\/revisions"}],"predecessor-version":[{"id":1528,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1527\/revisions\/1528"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=1527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=1527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=1527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}