Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 77FC59C82 for ; Mon, 15 Dec 2014 13:32:52 +0000 (UTC) Received: (qmail 40621 invoked by uid 500); 15 Dec 2014 13:32:51 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 40489 invoked by uid 500); 15 Dec 2014 13:32:51 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 39979 invoked by uid 99); 15 Dec 2014 13:32:51 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Dec 2014 13:32:51 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 376089C6F9C; Mon, 15 Dec 2014 13:32:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zaspire@apache.org To: commits@cordova.apache.org Date: Mon, 15 Dec 2014 13:33:00 -0000 Message-Id: In-Reply-To: <91c426b12d574238a1cdabda159c34c7@git.apache.org> References: <91c426b12d574238a1cdabda159c34c7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/37] cordova-ubuntu git commit: Separated ubuntu.js in multiple tasks files for better maintainability. Use template folder for storing project assets and tasks. Deleted unecessary package.json. Various improvements. Separated ubuntu.js in multiple tasks files for better maintainability. Use template folder for storing project assets and tasks. Deleted unecessary package.json. Various improvements. Project: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/commit/4894ac2f Tree: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/tree/4894ac2f Diff: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/diff/4894ac2f Branch: refs/heads/master Commit: 4894ac2f9d7b83ff94d895badfef4f5d93b9b02a Parents: eb7c05c Author: Jean-Francois Moy Authored: Wed Oct 29 11:56:03 2014 +0000 Committer: Jean-Francois Moy Committed: Wed Oct 29 11:56:03 2014 +0000 ---------------------------------------------------------------------- bin/build/build | 32 - bin/build/clean | 28 - bin/build/lib/msg.js | 25 - bin/build/lib/templates/changelog | 7 - bin/build/lib/templates/compat | 1 - bin/build/lib/templates/control | 17 - bin/build/lib/templates/cordova.desktop | 7 - bin/build/lib/templates/install | 3 - bin/build/lib/templates/rules | 27 - bin/build/lib/ubuntu.js | 610 -------------------- bin/build/run | 32 - bin/build/version | 25 - bin/check_reqs | 14 +- bin/create | 57 +- bin/lib/check_reqs.js | 92 +++ bin/lib/create.js | 63 ++ bin/lib/update.js | 69 +++ bin/package.json | 37 -- bin/templates/project/cordova/build | 33 ++ bin/templates/project/cordova/clean | 27 + bin/templates/project/cordova/defaults.xml | 33 ++ bin/templates/project/cordova/lib/build.js | 352 +++++++++++ bin/templates/project/cordova/lib/constants.js | 33 ++ bin/templates/project/cordova/lib/device.js | 72 +++ bin/templates/project/cordova/lib/msg.js | 25 + bin/templates/project/cordova/lib/run.js | 137 +++++ bin/templates/project/cordova/lib/utils.js | 72 +++ bin/templates/project/cordova/run | 33 ++ bin/templates/project/cordova/version | 25 + bin/templates/project/misc/changelog | 7 + bin/templates/project/misc/compat | 1 + bin/templates/project/misc/control | 17 + bin/templates/project/misc/cordova.desktop | 7 + bin/templates/project/misc/install | 3 + bin/templates/project/misc/rules | 27 + bin/update | 41 +- package.json | 30 +- 37 files changed, 1175 insertions(+), 946 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/build ---------------------------------------------------------------------- diff --git a/bin/build/build b/bin/build/build deleted file mode 100755 index e40d98e..0000000 --- a/bin/build/build +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env node - -/* - * - * Copyright 2013 Canonical Ltd. - * - * Licensed 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 path = require('path'); -var platform = require('./lib/ubuntu'); - -var root = path.resolve(); -var www = path.join(root, 'www'); - -var argv = require('optimist').string(['framework']).argv; - -platform.check_reqs(root).then(function () { - return platform.build(root, platform.ALL, false, undefined, argv.framework, false); -}).done(); http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/clean ---------------------------------------------------------------------- diff --git a/bin/build/clean b/bin/build/clean deleted file mode 100755 index 4f1f27a..0000000 --- a/bin/build/clean +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env node - -/* - * - * Copyright 2013 Canonical Ltd. - * - * Licensed 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 path = require('path'); -var args = process.argv; -var ROOT = path.join(__dirname, '..'); -var shell = require('shelljs'); -var fs = require('fs'); -var et = require('elementtree'); - -throw new Error('unimplemented'); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/lib/msg.js ---------------------------------------------------------------------- diff --git a/bin/build/lib/msg.js b/bin/build/lib/msg.js deleted file mode 100644 index 6125aa5..0000000 --- a/bin/build/lib/msg.js +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env node - -/* - * - * Copyright 2013 Canonical Ltd. - * - * Licensed 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. - * -*/ - -module.exports = { - UBUNTU_TOUCH_DEVICE_NOT_AVALIABLE: 'UbuntuTouch device is not attached', - EMULATOR_IS_NOT_RUNNING: 'UbuntuTouch emulator is not running' -}; http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/lib/templates/changelog ---------------------------------------------------------------------- diff --git a/bin/build/lib/templates/changelog b/bin/build/lib/templates/changelog deleted file mode 100644 index ec94655..0000000 --- a/bin/build/lib/templates/changelog +++ /dev/null @@ -1,7 +0,0 @@ -{PACKAGE_NAME} ({PACKAGE_VERSION}) trusty; urgency=medium - - [ {MAINTAINER_NAME} ] - * upstream release - - -- {MAINTAINER_NAME} <{MAINTAINER_EMAIL}> Thu, 30 Aug 2014 06:06:06 +0000 - http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/lib/templates/compat ---------------------------------------------------------------------- diff --git a/bin/build/lib/templates/compat b/bin/build/lib/templates/compat deleted file mode 100644 index ec63514..0000000 --- a/bin/build/lib/templates/compat +++ /dev/null @@ -1 +0,0 @@ -9 http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/lib/templates/control ---------------------------------------------------------------------- diff --git a/bin/build/lib/templates/control b/bin/build/lib/templates/control deleted file mode 100644 index 51fb082..0000000 --- a/bin/build/lib/templates/control +++ /dev/null @@ -1,17 +0,0 @@ -Source: {PACKAGE_NAME} -Section: devel -Priority: optional -Maintainer: {MAINTAINER_NAME} <{MAINTAINER_EMAIL}> -Build-Depends: ubuntu-sdk, - qtfeedback5-dev, - qtmultimedia5-dev, - qtpim5-dev, - libqt5sensors5-dev, - qtsystems5-dev, - qtlocation5-dev, - libicu-dev - -Package: {PACKAGE_NAME} -Architecture: any -Description: {PACKAGE_DESCRIPTION} -Depends: ubuntu-sdk-libs http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/lib/templates/cordova.desktop ---------------------------------------------------------------------- diff --git a/bin/build/lib/templates/cordova.desktop b/bin/build/lib/templates/cordova.desktop deleted file mode 100644 index dee2f44..0000000 --- a/bin/build/lib/templates/cordova.desktop +++ /dev/null @@ -1,7 +0,0 @@ -[Desktop Entry] -Name={PACKAGE_TITLE} -Exec=/opt/{PACKAGE_NAME}/cordova-ubuntu -Terminal=false -Type=Application -X-Ubuntu-Touch=true -Icon={PACKAGE_ICON} http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/lib/templates/install ---------------------------------------------------------------------- diff --git a/bin/build/lib/templates/install b/bin/build/lib/templates/install deleted file mode 100644 index c3e51ca..0000000 --- a/bin/build/lib/templates/install +++ /dev/null @@ -1,3 +0,0 @@ -/opt/{PACKAGE_NAME} -/usr/share/applications/* - http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/lib/templates/rules ---------------------------------------------------------------------- diff --git a/bin/build/lib/templates/rules b/bin/build/lib/templates/rules deleted file mode 100755 index 27bc587..0000000 --- a/bin/build/lib/templates/rules +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/make -f - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - -export CFLAGS := $(shell dpkg-buildflags --get CFLAGS) $(shell dpkg-buildflags --get CPPFLAGS) -export CXXFLAGS := $(shell dpkg-buildflags --get CXXFLAGS) $(shell dpkg-buildflags --get CPPFLAGS) -export LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS) -Wl,--as-needed -export QT_SELECT := qt5 - -DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) - -# ----------------------------------- - -%: - dh $@ --fail-missing - -override_dh_auto_configure: - dh_auto_configure -- -DCMAKE_INSTALL_PREFIX=/opt/{PACKAGE_NAME} - -override_dh_auto_install: - dh_auto_install --destdir=debian/tmp - cp -R $(CURDIR)/www/* $(CURDIR)/debian/tmp/opt/{PACKAGE_NAME}/www - cp -R $(CURDIR)/debian/config.xml $(CURDIR)/debian/tmp/opt/{PACKAGE_NAME}/ - cp -R $(CURDIR)/qml/* $(CURDIR)/debian/tmp/opt/{PACKAGE_NAME}/qml - mkdir -p $(CURDIR)/debian/tmp/usr/share/applications/ - cp -R $(CURDIR)/debian/cordova.desktop $(CURDIR)/debian/tmp/usr/share/applications/{PACKAGE_NAME}.desktop http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/lib/ubuntu.js ---------------------------------------------------------------------- diff --git a/bin/build/lib/ubuntu.js b/bin/build/lib/ubuntu.js deleted file mode 100644 index fad368c..0000000 --- a/bin/build/lib/ubuntu.js +++ /dev/null @@ -1,610 +0,0 @@ -#!/usr/bin/env node - -/* - * - * Copyright 2013 Canonical Ltd. - * - * Licensed 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 shell = require('shelljs'); -var path = require('path'); -var fs = require('fs'); -var msg = require('./msg'); -var assert = require('assert'); -var colors = require('colors'); -var Q = require("q"); -var os = require("os"); - -var DEFAULT_FRAMEWORK = "ubuntu-sdk-14.04"; - -function exec(cmd, silent) { - console.log(cmd.green); - - var res = shell.exec(cmd, { silent: silent }); - if (res.code !== 0) { - console.error(cmd.green + " " + "FAILED".underline.red); - process.exit(1); - } - - return res; -} - -function execAsync(cmd) { - var deferred = Q.defer(); - - console.log(cmd.green); - - shell.exec(cmd, { async: true }, function (code, output) { - var res = { code: code, output: output }; - if (res.code !== 0) { - console.error(cmd.green + " " + "FAILED".underline.red); - process.exit(1); - } - deferred.resolve(res); - }); - - return deferred.promise; -} - - -function cp(source, dest) { - console.log(('cp -Rf ' + source + ' ' + dest).green); - - if (shell.cp('-r', source, dest) === null) { - console.error("FAILED".underline.red); - process.exit(1); - } -} - -function pushd(dir) { - console.log(('pushd ' + dir).green); - shell.pushd(dir); -} - -function popd(dir) { - console.log(('popd').green); - shell.popd(); -} - -function cpuCount() { - return os.cpus().length; -} - -function additionalDependencies(ubuntuDir) { - var files = []; - try { - files = fs.readdirSync(path.join(ubuntuDir, 'configs')).filter(function(s) { - return s[0] != '.'; - }); - } catch (e) {} - var deb = []; - for (var i = 0; i < files.length; i++) { - var config = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'configs', files[i]))); - if (config.deb) - deb = deb.concat(config.deb); - } - return deb; -} - -function checkChrootEnv(ubuntuDir, architecture, framework) { - var deps = "cmake libicu-dev:ARCH pkg-config qtbase5-dev:ARCH qtchooser qtdeclarative5-dev:ARCH qtfeedback5-dev:ARCH qtlocation5-dev:ARCH qtmultimedia5-dev:ARCH qtpim5-dev:ARCH libqt5sensors5-dev:ARCH qtsystems5-dev:ARCH "; - deps += additionalDependencies(ubuntuDir).join(' '); - deps = deps.replace(/ARCH/g, architecture); - - var cmd = "click chroot -a" + architecture + " -f " + framework + " run dpkg-query -Wf'${db:Status-abbrev}' " + deps; - console.log(cmd.green); - res = shell.exec(cmd); - - if (res.code !== 0 || res.output.indexOf('un') !== -1) { - console.error(("Error: missing " + architecture + " chroot").red); - console.error(("run:\nsudo click chroot -a" + architecture + " -f " + framework + " create").red); - console.error(("sudo click chroot -a" + architecture + " -f " + framework + " install " + deps).red); - process.exit(2); - } -} - -function checkEnv(ubuntuDir) { - var deps = additionalDependencies(ubuntuDir).join(' '); - deps = deps.replace(/:ARCH/g, ''); - - if (!deps.length) - return; - - var cmd = "dpkg-query -Wf'${db:Status-abbrev}' " + deps; - console.log(cmd.green); - res = shell.exec(cmd); - - if (res.code !== 0 || res.output.indexOf('un') !== -1) { - console.error(("Error: missing packages" + deps).red); - process.exit(2); - } -} - -module.exports.createProject = function(projectPath, ROOT) { - if (fs.existsSync(projectPath)) { - console.error('Project already exists! Delete and recreate'); - process.exit(2); - } - - shell.mkdir(projectPath); - shell.cp('-r', path.join(ROOT, '*'), path.join(projectPath, 'build')); - shell.mkdir(path.join(projectPath, 'native')); - shell.cp('-r', path.join(ROOT, 'bin/build/*'), path.join(projectPath, 'cordova')); - shell.cp('-r', path.join(ROOT, 'bin/check_reqs'), path.join(projectPath, 'cordova')); - - shell.cp('-r', path.join(ROOT, 'bin/node_modules'), path.join(projectPath, 'cordova')); - - shell.cp('-r', path.join(ROOT, 'xml/config.xml'), projectPath); - - shell.mkdir(path.join(projectPath, 'www')); - shell.cp(path.join(ROOT, 'www/cordova.js'), path.join(projectPath, 'www')); - - shell.cd(projectPath); -} - -module.exports.updateProject = function(projectPath, ROOT) { - if (!fs.existsSync(projectPath)) { - console.error('Project does not exist!'); - process.exit(2); - } - - shell.rm('-r', path.join(projectPath, 'www')); - shell.mkdir(path.join(projectPath, 'www')); - shell.cp(path.join(ROOT, 'www/cordova.js'), path.join(projectPath, 'www')); - - shell.rm('-r', path.join(projectPath, 'cordova')); - shell.cp('-r', path.join(ROOT, 'bin/build/*'), path.join(projectPath, 'cordova')); - shell.cp('-r', path.join(ROOT, 'bin/check_reqs'), path.join(projectPath, 'cordova')); - shell.cp('-r', path.join(ROOT, 'bin/node_modules'), path.join(projectPath, 'cordova')); - - var tmp = path.join(projectPath, 'tmp'); - shell.mkdir(tmp); - - var pluginsDir = path.join(projectPath, 'build', 'src', 'plugins'); - var coreplugins = path.join(projectPath, 'build', 'src', 'coreplugins.cpp'); - shell.mv(coreplugins, tmp); - shell.mv(pluginsDir, tmp); - shell.rm('-r', path.join(projectPath, 'build')); - - shell.cp('-r', path.join(ROOT, '*'), path.join(projectPath, 'build')); - - shell.rm('-r', coreplugins); - shell.rm('-r', pluginsDir); - shell.mv(path.join(tmp, 'plugins'), path.join(projectPath, 'build', 'src')); - shell.mv(path.join(tmp, 'coreplugins.cpp'), path.join(projectPath, 'build', 'src')); - - shell.rm('-r', tmp); - console.log('project updated'.green); -} - -function checkClickPackage(prefixDir) { - pushd(prefixDir); - - // 13.10 missing click-reviewers-tools package - // FIXME: remove this check after EOL - if (fs.existsSync('/usr/bin/click-run-checks')) { - var cmd = '/usr/bin/click-run-checks *.click'; - console.log(cmd.green); - var output = shell.exec(cmd, { silent: true }).output; - var json = '[', b = 0; - for (var i = 0; i < output.length; i++) { - if (output[i] == '{') { - if (json.length > 1 && !b) - json += ', '; - b++; - } else if (output[i] == '}') { - b--; - if (b == 0) - json += '} '; - } - if (b > 0) { - json += output[i]; - } - } - json += ']'; - var out = JSON.parse(json); - for (var i = 0; i < out.length; i++) { - if (out[i].warn) { - for (var m in out[i].warn) { - if (out[i].warn[m].text) { - console.warn(out[i].warn[m].text.yellow); - if (out[i].warn[m].link) - console.warn(out[i].warn[m].link); - } - } - } - } - for (var i = 0; i < out.length; i++) { - if (out[i].error) { - for (var m in out[i].error) { - if (out[i].error[m].text) { - console.warn(out[i].error[m].text.yellow); - if (out[i].error[m].link) - console.warn(out[i].error[m].link); - } - } - } - } - } - - popd(); -} - -function additionalBuildDependencies(ubuntuDir) { - var files = []; - try { - files = fs.readdirSync(path.join(ubuntuDir, 'configs')).filter(function(s) { - return s[0] != '.'; - }); - } catch (e) {} - - var pkgConfig = []; - for (var i = 0; i < files.length; i++) { - var config = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'configs', files[i]))); - if (config.pkgConfig) - pkgConfig = pkgConfig.concat(config.pkgConfig); - } - - return pkgConfig; -} - -function buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework, debug) { - assert.ok(architecture && architecture.match(/^[a-z0-9_]+$/)); - - var archDir = path.join(ubuntuDir, framework, architecture); - var prefixDir = path.join(archDir, 'prefix'); - - if (!fs.existsSync(archDir)) - shell.mkdir('-p', archDir); - - if (nobuild && fs.existsSync(path.join(prefixDir, 'cordova-ubuntu'))) { - return Q(); - } - - checkChrootEnv(ubuntuDir, architecture, framework); - - shell.rm('-rf', path.join(archDir, 'build')); - - shell.rm('-rf', prefixDir); - shell.mkdir(path.join(archDir, 'build')); - shell.mkdir(prefixDir); - - pushd(path.join(archDir, 'build')); - - var buildType = '"Debug"'; - if (!debug) - buildType = '"Release"'; - - var cmakeCmd = 'click chroot -a' + architecture + ' -f ' + framework + ' run cmake ' + campoDir - + ' -DCMAKE_INSTALL_PREFIX="' + prefixDir + '"' + ' -DCMAKE_BUILD_TYPE=' + buildType; - - if (framework == 'ubuntu-sdk-13.10') - cmakeCmd += ' -DCMAKE_TOOLCHAIN_FILE=/etc/dpkg-cross/cmake/CMakeCross.txt'; - - var deps = additionalBuildDependencies(ubuntuDir).join(' ').replace(/ARCH/g, architecture); - if (deps.length) - cmakeCmd += ' -DADDITIONAL_DEPENDECIES="' + deps + '"'; - - return execAsync(cmakeCmd).then(function () { - if (architecture != "i386") - exec('find . -name AutomocInfo.cmake | xargs sed -i \'s;AM_QT_MOC_EXECUTABLE .*;AM_QT_MOC_EXECUTABLE "/usr/lib/\'$(dpkg-architecture -qDEB_BUILD_MULTIARCH)\'/qt5/bin/moc");\''); - return execAsync('click chroot -a' + architecture + ' -f ' + framework + ' run make -j ' + cpuCount()); - }).then(function () { - return execAsync('click chroot -a' + architecture + ' -f ' + framework + ' run make install'); - }).then(function () { - cp(path.join(ubuntuDir, 'www', '*'), path.join(prefixDir, 'www')); - cp(path.join(ubuntuDir, 'qml', '*'), path.join(prefixDir, 'qml')); - cp(path.join(ubuntuDir, 'cordova.desktop'), prefixDir); - cp(path.join(ubuntuDir, 'config.xml'), prefixDir); - - var content = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'manifest.json'), {encoding: "utf8"})); - content.architecture = architecture; - content.framework = framework; - fs.writeFileSync(path.join(prefixDir, 'manifest.json'), JSON.stringify(content)); - - content = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'apparmor.json'), {encoding: "utf8"})); - if (framework == 'ubuntu-sdk-13.10') - content.policy_version = 1; - else - content.policy_version = 1.1; - fs.writeFileSync(path.join(prefixDir, 'apparmor.json'), JSON.stringify(content)); - - pushd(prefixDir); - - return execAsync('click build .'); - }).then(function () { - checkClickPackage(prefixDir); - popd(); - - popd(); - }); -} - -function fillTemplate(source, dest, obj) { - var content = fs.readFileSync(source, {encoding: "utf8"}); - for (var prop in obj) { - content = content.replace(new RegExp('{' + prop + '}', 'g'), obj[prop]) - } - - fs.writeFileSync(dest, content); -} - -function buildNative(campoDir, ubuntuDir, nobuild, debug) { - var nativeDir = path.join(ubuntuDir, 'native'); - var prefixDir = path.join(nativeDir, 'prefix'); - - if (nobuild && fs.existsSync(path.join(prefixDir, 'cordova-ubuntu'))) { - return Q(); - } - - checkEnv(ubuntuDir); - - shell.rm('-rf', prefixDir); - - shell.mkdir('-p', path.join(nativeDir, 'build')); - shell.mkdir(prefixDir); - - pushd(path.join(nativeDir, 'build')); - - var buildType = '"Debug"'; - if (!debug) - buildType = '"Release"'; - - var cmakeCmd = 'cmake ' + campoDir + ' -DCMAKE_INSTALL_PREFIX="' + prefixDir + '"' - + ' -DCMAKE_BUILD_TYPE=' + buildType; - - var deps = additionalBuildDependencies(ubuntuDir).join(' ').replace(/ARCH/g, ''); - if (deps.length) - cmakeCmd += ' -DADDITIONAL_DEPENDECIES="' + deps + '"'; - - var debDir; - return execAsync(cmakeCmd).then(function () { - return execAsync('make -j ' + cpuCount() + '; make install'); - }).then(function () { - cp(path.join(ubuntuDir, 'config.xml'), prefixDir); - cp(path.join(ubuntuDir, 'www', '*'), path.join(prefixDir, 'www')); - cp(path.join(ubuntuDir, 'qml', '*'), path.join(prefixDir, 'qml')); - - popd(); - - var manifest = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'manifest.json'), {encoding: "utf8"})); - - assert(manifest.name.length); - assert(manifest.name.indexOf(' ') == -1); - - debDir = path.join(nativeDir, manifest.name); - - shell.rm('-rf', debDir); - - shell.mkdir('-p', path.join(debDir, 'debian')); - cp(path.join(campoDir, '*'), debDir); - - cp(path.join(ubuntuDir, 'config.xml'), path.join(debDir, 'debian')); - cp(path.join(ubuntuDir, 'www', '*'), path.join(debDir, 'www')); - cp(path.join(ubuntuDir, 'qml', '*'), path.join(debDir, 'qml')); - - var destDir = path.join('/opt', manifest.name); - - var icon = fs.readFileSync(path.join(ubuntuDir, 'cordova.desktop'), {encoding: "utf8"}).match(/^Icon=(.+)$/m); - icon = icon ? '/opt/' + manifest.name + '/' + icon[1] : 'qmlscene'; - - var maintainerEmail = manifest.maintainer.match('<.+>$'); - maintainerEmail = maintainerEmail?maintainerEmail[0]:''; - var maintainerName = manifest.maintainer.replace(maintainerEmail, '').trim(); - maintainerEmail = maintainerEmail.replace('<', '').replace('>', ''); - - var props = { PACKAGE_NAME: manifest.name, - PACKAGE_TITLE: manifest.title, - PACKAGE_VERSION: manifest.version, - MAINTAINER_NAME: maintainerName, - MAINTAINER_EMAIL: maintainerEmail, - PACKAGE_DESCRIPTION: manifest.description, - PACKAGE_ICON: icon }; - var templateDir = path.join(campoDir, 'bin', 'build', 'lib', 'templates'); - var templates = [{source: path.join(templateDir, 'changelog'), dest: path.join(debDir, 'debian', 'changelog')}, - {source: path.join(templateDir, 'compat'), dest: path.join(debDir, 'debian', 'compat')}, - {source: path.join(templateDir, 'control'), dest: path.join(debDir, 'debian', 'control')}, - {source: path.join(templateDir, 'rules'), dest: path.join(debDir, 'debian', 'rules')}, - {source: path.join(templateDir, 'cordova.desktop'), dest: path.join(debDir, 'debian', 'cordova.desktop')}, - {source: path.join(templateDir, 'install'), dest: path.join(debDir, 'debian', manifest.name + '.install')}]; - for (var i = 0; i < templates.length; i++) { - fillTemplate(templates[i].source, templates[i].dest, props); - } - - console.error('In order to build debian package, execute'.yellow); - console.error(('cd ' + debDir + '; ' + 'debuild').yellow); - }); -} - -module.exports.ALL = 2; -module.exports.PHONE = 0; -module.exports.DESKTOP = 1; - -module.exports.build = function(rootDir, target, nobuild, architecture, framework, debug) { - var ubuntuDir = path.join(rootDir, 'platforms', 'ubuntu'); - var campoDir = path.join(ubuntuDir, 'build'); - - if (!architecture) - architecture = 'armhf'; - if (!framework) - framework = DEFAULT_FRAMEWORK; - - assert.ok(fs.existsSync(ubuntuDir)); - assert.ok(fs.existsSync(campoDir)); - - if (target === module.exports.PHONE) - return buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework, debug); - if (target === module.exports.DESKTOP) - return buildNative(campoDir, ubuntuDir, nobuild, debug); - if (target === module.exports.ALL) { - return buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework, debug).then(function () { - return buildNative(campoDir, ubuntuDir, nobuild); - }); - } -} - -function runNative(rootDir, debug) { - var ubuntuDir = path.join(rootDir, 'platforms', 'ubuntu'); - var nativeDir = path.join(ubuntuDir, 'native'); - - pushd(path.join(nativeDir, 'prefix')); - - var cmd = 'QTWEBKIT_INSPECTOR_SERVER=9222 ./cordova-ubuntu www/'; - if (debug) { - cmd = "DEBUG=1 " + cmd; - console.error('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222'.yellow); - } - - return execAsync(cmd).then(function () { - popd(); - }); -} - -function deviceList() { - var res = exec('adb devices'); - - var response = res.output.split('\n'); - var deviceList = []; - - for (var i = 1; i < response.length; i++) { - if (response[i].match(/\w+\tdevice/)) { - deviceList.push(response[i].replace(/\tdevice/, '').replace('\r', '')); - } - } - - return deviceList; -} - -function adbExec(target, command) { - assert.ok(target && command); - return exec('adb -s ' + target + ' ' + command); -} - -function adbExecAsync(target, command) { - assert.ok(target && command); - return execAsync('adb -s ' + target + ' ' + command); -} - -function isDeviceAttached(target) { - var res = adbExec(target, 'get-state'); - - if (res.output.indexOf('device') == -1) - return false; - - res = adbExec(target, 'shell uname -a'); - if (res.output.indexOf('ubuntu-phablet') == -1) - return false; - - return true; -} - -function getDeviceArch(target) { - var out = adbExec(target, 'shell "dpkg --print-architecture 2>/dev/null"').output.split('\r\n'); - - assert.ok(out.length == 2 && out[0].indexOf(' ') == -1); - - return out[0]; -} - -function runOnDevice(rootDir, debug, target, architecture, framework) { - var ubuntuDir = path.join(rootDir, 'platforms', 'ubuntu'); - - if (!isDeviceAttached(target)) { - console.error(msg.UBUNTU_TOUCH_DEVICE_NOT_AVALIABLE.red) - process.exit(1); - } - - var archDir = path.join(ubuntuDir, framework, architecture); - var prefixDir = path.join(archDir, 'prefix'); - - pushd(prefixDir); - - var manifest = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'manifest.json'), {encoding: "utf8"})); - var appId = manifest.name; - - var names = shell.ls().filter(function (name) { - return name.indexOf(appId) == 0 && name.indexOf('.click'); - }); - - assert.ok(names.length == 1); - - adbExec(target, 'shell "ps -A -eo pid,cmd | grep cordova-ubuntu | awk \'{ print \\$1 }\' | xargs kill -9"') - - if (debug) - adbExec(target, 'forward --remove-all'); - - adbExec(target, 'push ' + names[0] + ' /home/phablet'); - adbExec(target, 'shell "cd /home/phablet/; pkcon install-local ' + names[0] + ' -p --allow-untrusted -y"'); - - if (debug) { - console.error('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222'); - - adbExec(target, 'forward tcp:9222 tcp:9222'); - } - - console.log('have fun!'.rainbow); - - return adbExecAsync(target, 'shell bash -c "ubuntu-app-launch \\`ubuntu-app-triplet ' + appId + '\\`"').then(function () { - popd(); - }); -} - -module.exports.run = function(rootDir, desktop, debug, target, nobuild, emulator, framework) { - if (desktop && !emulator) { - return module.exports.build(rootDir, module.exports.DESKTOP, nobuild, null, null, debug).then(function () { - return runNative(rootDir, debug); - }); - } - - if (!framework) - framework = DEFAULT_FRAMEWORK; - - if (!target) { - var devices = deviceList(); - - if (!devices.length) { - console.error(msg.UBUNTU_TOUCH_DEVICE_NOT_AVALIABLE.red) - process.exit(1); - } - - if (emulator) { - devices = devices.filter(function (name) { - return name.match(/^emulator-/); - }); - if (!devices.length) { - console.error(msg.EMULATOR_IS_NOT_RUNNING.red) - process.exit(1); - } - } - - target = devices[0]; - - if (devices.length > 1) { - console.warn('you can specify target with --target '.yellow); - console.warn(('running on ' + target).yellow); - } - } - var arch = getDeviceArch(target); - - return module.exports.build(rootDir, module.exports.PHONE, nobuild, arch, framework, debug).then(function () { - return runOnDevice(rootDir, debug, target, arch, framework); - }); -} - -module.exports.check_reqs = function(rootDir) { - var checkReqs = path.join(rootDir, 'platforms', 'ubuntu', 'cordova', 'check_reqs'); - return execAsync(checkReqs); -} http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/run ---------------------------------------------------------------------- diff --git a/bin/build/run b/bin/build/run deleted file mode 100755 index 8a1d9ca..0000000 --- a/bin/build/run +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env node - -/* - * - * Copyright 2013 Canonical Ltd. - * - * Licensed 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 path = require('path'); -var platform = require('./lib/ubuntu'); - -var root = path.resolve(); -var www = path.join(root, 'www'); - -var argv = require('optimist').boolean(['device', 'emulator', 'debug', 'nobuild']).string(['target', 'framework']).argv; - -platform.check_reqs(root).then(function () { - return platform.run(root, !argv.device, argv.debug, argv.target, argv.nobuild, argv.emulator, argv.framework); -}).done(); - http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/build/version ---------------------------------------------------------------------- diff --git a/bin/build/version b/bin/build/version deleted file mode 100755 index 26dabe2..0000000 --- a/bin/build/version +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env node - -/* - * - * Copyright 2013 Canonical Ltd. - * - * Licensed 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. - * -*/ - -// Coho updates this line: -var VERSION = "3.7.0-dev"; - -console.log(VERSION); http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/check_reqs ---------------------------------------------------------------------- diff --git a/bin/check_reqs b/bin/check_reqs index 56b5a6e..676f105 100755 --- a/bin/check_reqs +++ b/bin/check_reqs @@ -2,7 +2,7 @@ /* * - * Copyright 2013 Canonical Ltd. + * Copyright 2014 Canonical Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,4 @@ * */ -var exec = require('child_process').exec; - -var deps = "cmake libicu-dev pkg-config devscripts qtbase5-dev qtchooser qtdeclarative5-dev qtfeedback5-dev qtlocation5-dev qtmultimedia5-dev qtpim5-dev libqt5sensors5-dev qtsystems5-dev"; - -exec("dpkg-query -Wf'${db:Status-abbrev}\\n' click " + deps, function(error, stdout, stderr) { - if (error || stdout.indexOf('un') !== -1) { - console.error("Error: missing dependency " + deps); - process.exit(2); - } -}); - +require('./lib/check_reqs').check_reqs(); http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/create ---------------------------------------------------------------------- diff --git a/bin/create b/bin/create index cb75109..29c41d4 100755 --- a/bin/create +++ b/bin/create @@ -2,7 +2,7 @@ /* * - * Copyright 2013 Canonical Ltd. + * Copyright 2014 Canonical Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,56 +20,19 @@ */ var path = require('path'); var args = process.argv; -var ROOT = path.join(__dirname, '..'); -var fs = require('fs'); -function help() { +var check_reqs = require('./lib/check_reqs').check_reqs; + + +if (args.length < 3 || (args[2] == '--help' || args[2] == '/?' || args[2] == '-h' || + args[2] == 'help' || args[2] == '-help' || args[2] == '/help')) { console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'bin', 'create')) + ' '); console.log(' : Path to your new Cordova Ubuntu project'); console.log(' : Package name'); console.log(' : Project name'); - process.exit(0); -} - -function create(projectPath) { - function create_project() { - require('./build/lib/ubuntu').createProject(projectPath, ROOT); - } - - try { - require.resolve("shelljs"); - require.resolve("elementtree"); - require.resolve("colors"); - require.resolve("optimist"); - require.resolve("q"); - create_project(); - } catch(e) { - console.log('Shelljs module was not found, running \'npm install\'.....'); - var exec = require('child_process').exec; - var cwd = process.cwd(); - - var block = true; - exec('npm install', {cwd: __dirname}, function (error, stdout, stderr) { - block = false; - if (error !== null) { - console.error('ERROR : running \'npm install\' is npm installed? ' + error); - console.error(stderr); - process.exit(error.code); - } - }); - function wait() { - if (block) - setTimeout(wait, 1500); - else - create_project(); - }; - setTimeout(wait, 1500); - } -} - -if(args.length < 3 || (args[2] == '--help' || args[2] == '/?' || args[2] == '-h' || - args[2] == 'help' || args[2] == '-help' || args[2] == '/help')) { - help(); + process.exit(1); } else { - create(args[2]); + check_reqs(function () { + require('./lib/create').createProject(args[2], args[3], args[4], args[5]); + }); } http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/lib/check_reqs.js ---------------------------------------------------------------------- diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js new file mode 100644 index 0000000..1853828 --- /dev/null +++ b/bin/lib/check_reqs.js @@ -0,0 +1,92 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2014 Canonical Ltd. + * + * Licensed 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 exec = require('child_process').exec; + +var DEPENDENCIES = [ + 'click', + 'cmake', + 'libicu-dev', + 'pkg-config', + 'devscripts', + 'qtbase5-dev', + 'qtchooser', + 'qtdeclarative5-dev', + 'qtfeedback5-dev', + 'qtlocation5-dev', + 'qtmultimedia5-dev', + 'qtpim5-dev', + 'libqt5sensors5-dev', + 'qtsystems5-dev' +]; + +exports.check_reqs = function (callback) { + if (!checkNodeDependencies()) { + installNodeDependencies(checkUbuntuDependencies.bind(null, callback)); + } else { + checkUbuntuDependencies(callback); + } +}; + +function checkUbuntuDependencies(callback) { + var deps = DEPENDENCIES.join(' '); + exec("dpkg-query -Wf'${db:Status-abbrev}\\n'" + deps, function (error, stdout, stderr) { + if (error !== null) { + console.error('Error: missing dependency ' + deps); + process.exit(1); + } + callback(); + }); +} + +function checkNodeDependencies() { + try { + require.resolve("shelljs"); + require.resolve("colors"); + require.resolve("optimist"); + require.resolve("q"); + } catch(e) { + // One or more dependencies are missing, need installation. + return false; + } + + return true; +} + +function installNodeDependencies(callback) { + var block = true; + exec('npm install', {cwd: __dirname}, function (error, stdout, stderr) { + block = false; + if (error !== null) { + console.error('ERROR : running \'npm install\' is npm installed? ' + error); + console.error(stderr); + process.exit(error.code); + } + }); + function wait() { + if (block) { + setTimeout(wait, 1500); + } else { + callback(); + } + }; + setTimeout(wait, 1500); +} http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/lib/create.js ---------------------------------------------------------------------- diff --git a/bin/lib/create.js b/bin/lib/create.js new file mode 100644 index 0000000..ad03cd8 --- /dev/null +++ b/bin/lib/create.js @@ -0,0 +1,63 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2014 Canonical Ltd. + * + * Licensed 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 shell = require('shelljs'), + // child_process = require('child_process'), + path = require('path'), + fs = require('fs'), + check_reqs = require('./check_reqs').check_reqs, + ROOT = path.join(__dirname, '..', '..'); + +exports.createProject = function(projectPath, packageName, projectName) { + if (fs.existsSync(projectPath)) { + console.error('Project already exists! Delete and recreate'); + process.exit(1); + } + + console.log('Creating a Cordova Project:\n', + 'Project Path: ' + projectPath + '\n', + 'Package Name: ' + packageName + '\n', + 'Project Name: ' + projectName + '\n' + ); + + shell.mkdir(projectPath); + + shell.cp('-r', path.join(ROOT, '*'), path.join(projectPath, 'build')); + + shell.mkdir(path.join(projectPath, 'native')); + + // Copy the necessary node_modules for building and running the project. + shell.cp('-r', path.join(ROOT, 'node_modules'), path.join(projectPath, 'cordova')); + + // Checking requirements task needs to be copied as well. + shell.cp('-r', path.join(ROOT, 'bin/check_reqs'), path.join(projectPath, 'cordova')); + shell.cp('-r', path.join(ROOT, 'bin', 'lib', 'check_reqs.js'), path.join(projectPath, 'cordova', 'lib')); + + // Copy the default template including the defaults.xml for the Ubuntu platform. + shell.cp('-r', path.join(ROOT, 'bin', 'templates', 'project', 'cordova'), projectPath); + + shell.mkdir(path.join(projectPath, 'www')); + shell.cp(path.join(ROOT, 'www', 'cordova.js'), path.join(projectPath, 'www')); + + shell.cp('-r', path.join(ROOT, 'xml/config.xml'), projectPath); +} + + http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/lib/update.js ---------------------------------------------------------------------- diff --git a/bin/lib/update.js b/bin/lib/update.js new file mode 100644 index 0000000..f7b288f --- /dev/null +++ b/bin/lib/update.js @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2014 Canonical Ltd. + * + * Licensed 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 shell = require('shelljs'), + // child_process = require('child_process'), + path = require('path'), + fs = require('fs'), + check_reqs = require('./check_reqs'), + ROOT = path.join(__dirname, '..', '..'); + +exports.updateProject = function(projectPath) { + if (!fs.existsSync(projectPath)) { + console.error('Project does not exist!'); + process.exit(1); + } + + shell.rm('-r', path.join(projectPath, 'www')); + shell.mkdir(path.join(projectPath, 'www')); + shell.cp(path.join(ROOT, 'www', 'cordova.js'), path.join(projectPath, 'www')); + + shell.rm('-r', path.join(projectPath, 'cordova')); + + // Copy the necessary node modules. + shell.cp('-r', path.join(ROOT, 'node_modules'), path.join(projectPath, 'cordova')); + + // Checking requirements needs to be copied as well. + shell.cp('-r', path.join(ROOT, 'bin/check_reqs'), path.join(projectPath, 'cordova')); + shell.cp('-r', path.join(ROOT, 'bin', 'lib', 'check_reqs.js'), path.join(projectPath, 'cordova', 'lib')); + + // Copy the default template including the defaults.xml for the Ubuntu platform. + shell.cp('-r', path.join(ROOT, 'bin', 'templates', 'project', 'cordova'), projectPath); + + var tmp = path.join(projectPath, 'tmp'); + shell.mkdir(tmp); + + var pluginsDir = path.join(projectPath, 'build', 'src', 'plugins'); + var coreplugins = path.join(projectPath, 'build', 'src', 'coreplugins.cpp'); + shell.mv(coreplugins, tmp); + shell.mv(pluginsDir, tmp); + shell.rm('-r', path.join(projectPath, 'build')); + + shell.cp('-r', path.join(ROOT, '*'), path.join(projectPath, 'build')); + + shell.rm('-r', coreplugins); + shell.rm('-r', pluginsDir); + shell.mv(path.join(tmp, 'plugins'), path.join(projectPath, 'build', 'src')); + shell.mv(path.join(tmp, 'coreplugins.cpp'), path.join(projectPath, 'build', 'src')); + + shell.rm('-r', tmp); + console.log('project updated'.green); +} http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/package.json ---------------------------------------------------------------------- diff --git a/bin/package.json b/bin/package.json deleted file mode 100644 index bb2dc7a..0000000 --- a/bin/package.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "cordova-ubuntu", - "description": "Cordova tooling for the Ubuntu platform.", - "version": "0.0.0", - "homepage": "https://launchpad.net/cordova-ubuntu/", - "repository": { - "type": "git", - "url": "https://git-wip-us.apache.org/repos/asf?p=cordova-ubuntu.git" - }, - "keywords": [ - "cli", - "cordova", - "ubuntu", - "tooling" - ], - "engineStrict": "true", - "engines": { - "node": ">=0.10.0" - }, - "dependencies": { - "q": "2.0.*", - "shelljs": "0.2.6", - "elementtree": "*", - "colors": "0.6.2", - "optimist": "0.6.0" - }, - "devDependencies": { - }, - "optionalDependencies": { - }, - "author": { - "name": "Maxim Ermilov", - "email": "maxim.ermilov@canonical.com" - }, - "contributors": [ - ] -} http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/cordova/build ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova/build b/bin/templates/project/cordova/build new file mode 100755 index 0000000..ed571ff --- /dev/null +++ b/bin/templates/project/cordova/build @@ -0,0 +1,33 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2013 Canonical Ltd. + * + * Licensed 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 path = require('path'); +var build = require('./lib/build').build; +var check_reqs = require('./lib/check_reqs').check_reqs; +var PLATFORMS = require('./lib/constants').PLATFORM_TYPES; + +var root = path.resolve(); +var www = path.join(root, 'www'); + +check_reqs(function () { + var argv = require('optimist').string(['framework']).argv; + return build(root, PLATFORMS.ALL, false, undefined, argv.framework, false); +}); http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/cordova/clean ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova/clean b/bin/templates/project/cordova/clean new file mode 100755 index 0000000..2057443 --- /dev/null +++ b/bin/templates/project/cordova/clean @@ -0,0 +1,27 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2013 Canonical Ltd. + * + * Licensed 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 path = require('path'); +var args = process.argv; +var ROOT = path.join(__dirname, '..'); +var shell = require('shelljs'); +var fs = require('fs'); + +throw new Error('unimplemented'); http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/cordova/defaults.xml ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova/defaults.xml b/bin/templates/project/cordova/defaults.xml new file mode 100644 index 0000000..41fc654 --- /dev/null +++ b/bin/templates/project/cordova/defaults.xml @@ -0,0 +1,33 @@ + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/cordova/lib/build.js ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova/lib/build.js b/bin/templates/project/cordova/lib/build.js new file mode 100644 index 0000000..ba4a7e9 --- /dev/null +++ b/bin/templates/project/cordova/lib/build.js @@ -0,0 +1,352 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2014 Canonical Ltd. + * + * Licensed 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 assert = require('assert'); +var colors = require('colors'); +var fs = require('fs'); +var os = require('os'); +var Q = require('q'); +var path = require('path'); +var shell = require('shelljs'); + +var Constants = require('./constants'); +var Utils = require('./utils'); + +var PLATFORMS = Constants.PLATFORM_TYPES; + +module.exports.build = function(rootDir, target, nobuild, architecture, framework, debug) { + var ubuntuDir = path.join(rootDir, 'platforms', 'ubuntu'); + var campoDir = path.join(ubuntuDir, 'build'); + + if (!architecture) + architecture = Constants.DEFAULT_ARCH; + if (!framework) + framework = Constants.DEFAULT_FRAMEWORK; + assert.ok(fs.existsSync(ubuntuDir)); + assert.ok(fs.existsSync(campoDir)); + + if (target === PLATFORMS.PHONE) + return buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework, debug); + if (target === PLATFORMS.DESKTOP) + return buildNative(campoDir, ubuntuDir, nobuild, debug); + if (target === PLATFORMS.ALL) { + return buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework, debug).then(function () { + return buildNative(campoDir, ubuntuDir, nobuild); + }); + } +}; + +function buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework, debug) { + assert.ok(architecture && architecture.match(/^[a-z0-9_]+$/)); + + var archDir = path.join(ubuntuDir, framework, architecture); + var prefixDir = path.join(archDir, 'prefix'); + + if (!fs.existsSync(archDir)) + shell.mkdir('-p', archDir); + + if (nobuild && fs.existsSync(path.join(prefixDir, 'cordova-ubuntu'))) { + return Q(); + } + + checkChrootEnv(ubuntuDir, architecture, framework); + + shell.rm('-rf', path.join(archDir, 'build')); + + shell.rm('-rf', prefixDir); + shell.mkdir(path.join(archDir, 'build')); + shell.mkdir(prefixDir); + + shell.pushd(path.join(archDir, 'build')); + + var buildType = '"Debug"'; + if (!debug) + buildType = '"Release"'; + + var cmakeCmd = 'click chroot -a ' + architecture + ' -f ' + framework + ' run cmake ' + campoDir + + ' -DCMAKE_INSTALL_PREFIX="' + prefixDir + '"' + ' -DCMAKE_BUILD_TYPE=' + buildType; + + if (framework == 'ubuntu-sdk-13.10') + cmakeCmd += ' -DCMAKE_TOOLCHAIN_FILE=/etc/dpkg-cross/cmake/CMakeCross.txt'; + + var deps = additionalBuildDependencies(ubuntuDir).join(' ').replace(/ARCH/g, architecture); + if (deps.length) + cmakeCmd += ' -DADDITIONAL_DEPENDECIES="' + deps + '"'; + + return Utils.execAsync(cmakeCmd).then(function () { + if (architecture != "i386") + Utils.execSync('find . -name AutomocInfo.cmake | xargs sed -i \'s;AM_QT_MOC_EXECUTABLE .*;AM_QT_MOC_EXECUTABLE "/usr/lib/\'$(dpkg-architecture -qDEB_BUILD_MULTIARCH)\'/qt5/bin/moc");\''); + return Utils.execAsync('click chroot -a ' + architecture + ' -f ' + framework + ' run make -j ' + cpuCount()); + }).then(function () { + return Utils.execAsync('click chroot -a ' + architecture + ' -f ' + framework + ' run make install'); + }).then(function () { + Utils.cp(path.join(ubuntuDir, 'www', '*'), path.join(prefixDir, 'www')); + Utils.cp(path.join(ubuntuDir, 'qml', '*'), path.join(prefixDir, 'qml')); + Utils.cp(path.join(ubuntuDir, 'cordova.desktop'), prefixDir); + Utils.cp(path.join(ubuntuDir, 'config.xml'), prefixDir); + + var content = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'manifest.json'), {encoding: "utf8"})); + content.architecture = architecture; + content.framework = framework; + fs.writeFileSync(path.join(prefixDir, 'manifest.json'), JSON.stringify(content)); + + content = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'apparmor.json'), {encoding: "utf8"})); + if (framework == 'ubuntu-sdk-13.10') + content.policy_version = 1; + else + content.policy_version = 1.1; + fs.writeFileSync(path.join(prefixDir, 'apparmor.json'), JSON.stringify(content)); + + shell.pushd(prefixDir); + + return Utils.execAsync('click build .'); + }).then(function () { + checkClickPackage(prefixDir); + Utils.popd(); + + Utils.popd(); + }); +} + +function buildNative(campoDir, ubuntuDir, nobuild, debug) { + var nativeDir = path.join(ubuntuDir, 'native'); + var prefixDir = path.join(nativeDir, 'prefix'); + + if (nobuild && fs.existsSync(path.join(prefixDir, 'cordova-ubuntu'))) { + return Q(); + } + + checkEnv(ubuntuDir); + + shell.rm('-rf', prefixDir); + + shell.mkdir('-p', path.join(nativeDir, 'build')); + shell.mkdir(prefixDir); + + shell.pushd(path.join(nativeDir, 'build')); + + var buildType = '"Debug"'; + if (!debug) + buildType = '"Release"'; + + var cmakeCmd = 'cmake ' + campoDir + ' -DCMAKE_INSTALL_PREFIX="' + prefixDir + '"' + + ' -DCMAKE_BUILD_TYPE=' + buildType; + + var deps = additionalBuildDependencies(ubuntuDir).join(' ').replace(/ARCH/g, ''); + if (deps.length) + cmakeCmd += ' -DADDITIONAL_DEPENDECIES="' + deps + '"'; + + var debDir; + return Utils.execAsync(cmakeCmd).then(function () { + return Utils.execAsync('make -j ' + cpuCount() + '; make install'); + }).then(function () { + Utils.cp(path.join(ubuntuDir, 'config.xml'), prefixDir); + Utils.cp(path.join(ubuntuDir, 'www', '*'), path.join(prefixDir, 'www')); + Utils.cp(path.join(ubuntuDir, 'qml', '*'), path.join(prefixDir, 'qml')); + + Utils.popd(); + + var manifest = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'manifest.json'), {encoding: "utf8"})); + + assert(manifest.name.length); + assert(manifest.name.indexOf(' ') == -1); + + debDir = path.join(nativeDir, manifest.name); + + shell.rm('-rf', debDir); + + shell.mkdir('-p', path.join(debDir, 'debian')); + Utils.cp(path.join(campoDir, '*'), debDir); + + Utils.cp(path.join(ubuntuDir, 'config.xml'), path.join(debDir, 'debian')); + Utils.cp(path.join(ubuntuDir, 'www', '*'), path.join(debDir, 'www')); + Utils.cp(path.join(ubuntuDir, 'qml', '*'), path.join(debDir, 'qml')); + + var destDir = path.join('/opt', manifest.name); + + var icon = fs.readFileSync(path.join(ubuntuDir, 'cordova.desktop'), {encoding: "utf8"}).match(/^Icon=(.+)$/m); + icon = icon ? '/opt/' + manifest.name + '/' + icon[1] : 'qmlscene'; + + var maintainerEmail = manifest.maintainer.match('<.+>$'); + maintainerEmail = maintainerEmail?maintainerEmail[0]:''; + var maintainerName = manifest.maintainer.replace(maintainerEmail, '').trim(); + maintainerEmail = maintainerEmail.replace('<', '').replace('>', ''); + + var props = { PACKAGE_NAME: manifest.name, + PACKAGE_TITLE: manifest.title, + PACKAGE_VERSION: manifest.version, + MAINTAINER_NAME: maintainerName, + MAINTAINER_EMAIL: maintainerEmail, + PACKAGE_DESCRIPTION: manifest.description, + PACKAGE_ICON: icon }; + var templateDir = path.join(campoDir, 'bin', 'templates', 'project', 'misc'); + var templates = [{source: path.join(templateDir, 'changelog'), dest: path.join(debDir, 'debian', 'changelog')}, + {source: path.join(templateDir, 'compat'), dest: path.join(debDir, 'debian', 'compat')}, + {source: path.join(templateDir, 'control'), dest: path.join(debDir, 'debian', 'control')}, + {source: path.join(templateDir, 'rules'), dest: path.join(debDir, 'debian', 'rules')}, + {source: path.join(templateDir, 'cordova.desktop'), dest: path.join(debDir, 'debian', 'cordova.desktop')}, + {source: path.join(templateDir, 'install'), dest: path.join(debDir, 'debian', manifest.name + '.install')}]; + for (var i = 0; i < templates.length; i++) { + fillTemplate(templates[i].source, templates[i].dest, props); + } + console.error('In order to build debian package, execute'.yellow); + console.error(('cd ' + debDir + '; ' + 'debuild').yellow); + }); +}; + +/** +* Generates a file from a template source, injecting the values contained in the +* provided js object. +*/ +function fillTemplate(source, dest, obj) { + var content = fs.readFileSync(source, {encoding: "utf8"}); + for (var prop in obj) { + content = content.replace(new RegExp('{' + prop + '}', 'g'), obj[prop]) + } + + fs.writeFileSync(dest, content); +} + +function additionalBuildDependencies(ubuntuDir) { + var files = []; + try { + files = fs.readdirSync(path.join(ubuntuDir, 'configs')).filter(function(s) { + return s[0] != '.'; + }); + } catch (e) {} + + var pkgConfig = []; + for (var i = 0; i < files.length; i++) { + var config = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'configs', files[i]))); + if (config.pkgConfig) + pkgConfig = pkgConfig.concat(config.pkgConfig); + } + + return pkgConfig; +} + +function checkClickPackage(prefixDir) { + shell.pushd(prefixDir); + + // 13.10 missing click-reviewers-tools package + // FIXME: remove this check after EOL + if (fs.existsSync('/usr/bin/click-run-checks')) { + var cmd = '/usr/bin/click-run-checks *.click'; + console.log(cmd.green); + var output = shell.exec(cmd, { silent: true }).output; + var json = '[', b = 0; + for (var i = 0; i < output.length; i++) { + if (output[i] == '{') { + if (json.length > 1 && !b) + json += ', '; + b++; + } else if (output[i] == '}') { + b--; + if (b == 0) + json += '} '; + } + if (b > 0) { + json += output[i]; + } + } + json += ']'; + var out = JSON.parse(json); + for (var i = 0; i < out.length; i++) { + if (out[i].warn) { + for (var m in out[i].warn) { + if (out[i].warn[m].text) { + console.warn(out[i].warn[m].text.yellow); + if (out[i].warn[m].link) + console.warn(out[i].warn[m].link); + } + } + } + } + for (var i = 0; i < out.length; i++) { + if (out[i].error) { + for (var m in out[i].error) { + if (out[i].error[m].text) { + console.warn(out[i].error[m].text.yellow); + if (out[i].error[m].link) + console.warn(out[i].error[m].link); + } + } + } + } + } + + Utils.popd(); +} + +function cpuCount() { + return os.cpus().length; +} + +function checkEnv(ubuntuDir) { + var deps = additionalDependencies(ubuntuDir).join(' '); + deps = deps.replace(/:ARCH/g, ''); + + if (!deps.length) + return; + + var cmd = "dpkg-query -Wf'${db:Status-abbrev}' " + deps; + console.log(cmd.green); + res = shell.exec(cmd); + + if (res.code !== 0 || res.output.indexOf('un') !== -1) { + console.error(("Error: missing packages" + deps).red); + process.exit(1); + } +} + +function checkChrootEnv(ubuntuDir, architecture, framework) { + var deps = "cmake libicu-dev:ARCH pkg-config qtbase5-dev:ARCH qtchooser qtdeclarative5-dev:ARCH qtfeedback5-dev:ARCH qtlocation5-dev:ARCH qtmultimedia5-dev:ARCH qtpim5-dev:ARCH libqt5sensors5-dev:ARCH qtsystems5-dev:ARCH "; + deps += additionalDependencies(ubuntuDir).join(' '); + deps = deps.replace(/ARCH/g, architecture); + + var cmd = "click chroot -a " + architecture + " -f " + framework + " run dpkg-query -Wf'${db:Status-abbrev}' " + deps; + console.log(cmd.green); + res = shell.exec(cmd); + + if (res.code !== 0 || res.output.indexOf('un') !== -1) { + console.error(("Error: missing " + architecture + " chroot").red); + console.error(("run:\nsudo click chroot -a " + architecture + " -f " + framework + " create").red); + console.error(("sudo click chroot -a " + architecture + " -f " + framework + " install " + deps).red); + process.exit(1); + } +} + +function additionalDependencies(ubuntuDir) { + var files = []; + try { + files = fs.readdirSync(path.join(ubuntuDir, 'configs')).filter(function(s) { + return s[0] != '.'; + }); + } catch (e) {} + var deb = []; + for (var i = 0; i < files.length; i++) { + var config = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'configs', files[i]))); + if (config.deb) + deb = deb.concat(config.deb); + } + return deb; +} + + http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/cordova/lib/constants.js ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova/lib/constants.js b/bin/templates/project/cordova/lib/constants.js new file mode 100644 index 0000000..a12155b --- /dev/null +++ b/bin/templates/project/cordova/lib/constants.js @@ -0,0 +1,33 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2014 Canonical Ltd. + * + * Licensed 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. + */ + +module.exports = { + 'DEFAULT_FRAMEWORK': 'ubuntu-sdk-14.04', + 'DEFAULT_ARCH': 'armhf', + 'PLATFORM_TYPES': { + 'PHONE': 0, + 'DESKTOP': 1, + 'ALL': 2 + }, + 'MSG': { + 'UBUNTU_TOUCH_DEVICE_NOT_AVALIABLE': 'UbuntuTouch device is not attached', + 'EMULATOR_IS_NOT_RUNNING': 'UbuntuTouch emulator is not running' + } +}; http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/cordova/lib/device.js ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova/lib/device.js b/bin/templates/project/cordova/lib/device.js new file mode 100644 index 0000000..7ca1c81 --- /dev/null +++ b/bin/templates/project/cordova/lib/device.js @@ -0,0 +1,72 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2014 Canonical Ltd. + * + * Licensed 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 assert = require('assert'); +var Utils = require('./utils'); + +module.exports.list = function () { + var res = Utils.execSync('adb devices'); + + var response = res.output.split('\n'); + var deviceList = []; + + for (var i = 1; i < response.length; i++) { + if (response[i].match(/\w+\tdevice/)) { + deviceList.push(response[i].replace(/\tdevice/, '').replace('\r', '')); + } + } + + return deviceList; +}; + +module.exports.isAttached = function (target) { + var res = adbExec(target, 'get-state'); + + if (res.output.indexOf('device') == -1) + return false; + + res = adbExec(target, 'shell uname -a'); + if (res.output.indexOf('ubuntu-phablet') == -1) + return false; + + return true; +}; + +module.exports.arch = function (target) { + var out = adbExec(target, 'shell "dpkg --print-architecture 2>/dev/null"').output.split('\r\n'); + + assert.ok(out.length == 2 && out[0].indexOf(' ') == -1); + + return out[0]; +}; + +function adbExec(target, command, options) { + assert.ok(target && command); + return Utils.exec('adb -s ' + target + ' ' + command); +} + +function adbExecAsync(target, command) { + assert.ok(target && command); + return Utils.execAsync('adb -s ' + target + ' ' + command); +} + +module.exports.adbExec = adbExec; +module.exports.adbExecAsync = adbExecAsync; http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/cordova/lib/msg.js ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova/lib/msg.js b/bin/templates/project/cordova/lib/msg.js new file mode 100644 index 0000000..6125aa5 --- /dev/null +++ b/bin/templates/project/cordova/lib/msg.js @@ -0,0 +1,25 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2013 Canonical Ltd. + * + * Licensed 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. + * +*/ + +module.exports = { + UBUNTU_TOUCH_DEVICE_NOT_AVALIABLE: 'UbuntuTouch device is not attached', + EMULATOR_IS_NOT_RUNNING: 'UbuntuTouch emulator is not running' +}; http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/cordova/lib/run.js ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova/lib/run.js b/bin/templates/project/cordova/lib/run.js new file mode 100644 index 0000000..0418fce --- /dev/null +++ b/bin/templates/project/cordova/lib/run.js @@ -0,0 +1,137 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2014 Canonical Ltd. + * + * Licensed 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 assert = require('assert'); +var colors = require('colors'); +var fs = require('fs'); +var path = require('path'); +var shell = require('shelljs'); + +var build = require('./build').build; + +var Devices = require('./device'); +var Constants = require('./constants'); +var Utils = require('./utils'); + +var PLATFORMS = Constants.PLATFORM_TYPES; +var MSG = Constants.MSG; + +module.exports.run = function(rootDir, desktop, debug, target, nobuild, emulator, framework) { + if (desktop && !emulator) { + return build(rootDir, PLATFORMS.DESKTOP, nobuild, null, null, debug).then(function () { + return runNative(rootDir, debug); + }); + } + + if (!framework) + framework = Constants.DEFAULT_FRAMEWORK; + + if (!target) { + var devices = Devices.list(); + + if (!devices.length) { + console.error(MSG.UBUNTU_TOUCH_DEVICE_NOT_AVALIABLE.red) + process.exit(1); + } + + if (emulator) { + devices = devices.filter(function (name) { + return name.match(/^emulator-/); + }); + if (!devices.length) { + console.error(MSG.EMULATOR_IS_NOT_RUNNING.red) + process.exit(1); + } + } + + target = devices[0]; + + if (devices.length > 1) { + console.warn('you can specify target with --target '.yellow); + console.warn(('running on ' + target).yellow); + } + } + var arch = Devices.arch(target); + + return build(rootDir, PLATFORMS.PHONE, nobuild, arch, framework, debug).then(function () { + return runOnDevice(rootDir, debug, target, arch, framework); + }); +}; + +function runNative(rootDir, debug) { + console.log('Running Cordova'.green); + var ubuntuDir = path.join(rootDir, 'platforms', 'ubuntu'); + var nativeDir = path.join(ubuntuDir, 'native'); + + Utils.pushd(path.join(nativeDir, 'prefix')); + + var cmd = 'QTWEBKIT_INSPECTOR_SERVER=9222 ./cordova-ubuntu www/'; + if (debug) { + cmd = "DEBUG=1 " + cmd; + console.error('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222'.yellow); + } + + return Utils.execAsync(cmd).then(function () { + Utils.popd(); + }); +} + +function runOnDevice(rootDir, debug, target, architecture, framework) { + var ubuntuDir = path.join(rootDir, 'platforms', 'ubuntu'); + + if (!isDeviceAttached(target)) { + console.error(MSG.UBUNTU_TOUCH_DEVICE_NOT_AVALIABLE.red) + process.exit(1); + } + + var archDir = path.join(ubuntuDir, framework, architecture); + var prefixDir = path.join(archDir, 'prefix'); + + Utils.pushd(prefixDir); + + var manifest = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'manifest.json'), {encoding: "utf8"})); + var appId = manifest.name; + + var names = shell.ls().filter(function (name) { + return name.indexOf(appId) == 0 && name.indexOf('.click'); + }); + + assert.ok(names.length == 1); + + adbExec(target, 'shell "ps -A -eo pid,cmd | grep cordova-ubuntu | awk \'{ print \\$1 }\' | xargs kill -9"') + + if (debug) + adbExec(target, 'forward --remove-all'); + + adbExec(target, 'push ' + names[0] + ' /home/phablet'); + adbExec(target, 'shell "cd /home/phablet/; pkcon install-local ' + names[0] + ' -p --allow-untrusted -y"'); + + if (debug) { + console.error('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222'); + + adbExec(target, 'forward tcp:9222 tcp:9222'); + } + + console.log('have fun!'.rainbow); + + return adbExecAsync(target, 'shell bash -c "ubuntu-app-launch \\`ubuntu-app-triplet ' + appId + '\\`"').then(function () { + Utils.popd(); + }); +} http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/cordova/lib/utils.js ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova/lib/utils.js b/bin/templates/project/cordova/lib/utils.js new file mode 100644 index 0000000..60e99c4 --- /dev/null +++ b/bin/templates/project/cordova/lib/utils.js @@ -0,0 +1,72 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2014 Canonical Ltd. + * + * Licensed 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 Q = require('q'); +var colors = require('colors'); +var shell = require('shelljs'); + +module.exports.cp = function(source, dest) { + console.log(('cp -Rf ' + source + ' ' + dest).green); + + if (shell.cp('-r', source, dest) === null) { + console.error("FAILED".underline.red); + process.exit(1); + } +}; + +module.exports.pushd = function(dir) { + console.log(('pushd ' + dir).green); + shell.pushd(dir); +}; + +module.exports.popd = function(dir) { + console.log(('popd').green); + shell.popd(); +}; + +module.exports.execSync = function(cmd, silent) { + console.log(cmd.green); + + var res = shell.exec(cmd, { silent: silent }); + if (res.code !== 0) { + console.error(cmd.green + " " + "FAILED".underline.red); + process.exit(1); + } + + return res; +}; + +module.exports.execAsync = function (cmd) { + var deferred = Q.defer(); + + console.log(cmd.green); + + shell.exec(cmd, { async: true }, function (code, output) { + var res = { code: code, output: output }; + if (res.code !== 0) { + console.error(cmd.green + " " + "FAILED".underline.red); + process.exit(1); + } + deferred.resolve(res); + }); + + return deferred.promise; +}; + http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/cordova/run ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova/run b/bin/templates/project/cordova/run new file mode 100755 index 0000000..2668dda --- /dev/null +++ b/bin/templates/project/cordova/run @@ -0,0 +1,33 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2013 Canonical Ltd. + * + * Licensed 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 path = require('path'); +var check_reqs = require('./lib/check_reqs').check_reqs; +var PLATFORMS = require('./lib/constants').PLATFORM_TYPES; +var run = require('./lib/run').run; + +var root = path.resolve(); +var www = path.join(root, 'www'); + +check_reqs(function () { + var argv = require('optimist').boolean(['device', 'emulator', 'debug', 'nobuild']).string(['target', 'framework']).argv; + return run(root, !argv.device, argv.debug, argv.target, argv.nobuild, argv.emulator, argv.framework); +}); http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/cordova/version ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova/version b/bin/templates/project/cordova/version new file mode 100755 index 0000000..26dabe2 --- /dev/null +++ b/bin/templates/project/cordova/version @@ -0,0 +1,25 @@ +#!/usr/bin/env node + +/* + * + * Copyright 2013 Canonical Ltd. + * + * Licensed 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. + * +*/ + +// Coho updates this line: +var VERSION = "3.7.0-dev"; + +console.log(VERSION); http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/misc/changelog ---------------------------------------------------------------------- diff --git a/bin/templates/project/misc/changelog b/bin/templates/project/misc/changelog new file mode 100644 index 0000000..ec94655 --- /dev/null +++ b/bin/templates/project/misc/changelog @@ -0,0 +1,7 @@ +{PACKAGE_NAME} ({PACKAGE_VERSION}) trusty; urgency=medium + + [ {MAINTAINER_NAME} ] + * upstream release + + -- {MAINTAINER_NAME} <{MAINTAINER_EMAIL}> Thu, 30 Aug 2014 06:06:06 +0000 + http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/misc/compat ---------------------------------------------------------------------- diff --git a/bin/templates/project/misc/compat b/bin/templates/project/misc/compat new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/bin/templates/project/misc/compat @@ -0,0 +1 @@ +9 http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/misc/control ---------------------------------------------------------------------- diff --git a/bin/templates/project/misc/control b/bin/templates/project/misc/control new file mode 100644 index 0000000..51fb082 --- /dev/null +++ b/bin/templates/project/misc/control @@ -0,0 +1,17 @@ +Source: {PACKAGE_NAME} +Section: devel +Priority: optional +Maintainer: {MAINTAINER_NAME} <{MAINTAINER_EMAIL}> +Build-Depends: ubuntu-sdk, + qtfeedback5-dev, + qtmultimedia5-dev, + qtpim5-dev, + libqt5sensors5-dev, + qtsystems5-dev, + qtlocation5-dev, + libicu-dev + +Package: {PACKAGE_NAME} +Architecture: any +Description: {PACKAGE_DESCRIPTION} +Depends: ubuntu-sdk-libs http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/misc/cordova.desktop ---------------------------------------------------------------------- diff --git a/bin/templates/project/misc/cordova.desktop b/bin/templates/project/misc/cordova.desktop new file mode 100644 index 0000000..dee2f44 --- /dev/null +++ b/bin/templates/project/misc/cordova.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Name={PACKAGE_TITLE} +Exec=/opt/{PACKAGE_NAME}/cordova-ubuntu +Terminal=false +Type=Application +X-Ubuntu-Touch=true +Icon={PACKAGE_ICON} http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/misc/install ---------------------------------------------------------------------- diff --git a/bin/templates/project/misc/install b/bin/templates/project/misc/install new file mode 100644 index 0000000..c3e51ca --- /dev/null +++ b/bin/templates/project/misc/install @@ -0,0 +1,3 @@ +/opt/{PACKAGE_NAME} +/usr/share/applications/* + http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/templates/project/misc/rules ---------------------------------------------------------------------- diff --git a/bin/templates/project/misc/rules b/bin/templates/project/misc/rules new file mode 100755 index 0000000..27bc587 --- /dev/null +++ b/bin/templates/project/misc/rules @@ -0,0 +1,27 @@ +#!/usr/bin/make -f + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +export CFLAGS := $(shell dpkg-buildflags --get CFLAGS) $(shell dpkg-buildflags --get CPPFLAGS) +export CXXFLAGS := $(shell dpkg-buildflags --get CXXFLAGS) $(shell dpkg-buildflags --get CPPFLAGS) +export LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS) -Wl,--as-needed +export QT_SELECT := qt5 + +DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) + +# ----------------------------------- + +%: + dh $@ --fail-missing + +override_dh_auto_configure: + dh_auto_configure -- -DCMAKE_INSTALL_PREFIX=/opt/{PACKAGE_NAME} + +override_dh_auto_install: + dh_auto_install --destdir=debian/tmp + cp -R $(CURDIR)/www/* $(CURDIR)/debian/tmp/opt/{PACKAGE_NAME}/www + cp -R $(CURDIR)/debian/config.xml $(CURDIR)/debian/tmp/opt/{PACKAGE_NAME}/ + cp -R $(CURDIR)/qml/* $(CURDIR)/debian/tmp/opt/{PACKAGE_NAME}/qml + mkdir -p $(CURDIR)/debian/tmp/usr/share/applications/ + cp -R $(CURDIR)/debian/cordova.desktop $(CURDIR)/debian/tmp/usr/share/applications/{PACKAGE_NAME}.desktop http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/bin/update ---------------------------------------------------------------------- diff --git a/bin/update b/bin/update index 636396c..e5f9bbe 100755 --- a/bin/update +++ b/bin/update @@ -20,42 +20,15 @@ */ var path = require('path'); var args = process.argv; -var ROOT = path.join(__dirname, '..'); var fs = require('fs'); -function installDependecies(cb) { - console.log('running \'npm install\'.....'); - var exec = require('child_process').exec; - var cwd = process.cwd(); - - var block = true; - exec('npm install', {cwd: __dirname}, function (error, stdout, stderr) { - block = false; - if (error !== null) { - console.error('ERROR : running \'npm install\' is npm installed? ' + error); - console.error(stderr); - process.exit(error.code); - } - }); - function wait() { - if (block) - setTimeout(wait, 1500); - else - cb(); - }; - setTimeout(wait, 1500); -} - - -function updateProject(projectPath, ROOT) { - installDependecies(function () { - var currentVersion = fs.readFileSync(path.join(projectPath, 'build', 'VERSION'), {encoding: "utf8"}); - var version = fs.readFileSync(path.join(ROOT, 'VERSION'), {encoding: "utf8"}); - if (version == currentVersion) - return; +var ROOT = path.join(__dirname, '..'); +var projectPath = args[2]; - require('./build/lib/ubuntu').updateProject(projectPath, ROOT); +var currentVersion = fs.readFileSync(path.join(projectPath, 'build', 'VERSION'), {encoding: "utf8"}); +var version = fs.readFileSync(path.join(ROOT, 'VERSION'), {encoding: "utf8"}); +if (version !== currentVersion) { + check_reqs(function () { + require('./lib/update').updateProject(projectPath, ROOT); }); } - -updateProject(args[2], ROOT); http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/4894ac2f/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index cf6842d..4a36966 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,43 @@ { "name": "cordova-ubuntu", "version": "3.7.0-dev", - "description": "cordova-ubuntu release", + "description": "Cordova tooling for the Ubuntu platform.", "main": "bin/create", "repository": { "type": "git", "url": "https://git-wip-us.apache.org/repos/asf/cordova-ubuntu.git" }, + "engineStrict": "true", + "engines": { + "node": ">=0.10.0" + }, + "dependencies": { + "colors": "0.6.2", + "optimist": "0.6.0", + "q": "2.0.*", + "shelljs": "0.2.6" + }, + "bundledDependencies": [ + "colors", + "optimist", + "q", + "shelljs" + ], "keywords": [ "ubuntu", "cordova", "apache" ], "author": "Apache Software Foundation", + "contributors": [ + { + "name": "Maxim Ermilov", + "email": "maxim.ermilov@canonical.com" + }, + { + "name": "Jean-Francois Moy", + "email": "jean-francois.moy@canonical.com" + } + ], "license": "Apache Version 2.0" -} \ No newline at end of file +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org