UNPKG

2.99 kBJavaScriptView Raw
1require("colors");
2var FS = require("fs");
3var Tpl = require("./template");
4var Path = require("path");
5var Input = require('readline-sync');
6var ChildProcess = require('child_process');
7
8
9exports.start = function( package ) {
10 console.log("Make sure you are in an empty folder.\n".bold);
11 var url = Input.question( "Please enter the URL of your Github project: " );
12 console.log( "Cloning the project...".cyan );
13 console.log( exec(
14 "git clone " + url + " ."
15 ).toString() );
16 var pieces = url.split( '/' );
17 var name = pieces.pop();
18 name = name.substr( 0, name.length - 4 );
19 var author = pieces.pop();
20 var desc = Input.question( "Description of your project: " );
21
22 FS.writeFileSync(
23 "package.json",
24 Tpl.file(
25 "package.json", {
26 url: url,
27 bugs: "https://github.com/" + author + "/" + name + "/issues",
28 name: name,
29 desc: desc,
30 version: package.version,
31 author: author,
32 homepage: "https://" + author + ".github.io/" + name
33 }
34 ).out
35 );
36 FS.writeFileSync(
37 "karma.conf.js",
38 Tpl.file( "karma.conf.js", {} ).out
39 );
40
41 var dependencies = [
42 "jasmine-core", "karma", "karma-chrome-launcher", "karma-firefox-launcher",
43 "karma-jasmine", "toloframework"
44 ];
45 dependencies.forEach(function ( dep ) {
46 console.log( ("Installing " + dep + "...").cyan );
47 console.log( exec(
48 "npm install --save " + dep
49 ).toString() );
50 });
51 FS.writeFileSync(
52 ".gitignore",
53 "*~\n"
54 + "*#\n"
55 + "tmp/\n"
56 + "www/\n"
57 + "node_modules/\n"
58 );
59
60 console.log( "Preparing branch gh-pages...".cyan );
61 var branches = exec( "git branch" );
62 if( branches.indexOf( " gh-pages" ) == -1 ) {
63 exec( "git branch gh-pages" );
64 }
65 exec( "git add . -A" );
66 exec( "git commit -am 'first commit.'" );
67 exec( "git push" );
68 exec( "git push origin gh-pages" );
69 console.log( "Preparing output...".cyan );
70 if( !FS.existsSync( "www" ) ) {
71 FS.mkdirSync( "www" );
72 }
73 if( !FS.existsSync( "src" ) ) {
74 FS.mkdirSync( "src" );
75 }
76 if( !FS.existsSync( "src/mod" ) ) {
77 FS.mkdirSync( "src/mod" );
78 }
79 exec( "git clone " + url + " ./www" );
80 exec( "cd www && git checkout gh-pages" );
81 FS.writeFileSync(
82 "src/index.html",
83 "<x-html app='app' title='" + name + "'></x-html>"
84 );
85 FS.writeFileSync(
86 "src/mod/app.js",
87 "\n\nexports.start = function() {\n};\n"
88 );
89};
90
91
92function exec( cmd ) {
93 try {
94 console.log( "> " + cmd.yellow );
95 return ChildProcess.execSync( cmd ).toString();
96 }
97 catch( ex ) {
98 console.log( ("" + ex).red.bold );
99 }
100}