You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2013/08/23 23:49:15 UTC
[09/14] git commit: added node version of create script
added node version of create script
Project: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/commit/73597797
Tree: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/tree/73597797
Diff: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/diff/73597797
Branch: refs/heads/master
Commit: 73597797de76b8df5e6d766192476e5b22f2a685
Parents: 375d3d6
Author: Steven Gill <st...@gmail.com>
Authored: Wed Aug 21 15:34:58 2013 -0700
Committer: Steven Gill <st...@gmail.com>
Committed: Fri Aug 23 14:32:29 2013 -0700
----------------------------------------------------------------------
bin/check_reqs | 26 ++++++
bin/create | 110 +++++++++++++++++++++++--
bin/templates/project/www/manifest.webapp | 14 ----
framework/manifest.webapp | 14 ++++
package.json | 28 +++++++
5 files changed, 169 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/73597797/bin/check_reqs
----------------------------------------------------------------------
diff --git a/bin/check_reqs b/bin/check_reqs
new file mode 100644
index 0000000..15f163a
--- /dev/null
+++ b/bin/check_reqs
@@ -0,0 +1,26 @@
+#!/usr/bin/env node
+
+/*
+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.
+*/
+
+//add methods as we determine what are the requirements
+
+module.exports.run = function() {
+ return true;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/73597797/bin/create
----------------------------------------------------------------------
diff --git a/bin/create b/bin/create
index 8161907..7b9fa3f 100755
--- a/bin/create
+++ b/bin/create
@@ -1,12 +1,104 @@
+#!/usr/bin/env node
-BUILD_PATH="$( cd "$( dirname "$0" )/.." && pwd )"
-VERSION=$(cat "$BUILD_PATH"/VERSION)
-PROJECT_PATH="${1:-'./example'}"
+/*
+ * 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.
+ */
+
+var fs = require('fs'),
+ shjs = require('shelljs'),
+ args = process.argv,
+ path = require('path'),
+ check_reqs = require('./check_reqs');
-if [ -d "$PROJECT_PATH" ]
-then
- echo "Project already exists! Delete and recreate"
- exit 1
-fi
+/*
+* $ create [options]
+*
+* Creates an firefoxos application with the given options.
+*
+* Options:
+*
+* - `project_path` {String} Path to the new Cordova android project.
+* - `package_name`{String} Package name, following reverse-domain style convention.
+* - `project_name` {String} Project name.
+*/
-cp -r "`dirname $0`/templates/project" "$PROJECT_PATH"
\ No newline at end of file
+// Support basic help commands
+if((args[2] == '--help' || args[2] == '/?' || args[2] == '-h' ||
+ args[2] == 'help' || args[2] == '-help' || args[2] == '/help')) {
+ help();
+} else {
+ main(args[2], args[3], args[4]);
+}
+
+function main(project_path,package_name,project_name){
+ var ROOT = path.join(__dirname, '..');
+ console.log(ROOT);
+
+ var VERSION = fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf-8');
+ console.log(VERSION);
+
+ // Set default values for path, package and name
+ project_path = typeof project_path !== 'undefined' ? project_path : "CordovaExample";
+ package_name = typeof package_name !== 'undefined' ? package_name : 'org.apache.cordova.example';
+ project_name = typeof project_name !== 'undefined' ? project_name : 'CordovaExample';
+
+ // Check if project already exists
+ if(fs.existsSync(project_path)) {
+ console.error('Project already exists! Delete and recreate');
+ process.exit(2);
+ }
+
+ // Check that requirements are met and proper targets are installed
+ if(!check_reqs.run()) {
+ console.error('Please make sure you meeet the software requirements in order to build an firefoxos cordova project');
+ process.exit(2);
+ }
+
+ console.log('Creating Firefox OS project');
+ console.log('Project Path '+ path.relative(process.cwd(),project_path));
+ console.log('Package Name '+ package_name);
+ console.log('Project Name '+ project_name);
+
+ //copy template folder
+ shjs.cp('-r', path.join(ROOT, 'bin', 'templates', 'project', 'www'), project_path);
+
+ //copy cordova js file
+ shjs.cp('-r', path.join(ROOT, 'javascript', 'cordova.js'), path.join(project_path,'www'));
+
+ //copy manifest file
+ shjs.cp('-r', path.join(ROOT, 'framework', 'manifest.webapp'), path.join(project_path,'www'));
+
+ //update app manifest file
+ updateManifest(ROOT, project_path, project_name);
+
+
+}
+
+function help(){
+ console.log('you need help son');
+}
+
+function updateManifest(ROOT, project_path, project_name){
+ var filename = path.join(ROOT, project_path, 'www', 'manifest.webapp');
+ var file_content = fs.readFileSync(filename);
+ var content = JSON.parse(file_content);
+ content.name = project_name;
+ console.log(project_name);
+ console.log(content);
+ fs.writeFileSync(filename, JSON.stringify(content));
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/73597797/bin/templates/project/www/manifest.webapp
----------------------------------------------------------------------
diff --git a/bin/templates/project/www/manifest.webapp b/bin/templates/project/www/manifest.webapp
deleted file mode 100644
index ddece37..0000000
--- a/bin/templates/project/www/manifest.webapp
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "name": "My App",
- "description": "My elevator pitch goes here",
- "launch_path": "/index.html",
- "icons": {
- "128": "/img/logo.png"
- },
- "developer": {
- "name": "Your name or organization",
- "url": "http://your-homepage-here.org"
- },
- "default_locale": "en",
- "type": "privileged"
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/73597797/framework/manifest.webapp
----------------------------------------------------------------------
diff --git a/framework/manifest.webapp b/framework/manifest.webapp
new file mode 100644
index 0000000..ddece37
--- /dev/null
+++ b/framework/manifest.webapp
@@ -0,0 +1,14 @@
+{
+ "name": "My App",
+ "description": "My elevator pitch goes here",
+ "launch_path": "/index.html",
+ "icons": {
+ "128": "/img/logo.png"
+ },
+ "developer": {
+ "name": "Your name or organization",
+ "url": "http://your-homepage-here.org"
+ },
+ "default_locale": "en",
+ "type": "privileged"
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/73597797/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..42eb2b8
--- /dev/null
+++ b/package.json
@@ -0,0 +1,28 @@
+{
+ "name": "cordova-firefoxos",
+ "version": "0.0.0",
+ "description": "cordova firefoxos",
+ "main": "create",
+ "scripts": {
+ "test": "./create"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://git-wip-us.apache.org/repos/asf/cordova-firefoxos.git"
+ },
+ "keywords": [
+ "cordova",
+ "cli",
+ "tooling",
+ "firefoxos"
+ ],
+ "dependencies": {
+ "shelljs": "0.1.4"
+ },
+ "author": "Steve Gill",
+ "contributors": [
+ {"name": "James Long","email": "jlong@mozilla.com"},
+ {"name": "Herm Wong", "email": "hermanw@adobe.com"},
+ ],
+ "license": "Apache V2"
+}