{"id":466,"date":"2011-09-22T08:55:36","date_gmt":"2011-09-22T12:55:36","guid":{"rendered":"https:\/\/www.goer.org\/wordpress\/howto_create_a_windows_8_metro_app_with_js_yui_3"},"modified":"2013-11-17T06:55:50","modified_gmt":"2013-11-17T06:55:50","slug":"howto_create_a_windows_8_metro_app_with_js_yui_3","status":"publish","type":"post","link":"https:\/\/www.goer.org\/Journal\/2011\/09\/howto_create_a_windows_8_metro_app_with_js_yui_3.html","title":{"rendered":"HOWTO Create a Windows 8 Metro App with JS and YUI 3"},"content":{"rendered":"<p>Before reading further, readers should know:<\/p>\n<ul>\n<li>I am a knucklehead.<\/li>\n<li>I am not an engineer by any means.<\/li>\n<li>I have no Windows development experience whatsoever. I do not know anything about the Windows developer stack.<\/li>\n<li>My last Windows machine at home was a homebrew PC in 2002. That year, I switched to OS X. The last Windows machine I used at work was in early 2005.<\/li>\n<li>The procedure below does things the stupid way, rather than the right or elegant way.<\/li>\n<\/ul>\n<p>To sum up &#8212; me: knucklehead. Windows: alien territory.<\/p>\n<p>Onward.<\/p>\n<h2>A Suboptimal Workflow for Metro App Development with YUI 3<\/h2>\n<ol>\n<li>\n<p>Download the Windows 8 Developer Preview. Install the ISO as a VM using VirtualBox, Fusion, or Parallels. FWIW, I used Parallels with 2 GB RAM on a 30 GB volume.<\/p>\n<p>Marvel at the fact that Windows installations take a lot less time today than they did on 2002-era hardware. Click through license agreements with enthusiasm. But don&#8217;t sign up for Live.<\/p>\n<\/li>\n<li>\n<p>Boot your brand new Windows 8 VM! Don&#8217;t let the fact that your virtual sound card is broken dampen your spirits.<\/p>\n<p>Stare at the <a href=\"http:\/\/images.search.yahoo.com\/search\/images?va=windows+8+tiles\">brave new tablety world that is Windows 8<\/a>. This doesn&#8217;t look like XP at all. You are&#8230; kind of intrigued, actually. Your Mom, however, is going to be super-pissed.<\/p>\n<\/li>\n<li>\n<p>Click the <strong>Visual Studio 11<\/strong> square-thingy. Start a JS project and choose one of the built-in templates.<\/p>\n<p>It&#8217;s&#8230; a single-page web app! It uses a brand new JavaScript framework called Win-NIH.js. No, it&#8217;s actually called WinJS. <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/apps\/br211369\">It&#8217;s even documented<\/a>. I&#8217;m sure it&#8217;s awesome.<\/p>\n<\/li>\n<li>\n<p>Delete all <code>script<\/code> and <code>link<\/code> references to WinJS and related CSS assets from the main <code>default.html<\/code> web page.<\/p>\n<\/li>\n<li>\n<p><strong>Important:<\/strong> disable Visual Studio&#8217;s auto-id-mangling by going to Tools -&gt; Options -&gt; Text Editor -&gt; HTML -&gt; Miscellaneous and unchecking &#8220;Auto ID elements on paste in Source view&#8221;. (Thanks, <a href=\"http:\/\/www.netspectrum.de\/\">Hardy Erlinger<\/a>!) Otherwise, copying and pasting will cause Visual Studio 11 to stomp over all the IDs in the HTML, breaking your project. Yes, really.<\/p>\n<p>Now you&#8217;re going to need some code. So fire up Internet Explorer &#8212; might as well go all-in on this Microsoft stuff.<\/p>\n<\/li>\n<li>\n<p>Go to <a href=\"http:\/\/yuilibrary.com\">yuilibrary.com<\/a> and view the <a href=\"http:\/\/yuilibrary.com\/yui\/docs\/app\/app-todo.html\">TODO App Example<\/a>, a toy single-page app that demonstrates how to use the <a href=\"http:\/\/yuilibrary.com\/yui\/docs\/app\/\">YUI 3 App Framework<\/a>. Scroll down to the bottom of the page, copy the complete TODO example, and paste it into <code>default.html<\/code>. Good artists copy, great artists steal.<\/p>\n<\/li>\n<li>\n<p>Now it&#8217;s time to load the YUI library itself, or at least the modules that power the YUI 3 TODO app. Go to the <a href=\"http:\/\/yuilibrary.com\/yui\/configurator\/\">YUI 3 Dependency Configurator<\/a>. Select the modules <code>event-focus<\/code>, <code>json<\/code>, <code>model<\/code>, <code>model-list<\/code>, and <code>view<\/code> in the configurator, copy the resulting combo-load URL, and paste that URL into a new IE tab. IE will offer to open or save the JavaScript file. Click <strong>Save<\/strong>.<\/p>\n<\/li>\n<li>\n<p>Return to the project in Visual Studio. Right-click the <code>\/js<\/code> folder and add an existing file. Browse to the Downloads folder and add the <code>combo.js<\/code> file. When the file is imported to your project, feel free to rename it to <code>yui-todo.js<\/code> or something else meaningful.<\/p>\n<\/li>\n<li>\n<p>In <code>default.html<\/code>, add a script element with a src of <code>\/js\/yui-todo.js<\/code> above all other script elements.<\/p>\n<\/li>\n<li>\n<p>In the <code>YUI().use()<\/code> call, replace the list of module names with just <code>'*'<\/code>.<\/p>\n<\/li>\n<li>\n<p>From the <strong>Build<\/strong> menu, click <strong>Deploy<\/strong>. This builds your app and then side-loads it into your Windows environment, all in one step.<\/p>\n<\/li>\n<li>\n<p>Go back to the main Windows 8 tablety area. Scroll all the way to the right, and you will see your TODO app, with a generic black icon. Single-click to launch.<\/p>\n<\/li>\n<\/ol>\n<p>Congratulations! You&#8217;ve built, deployed, and run your first JS-style Metro app. It works exactly like the browser version. Except you can&#8217;t exit the app. Hahaha! You&#8217;re going to have to throw away your VM and start over.<\/p>\n<p>Kidding. To quit the Metro app, hit the CMD button. To make changes, you&#8217;ll want to delete the deployed app from your environment before attempting to rebuild and redeploy the app again.<\/p>\n<p>Elapsed time from launching Visual Studio (knowing nothing) to a deployed Metro app (still knowing nothing): a little under an hour. I actually wasted most of that time on other things:<\/p>\n<ul>\n<li>Stumbling around an unfamiliar UI, figuring out how to navigate around etc.<\/li>\n<li>Fooling around in Visual Studio &#8212; looking at the source files, building and deploying one of the default projects, building and deploying a static HTML page with one JS function all as a Hello World project, etc.<\/li>\n<li>The big one, the ID-stompage problem. This eventually required doing a Debug build. I have no idea how to use the Visual Studio debugger, and it slows things down tremendously, but it <em>does<\/em> generate some JS console log output for you when you go back to run the app.<\/li>\n<\/ul>\n<h2>Observations<\/h2>\n<ul>\n<li>Despite running into a serious bug in Visual Studio 11, I was really impressed that the whole thing worked as advertised. You are not locked into WinJS at all. If it runs in IE 10, it should build as a Metro app. I dig it.<\/li>\n<li><a href=\"http:\/\/tvtropes.org\/pmwiki\/pmwiki.php\/Main\/AsYouKnow\">As You Know Bob<\/a>, in the browser YUI 3 is meant to load a small seed file, and then <a href=\"http:\/\/yuilibrary.com\/yui\/docs\/yui\/index.html\">asynchronously load module files from a server or CDN running a combo-loader<\/a>. For Metro apps, we&#8217;re subverting this process by hand-crafting a physical rollup file of the modules we need and calling <code>YUI().use('*')<\/code>. Obviously, the way I actually created that rollup is a huge hack.<\/li>\n<li>I haven&#8217;t actually tested the YUI 3 Loader in Metro &#8212; it would be neat if it worked &#8212; but the loader is probably not all that relevant for creating Metro apps anyway.<\/li>\n<li>I don&#8217;t really know Visual Studio at all, so I don&#8217;t know how to develop iteratively there very well. Also, if you need to track down a runtime error, doing a Debug build is particularly painful. I&#8217;m sure Visual Studio experts know exactly how to do this stuff efficiently. See also: I am a knucklehead.<\/li>\n<\/ul>\n<p>Anyway, my recommendation for the typical frontend engineer is to just stick with the development environment you like. Build and test your app in browsers, and basically just use Visual Studio as a build tool. I bet someone smarter than me knows how to automatically import code into Visual Studio and trigger a build headlessly. That would be nifty.<\/p>\n<h2>Postscript for Future Microsoft App Store Employees<\/h2>\n<p>If you have been wondering why you keep having to reject submissions of this weird &#8220;YUI 3 TODO app&#8221; &#8212; well, this post is probably why. My sincere apologies.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Despite running into a serious bug in Visual Studio 11, I was really impressed that the whole thing worked as advertised. You are not locked into WinJS at all. If it runs in IE 10, it should build as a Metro app. I dig it.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,3],"tags":[],"class_list":["post-466","post","type-post","status-publish","format-standard","hentry","category-howto","category-web"],"_links":{"self":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/posts\/466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/comments?post=466"}],"version-history":[{"count":3,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/posts\/466\/revisions"}],"predecessor-version":[{"id":599,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/posts\/466\/revisions\/599"}],"wp:attachment":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/media?parent=466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/categories?post=466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/tags?post=466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}