{"action":"created","comment":{"url":"https://api.github.com/repos/ninjadev/nin/pulls/comments/35676446","id":35676446,"diff_hunk":"@@ -1,21 +1,66 @@\n var fs = require('fs'),\n     path = require('path'),\n-    utils = require('../utils');\n+    utils = require('../utils'),\n+    mkdirp = require('mkdirp');\n \n-var generate = function(toGenerate, path) {\n-  var projectRoot = utils.findProjectRoot(path);\n+var generate = function(type, name) {\n+  var projectRoot = utils.findProjectRoot(process.cwd());\n   if (projectRoot == '') {\n     process.stderr.write('Could not find nin.json in project root\\n');\n     process.exit(1);\n   }\n \n-  if (endsWith(toGenerate, 'Layer')) {\n-    generateLayer(toGenerate, projectRoot);\n-    addToLayers(toGenerate, projectRoot);\n+  if (name == \"\") {\n+    return;\n+  }\n+\n+  var camelizedName = utils.camelize(name);\n+\n+  switch (type) {\n+    case 'layer':\n+      generateLayer(camelizedName, 'TemplateLayer.js',\n+          [[/TemplateLayer/g, camelizedName]],\n+          projectRoot);\n+\n+      addToLayers(camelizedName, 'red', projectRoot);\n+      break;\n+\n+    case 'shader':\n+      generateShader(camelizedName, projectRoot);\n+      break;\n+\n+    case 'shaderWithLayer':\n+      var shaderLayerName = camelizedName + 'Layer';\n+\n+      generateShader(camelizedName, projectRoot);\n+      generateLayer(shaderLayerName, 'TemplateShaderLayer.js',\n+          [[/TemplateLayer/g, shaderLayerName],\n+           [/TemplateShader/g, camelizedName]],\n+          projectRoot);\n+\n+      addToLayers(camelizedName + 'Layer', 'pink', projectRoot);\n+      break;\n+\n+    default:\n+      process.stderr.write('Attempted to generate resource without generator:', type, '\\n');\n   }\n }\n \n-var generateLayer = function(layerName, projectRoot) {\n+var generateShader = function(shaderName, projectRoot) {\n+  var targetShaderPath = path.join(projectRoot, 'src', 'shaders', shaderName),\n+      templateShaderPath = path.join(__dirname, 'templateShader');\n+\n+  mkdirp.sync(targetShaderPath);\n+  fs.readdirSync(templateShaderPath).forEach(function (fileName) {\n+    var from = path.join(templateShaderPath, fileName),\n+        to = path.join(targetShaderPath, fileName);\n+    fs.createReadStream(from).pipe(fs.createWriteStream(to));\n+  });\n+\n+  process.stdout.write('Generated shader ' + shaderName + '\\n');","path":"nin/backend/generate/generate.js","position":67,"original_position":67,"commit_id":"08d1cd8f7b9020343024ded9aaf9723d14426dc9","original_commit_id":"08d1cd8f7b9020343024ded9aaf9723d14426dc9","user":{"login":"stianjensen","id":1413267,"avatar_url":"https://avatars.githubusercontent.com/u/1413267?v=3","gravatar_id":"","url":"https://api.github.com/users/stianjensen","html_url":"https://github.com/stianjensen","followers_url":"https://api.github.com/users/stianjensen/followers","following_url":"https://api.github.com/users/stianjensen/following{/other_user}","gists_url":"https://api.github.com/users/stianjensen/gists{/gist_id}","starred_url":"https://api.github.com/users/stianjensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stianjensen/subscriptions","organizations_url":"https://api.github.com/users/stianjensen/orgs","repos_url":"https://api.github.com/users/stianjensen/repos","events_url":"https://api.github.com/users/stianjensen/events{/privacy}","received_events_url":"https://api.github.com/users/stianjensen/received_events","type":"User","site_admin":false},"body":"How does this differ from console.log?","created_at":"2015-07-28T17:40:31Z","updated_at":"2015-07-28T17:40:31Z","html_url":"https://github.com/ninjadev/nin/pull/143#discussion_r35676446","pull_request_url":"https://api.github.com/repos/ninjadev/nin/pulls/143","_links":{"self":{"href":"https://api.github.com/repos/ninjadev/nin/pulls/comments/35676446"},"html":{"href":"https://github.com/ninjadev/nin/pull/143#discussion_r35676446"},"pull_request":{"href":"https://api.github.com/repos/ninjadev/nin/pulls/143"}}},"pull_request":{"url":"https://api.github.com/repos/ninjadev/nin/pulls/143","id":40836833,"html_url":"https://github.com/ninjadev/nin/pull/143","diff_url":"https://github.com/ninjadev/nin/pull/143.diff","patch_url":"https://github.com/ninjadev/nin/pull/143.patch","issue_url":"https://api.github.com/repos/ninjadev/nin/issues/143","number":143,"state":"open","locked":false,"title":"Add generate to menu","user":{"login":"aleksanb","id":1413365,"avatar_url":"https://avatars.githubusercontent.com/u/1413365?v=3","gravatar_id":"","url":"https://api.github.com/users/aleksanb","html_url":"https://github.com/aleksanb","followers_url":"https://api.github.com/users/aleksanb/followers","following_url":"https://api.github.com/users/aleksanb/following{/other_user}","gists_url":"https://api.github.com/users/aleksanb/gists{/gist_id}","starred_url":"https://api.github.com/users/aleksanb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aleksanb/subscriptions","organizations_url":"https://api.github.com/users/aleksanb/orgs","repos_url":"https://api.github.com/users/aleksanb/repos","events_url":"https://api.github.com/users/aleksanb/events{/privacy}","received_events_url":"https://api.github.com/users/aleksanb/received_events","type":"User","site_admin":false},"body":"\r\n![stufz](https://cloud.githubusercontent.com/assets/1413365/8896409/00d023a4-33fc-11e5-86e9-5b94fcfbb80d.png)\r\n\r\nWe can now generate resources from the frontend.\r\nOne more step towards full-fledged IDE.","created_at":"2015-07-25T13:21:22Z","updated_at":"2015-07-28T17:40:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"82ab78db319c038c0ce7cda99d26ca63f2098da4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ninjadev/nin/pulls/143/commits","review_comments_url":"https://api.github.com/repos/ninjadev/nin/pulls/143/comments","review_comment_url":"https://api.github.com/repos/ninjadev/nin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ninjadev/nin/issues/143/comments","statuses_url":"https://api.github.com/repos/ninjadev/nin/statuses/08d1cd8f7b9020343024ded9aaf9723d14426dc9","head":{"label":"ninjadev:add-generate-to-menu","ref":"add-generate-to-menu","sha":"08d1cd8f7b9020343024ded9aaf9723d14426dc9","user":{"login":"ninjadev","id":1992931,"avatar_url":"https://avatars.githubusercontent.com/u/1992931?v=3","gravatar_id":"","url":"https://api.github.com/users/ninjadev","html_url":"https://github.com/ninjadev","followers_url":"https://api.github.com/users/ninjadev/followers","following_url":"https://api.github.com/users/ninjadev/following{/other_user}","gists_url":"https://api.github.com/users/ninjadev/gists{/gist_id}","starred_url":"https://api.github.com/users/ninjadev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ninjadev/subscriptions","organizations_url":"https://api.github.com/users/ninjadev/orgs","repos_url":"https://api.github.com/users/ninjadev/repos","events_url":"https://api.github.com/users/ninjadev/events{/privacy}","received_events_url":"https://api.github.com/users/ninjadev/received_events","type":"Organization","site_admin":false},"repo":{"id":13017625,"name":"nin","full_name":"ninjadev/nin","owner":{"login":"ninjadev","id":1992931,"avatar_url":"https://avatars.githubusercontent.com/u/1992931?v=3","gravatar_id":"","url":"https://api.github.com/users/ninjadev","html_url":"https://github.com/ninjadev","followers_url":"https://api.github.com/users/ninjadev/followers","following_url":"https://api.github.com/users/ninjadev/following{/other_user}","gists_url":"https://api.github.com/users/ninjadev/gists{/gist_id}","starred_url":"https://api.github.com/users/ninjadev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ninjadev/subscriptions","organizations_url":"https://api.github.com/users/ninjadev/orgs","repos_url":"https://api.github.com/users/ninjadev/repos","events_url":"https://api.github.com/users/ninjadev/events{/privacy}","received_events_url":"https://api.github.com/users/ninjadev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ninjadev/nin","description":"nin is ninjatool","fork":false,"url":"https://api.github.com/repos/ninjadev/nin","forks_url":"https://api.github.com/repos/ninjadev/nin/forks","keys_url":"https://api.github.com/repos/ninjadev/nin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ninjadev/nin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ninjadev/nin/teams","hooks_url":"https://api.github.com/repos/ninjadev/nin/hooks","issue_events_url":"https://api.github.com/repos/ninjadev/nin/issues/events{/number}","events_url":"https://api.github.com/repos/ninjadev/nin/events","assignees_url":"https://api.github.com/repos/ninjadev/nin/assignees{/user}","branches_url":"https://api.github.com/repos/ninjadev/nin/branches{/branch}","tags_url":"https://api.github.com/repos/ninjadev/nin/tags","blobs_url":"https://api.github.com/repos/ninjadev/nin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ninjadev/nin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ninjadev/nin/git/refs{/sha}","trees_url":"https://api.github.com/repos/ninjadev/nin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ninjadev/nin/statuses/{sha}","languages_url":"https://api.github.com/repos/ninjadev/nin/languages","stargazers_url":"https://api.github.com/repos/ninjadev/nin/stargazers","contributors_url":"https://api.github.com/repos/ninjadev/nin/contributors","subscribers_url":"https://api.github.com/repos/ninjadev/nin/subscribers","subscription_url":"https://api.github.com/repos/ninjadev/nin/subscription","commits_url":"https://api.github.com/repos/ninjadev/nin/commits{/sha}","git_commits_url":"https://api.github.com/repos/ninjadev/nin/git/commits{/sha}","comments_url":"https://api.github.com/repos/ninjadev/nin/comments{/number}","issue_comment_url":"https://api.github.com/repos/ninjadev/nin/issues/comments{/number}","contents_url":"https://api.github.com/repos/ninjadev/nin/contents/{+path}","compare_url":"https://api.github.com/repos/ninjadev/nin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ninjadev/nin/merges","archive_url":"https://api.github.com/repos/ninjadev/nin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ninjadev/nin/downloads","issues_url":"https://api.github.com/repos/ninjadev/nin/issues{/number}","pulls_url":"https://api.github.com/repos/ninjadev/nin/pulls{/number}","milestones_url":"https://api.github.com/repos/ninjadev/nin/milestones{/number}","notifications_url":"https://api.github.com/repos/ninjadev/nin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ninjadev/nin/labels{/name}","releases_url":"https://api.github.com/repos/ninjadev/nin/releases{/id}","created_at":"2013-09-22T17:30:37Z","updated_at":"2015-07-12T21:22:19Z","pushed_at":"2015-07-28T17:33:24Z","git_url":"git://github.com/ninjadev/nin.git","ssh_url":"git@github.com:ninjadev/nin.git","clone_url":"https://github.com/ninjadev/nin.git","svn_url":"https://github.com/ninjadev/nin","homepage":null,"size":26936,"stargazers_count":8,"watchers_count":8,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":5,"forks":1,"open_issues":5,"watchers":8,"default_branch":"master"}},"base":{"label":"ninjadev:master","ref":"master","sha":"8efb60164c0ca04475f500513cc86a2a704676ca","user":{"login":"ninjadev","id":1992931,"avatar_url":"https://avatars.githubusercontent.com/u/1992931?v=3","gravatar_id":"","url":"https://api.github.com/users/ninjadev","html_url":"https://github.com/ninjadev","followers_url":"https://api.github.com/users/ninjadev/followers","following_url":"https://api.github.com/users/ninjadev/following{/other_user}","gists_url":"https://api.github.com/users/ninjadev/gists{/gist_id}","starred_url":"https://api.github.com/users/ninjadev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ninjadev/subscriptions","organizations_url":"https://api.github.com/users/ninjadev/orgs","repos_url":"https://api.github.com/users/ninjadev/repos","events_url":"https://api.github.com/users/ninjadev/events{/privacy}","received_events_url":"https://api.github.com/users/ninjadev/received_events","type":"Organization","site_admin":false},"repo":{"id":13017625,"name":"nin","full_name":"ninjadev/nin","owner":{"login":"ninjadev","id":1992931,"avatar_url":"https://avatars.githubusercontent.com/u/1992931?v=3","gravatar_id":"","url":"https://api.github.com/users/ninjadev","html_url":"https://github.com/ninjadev","followers_url":"https://api.github.com/users/ninjadev/followers","following_url":"https://api.github.com/users/ninjadev/following{/other_user}","gists_url":"https://api.github.com/users/ninjadev/gists{/gist_id}","starred_url":"https://api.github.com/users/ninjadev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ninjadev/subscriptions","organizations_url":"https://api.github.com/users/ninjadev/orgs","repos_url":"https://api.github.com/users/ninjadev/repos","events_url":"https://api.github.com/users/ninjadev/events{/privacy}","received_events_url":"https://api.github.com/users/ninjadev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ninjadev/nin","description":"nin is ninjatool","fork":false,"url":"https://api.github.com/repos/ninjadev/nin","forks_url":"https://api.github.com/repos/ninjadev/nin/forks","keys_url":"https://api.github.com/repos/ninjadev/nin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ninjadev/nin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ninjadev/nin/teams","hooks_url":"https://api.github.com/repos/ninjadev/nin/hooks","issue_events_url":"https://api.github.com/repos/ninjadev/nin/issues/events{/number}","events_url":"https://api.github.com/repos/ninjadev/nin/events","assignees_url":"https://api.github.com/repos/ninjadev/nin/assignees{/user}","branches_url":"https://api.github.com/repos/ninjadev/nin/branches{/branch}","tags_url":"https://api.github.com/repos/ninjadev/nin/tags","blobs_url":"https://api.github.com/repos/ninjadev/nin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ninjadev/nin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ninjadev/nin/git/refs{/sha}","trees_url":"https://api.github.com/repos/ninjadev/nin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ninjadev/nin/statuses/{sha}","languages_url":"https://api.github.com/repos/ninjadev/nin/languages","stargazers_url":"https://api.github.com/repos/ninjadev/nin/stargazers","contributors_url":"https://api.github.com/repos/ninjadev/nin/contributors","subscribers_url":"https://api.github.com/repos/ninjadev/nin/subscribers","subscription_url":"https://api.github.com/repos/ninjadev/nin/subscription","commits_url":"https://api.github.com/repos/ninjadev/nin/commits{/sha}","git_commits_url":"https://api.github.com/repos/ninjadev/nin/git/commits{/sha}","comments_url":"https://api.github.com/repos/ninjadev/nin/comments{/number}","issue_comment_url":"https://api.github.com/repos/ninjadev/nin/issues/comments{/number}","contents_url":"https://api.github.com/repos/ninjadev/nin/contents/{+path}","compare_url":"https://api.github.com/repos/ninjadev/nin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ninjadev/nin/merges","archive_url":"https://api.github.com/repos/ninjadev/nin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ninjadev/nin/downloads","issues_url":"https://api.github.com/repos/ninjadev/nin/issues{/number}","pulls_url":"https://api.github.com/repos/ninjadev/nin/pulls{/number}","milestones_url":"https://api.github.com/repos/ninjadev/nin/milestones{/number}","notifications_url":"https://api.github.com/repos/ninjadev/nin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ninjadev/nin/labels{/name}","releases_url":"https://api.github.com/repos/ninjadev/nin/releases{/id}","created_at":"2013-09-22T17:30:37Z","updated_at":"2015-07-12T21:22:19Z","pushed_at":"2015-07-28T17:33:24Z","git_url":"git://github.com/ninjadev/nin.git","ssh_url":"git@github.com:ninjadev/nin.git","clone_url":"https://github.com/ninjadev/nin.git","svn_url":"https://github.com/ninjadev/nin","homepage":null,"size":26936,"stargazers_count":8,"watchers_count":8,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":5,"forks":1,"open_issues":5,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ninjadev/nin/pulls/143"},"html":{"href":"https://github.com/ninjadev/nin/pull/143"},"issue":{"href":"https://api.github.com/repos/ninjadev/nin/issues/143"},"comments":{"href":"https://api.github.com/repos/ninjadev/nin/issues/143/comments"},"review_comments":{"href":"https://api.github.com/repos/ninjadev/nin/pulls/143/comments"},"review_comment":{"href":"https://api.github.com/repos/ninjadev/nin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ninjadev/nin/pulls/143/commits"},"statuses":{"href":"https://api.github.com/repos/ninjadev/nin/statuses/08d1cd8f7b9020343024ded9aaf9723d14426dc9"}}}}