| /** |
| 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. |
| ** |
| * BOOTSTRAP |
| * Runs through any bs to make sure the libraries and tests are good to go. |
| **/ |
| |
| var util = require('./src/util'), |
| create = require('./src/create'), |
| n = require('ncallbacks'), |
| path = require('path'), |
| fs = require('fs'), |
| shell = require('shelljs'), |
| platforms = require('./platforms'); |
| |
| // Create native projects using bin/create |
| var projectFixtures = path.join(__dirname, 'spec', 'fixtures', 'projects'); |
| var tempDir = path.join(projectFixtures, 'native'); |
| shell.rm('-rf', tempDir); |
| shell.mkdir('-p', tempDir); |
| |
| // Also create a standard cordova project for tests |
| var cordovaDir = path.join(projectFixtures, 'cordova'); |
| shell.rm('-rf', cordovaDir); |
| create(cordovaDir); |
| var platformsDir = path.join(cordovaDir, 'platforms'); |
| // kill the stupid spec shit! |
| shell.rm('-rf', path.join(cordovaDir, 'www', 'spec')); |
| |
| var end = n(Object.keys(platforms).length, function() { |
| // Check that we are installing globally into a root-only directory. |
| if (process.env.USER == 'root') { |
| console.log("**************************************************************************"); |
| console.log("* WARNING: YOU ARE INSTALLING GLOBALLY INTO A ROOT-ONLY DIRECTORY!!!1one *"); |
| console.log("* Your node install is global, so global modules get installed there too.*"); |
| console.log("* You should probably run the following command for this tool to run: *"); |
| console.log(" $ sudo chown -R " + process.env.SUDO_USER + " " + process.env.PWD); |
| console.log("* This will allow you to run this tool globally without using `sudo`. *"); |
| console.log("**************************************************************************"); |
| } |
| }); |
| |
| Object.keys(platforms).forEach(function(platform) { |
| platforms[platform].parser.check_requirements(function(err) { |
| if (err) { |
| console.error('WARNING: Your system does not meet requirements to create ' + platform + ' projects. See error output below.'); |
| console.error(err); |
| console.error('SKIPPING ' + platform + ' bootstrap.'); |
| end(); |
| } else { |
| console.log('SUCCESS: Minimum requirements for ' + platform + ' met.'); |
| var fix_path = path.join(tempDir, platform + '_fixture'); |
| var create = path.join(util.libDirectory, 'cordova-' + platform, 'bin', 'create'); |
| console.log('BOOTSTRAPPING ' + platform + '...'); |
| var cmd = create + ' "' + fix_path + '" org.apache.cordova.cordovaExample cordovaExample'; |
| shell.exec(cmd, {silent:true, async:true}, function(code, output) { |
| if (code > 0) { |
| console.error('ERROR! Could not create a native ' + platform + ' project test fixture. See below for error output.'); |
| console.error(output); |
| } else { |
| var platformDir = path.join(platformsDir, platform); |
| // remove extra spec bullshit as it intereferes with jasmine-node |
| var dub = path.join(fix_path, 'www'); |
| if (platform == 'android') dub = path.join(fix_path, 'assets', 'www'); |
| shell.rm('-rf', path.join(dub, 'spec')); |
| // copy over to full cordova project test fixture |
| shell.mkdir('-p', platformDir); |
| shell.cp('-rf', path.join(fix_path, '*'), platformDir); |
| shell.mkdir('-p',path.join(util.appDir(cordovaDir),'merges',platform)); |
| |
| // set permissions on executables |
| var scripts_path = path.join(fix_path, 'cordova'); |
| var other_path = path.join(platformDir, 'cordova'); |
| var scripts = fs.readdirSync(scripts_path); |
| scripts.forEach(function(script) { |
| var script_path = path.join(scripts_path, script); |
| var other_script_path = path.join(other_path, script); |
| shell.chmod('+x', script_path); |
| shell.chmod('+x', other_script_path); |
| }); |
| console.log('SUCCESS: ' + platform + ' ready to rock!'); |
| } |
| end(); |
| }); |
| } |
| }); |
| }); |