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 Q = require('q');
|
21 | var fs = require('fs');
|
22 | var path = require('path');
|
23 | var shell = require('shelljs');
|
24 | var create = require('./create');
|
25 | var events = require('cordova-common').events;
|
26 | var ConfigParser = require('cordova-common').ConfigParser;
|
27 | var CordovaError = require('cordova-common').CordovaError;
|
28 | var AppxManifest = require('../../template/cordova/lib/AppxManifest');
|
29 |
|
30 | // updates the cordova.js in project along with the cordova tooling.
|
31 | module.exports.update = function (destinationDir, options) {
|
32 | if (!fs.existsSync(destinationDir)) {
|
33 | // if specified project path is not valid then reject promise
|
34 | return Q.reject(new CordovaError('The given path to the project does not exist: ' + destinationDir));
|
35 | }
|
36 |
|
37 | var projectConfig = path.join(destinationDir, 'config.xml');
|
38 | if (!fs.existsSync(projectConfig)) {
|
39 | return Q.reject(new CordovaError('Can\'t update project at ' + destinationDir +
|
40 | '. config.xml does not exist in destination directory'));
|
41 | }
|
42 |
|
43 | var guid;
|
44 | var config = new ConfigParser(projectConfig);
|
45 |
|
46 | // guid param is used only when adding a platform, and isn't saved anywhere.
|
47 | // The only place, where it is being persisted - phone/win10 appxmanifest file,
|
48 | // but since win10 introduced just recently, we can't rely on its manifest
|
49 | // for old platform versions.
|
50 | var manifestPath = path.join(destinationDir, 'package.phone.appxmanifest');
|
51 | try {
|
52 | guid = AppxManifest.get(manifestPath).getPhoneIdentity().getPhoneProductId();
|
53 | } catch (e) { /* ignore IO errors */ }
|
54 |
|
55 | shell.rm('-rf', destinationDir);
|
56 | return create.create(destinationDir, config, { guid: guid }, events);
|
57 | };
|