1 | /**
|
2 | Licensed to the Apache Software Foundation (ASF) under one
|
3 | or more contributor license agreements. See the NOTICE file
|
4 | distributed with this work for additional information
|
5 | regarding copyright ownership. The ASF licenses this file
|
6 | to you under the Apache License, Version 2.0 (the
|
7 | "License"); you may not use this file except in compliance
|
8 | with the License. You may obtain a copy of the License at
|
9 |
|
10 | http://www.apache.org/licenses/LICENSE-2.0
|
11 |
|
12 | Unless required by applicable law or agreed to in writing,
|
13 | software distributed under the License is distributed on an
|
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15 | KIND, either express or implied. See the License for the
|
16 | specific language governing permissions and limitations
|
17 | under the License.
|
18 | */
|
19 |
|
20 | var path = require('path'),
|
21 | server = require('./server'),
|
22 | fs = require('fs'),
|
23 | util = require('./util');
|
24 |
|
25 | module.exports = function (opts) {
|
26 | var platformName = opts.platform;
|
27 | if (!platformName) {
|
28 | throw new Error('A platform must be specified');
|
29 | }
|
30 |
|
31 | opts.root = util.getPlatformWwwRoot(findProjectRoot(opts.root), platformName);
|
32 | if (!fs.existsSync(opts.root)) {
|
33 | throw new Error ('Project does not include the specified platform: ' + platformName);
|
34 | }
|
35 |
|
36 | return server(opts);
|
37 | };
|
38 |
|
39 | function findProjectRoot(path) {
|
40 | var projectRoot = util.cordovaProjectRoot(path);
|
41 | if (!projectRoot) {
|
42 | if (!path) {
|
43 | throw new Error('Current directory does not appear to be in a Cordova project.');
|
44 | } else {
|
45 | throw new Error('Directory "' + path + '" does not appear to be in a Cordova project.');
|
46 | }
|
47 | }
|
48 | return projectRoot;
|
49 | }
|