create new project CLI
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/commit/8d4e7135 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/8d4e7135 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/8d4e7135 Branch: refs/heads/master Commit: 8d4e7135ab0ad388ad249ffe4577c78f3e60a346 Parents: ac1ba7c Author: unknown <admin@MBP2W7.(none)> Authored: Mon Jun 4 14:17:25 2012 -0700 Committer: Jesse MacFadyen <purplecabb...@gmail.com> Committed: Tue Jun 5 12:48:35 2012 -0700 ---------------------------------------------------------------------- bin/create.bat | 1 + bin/create.js | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/8d4e7135/bin/create.bat ---------------------------------------------------------------------- diff --git a/bin/create.bat b/bin/create.bat new file mode 100644 index 0000000..70b6203 --- /dev/null +++ b/bin/create.bat @@ -0,0 +1 @@ +cscript bin\\create.js $* \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/8d4e7135/bin/create.js ---------------------------------------------------------------------- diff --git a/bin/create.js b/bin/create.js new file mode 100644 index 0000000..c58997c --- /dev/null +++ b/bin/create.js @@ -0,0 +1,154 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ + +/* + * create a cordova/wp7 project + * + * USAGE + * ./create [path package activity] + */ + +function Usage() +{ + WScript.Echo("Usage: create [PATH]"); // [PACKAGE] [ACTIVITY]"); + WScript.Echo("Creates a new cordova/wp7 project."); +} + +var ForReading = 1, ForWriting = 2, ForAppending = 8; +var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0; + +function read(filename) { + //WScript.Echo('Reading in ' + filename); + var fso=WScript.CreateObject("Scripting.FileSystemObject"); + var f=fso.OpenTextFile(filename, 1,2); + var s=f.ReadAll(); + f.Close(); + return s; +} + +function write(filename, contents) { + var fso=WScript.CreateObject("Scripting.FileSystemObject"); + var f=fso.OpenTextFile(filename, ForWriting, TristateTrue); + f.Write(contents); + f.Close(); +} +function replaceInFile(filename, regexp, replacement) { + write(filename,read(filename).replace(regexp,replacement)); +} +function exec(s, output) { + WScript.Echo('Executing::' + s); + var o=shell.Exec(s); + while (o.Status == 0) { + WScript.Sleep(100); + } + WScript.Echo(o.StdErr.ReadAll()); + WScript.Echo("Command exited with code " + o.Status); +} + +function fork(s) { + WScript.Echo('Executing ' + s); + var o=shell.Exec(s); + while (o.Status != 1) { + WScript.Sleep(100); + } + WScript.Echo(o.StdOut.ReadAll()); + WScript.Echo(o.StdErr.ReadAll()); + WScript.Echo("Command exited with code " + o.Status); +} + +function genGuid() +{ + var TypeLib = WScript.CreateObject("Scriptlet.TypeLib"); + strGuid = TypeLib.Guid.split("}")[0]; // there is extra crap after the } that is causing file streams to break, probably an EOF ... + strGuid = strGuid.replace(/[\{\}]/g,""); + return strGuid; +} + +var args = WScript.Arguments, + PROJECT_PATH="..\\example\\", + PACKAGE="org.apache.cordova.example", + ACTIVITY="cordovaExample", + shell=WScript.CreateObject("WScript.Shell"); + +// working dir +var ROOT = WScript.ScriptFullName.split('\\bin\\create.js').join(''); + +if (args.Count() > 0) +{ + PROJECT_PATH = args(0); + if(PROJECT_PATH.indexOf("--help") > -1 || + PROJECT_PATH.indexOf("/?") > -1 ) + { + Usage(); + WScript.Quit(1); + } + + if(args.Count() > 1) + { + PACKAGE=args(1); + } + + if(args.Count() > 2) + { + ACTIVITY=args(2); + } + +} + +// WScript.Echo("ROOT = " + ROOT); +// WScript.Echo('PROJECT_PATH ' + PROJECT_PATH); +// WScript.Echo('PACKAGE ' + PACKAGE); +// WScript.Echo('ACTIVITY ' + ACTIVITY); + +var PACKAGE_AS_PATH=PACKAGE.replace(/\./g, '\\'); +WScript.Echo("Package as path: " + PACKAGE_AS_PATH); + +var newProjGuid = genGuid(); + +// Copy the template source files to the new destination +exec('cmd /c xcopy templates\\full ' + PROJECT_PATH + ' /S /Y'); +// replace the guid in the AppManifest +replaceInFile(PROJECT_PATH + "\\Properties\\WMAppManifest.xml","$guid1$",newProjGuid); +// replace safe-project-name in AppManifest +replaceInFile(PROJECT_PATH + "\\Properties\\WMAppManifest.xml",/\$safeprojectname\$/g,ACTIVITY); + +WScript.Echo("Generated project : " + PROJECT_PATH + ACTIVITY); + +// TODO: Name the project according to the arguments +// update the solution to include the new project by name +// version BS +// index.html title set to project name ? + + + + + + +// var ACTIVITY_PATH=PROJECT_PATH+'\\src\\'+PACKAGE_AS_PATH+'\\'+ACTIVITY+'.java'; +// var MANIFEST_PATH=PROJECT_PATH+'\\AndroidManifest.xml'; +// var TARGET=shell.Exec('android.bat list targets').StdOut.ReadAll().match(/id:\s([0-9]).*/)[1]; +// var VERSION=read('VERSION').replace(/\r\n/,'').replace(/\n/,''); + +// WScript.Echo("Project path: " + PROJECT_PATH); +// WScript.Echo("Package: " + PACKAGE); +// WScript.Echo("Activity: " + ACTIVITY); +// WScript.Echo("Package as path: " + PACKAGE_AS_PATH); +// WScript.Echo("Activity path: " + ACTIVITY_PATH); +// WScript.Echo("Manifest path: " + MANIFEST_PATH); +// WScript.Echo("Cordova version: " + VERSION);