-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (61 loc) · 2.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env node
// module imports
const path = require('path');
const fs = require('fs');
const sh = require('shelljs');
const replace = require('replace-in-file');
const common = require('./lib/common');
//var packageJson = require(path.resolve(process.cwd(), './package.json'));
const cordovaConfig = require(path.resolve(process.cwd(), './cordova-helper.json'));
const cordovaCreate = require('./lib/cordova-create');
const cordovaRun = require('./lib/cordova-run');
const cordovawww = require('./lib/cordova-www');
//var config = packageJson['cordova-helper'] || {};
const distPath = path.resolve(cordovaConfig.distFolder);
const platform = cordovaConfig.platform;
const temp = path.resolve(process.cwd(), common.tempFolder);
const indexFileName = cordovaConfig.indexFileName ? cordovaConfig.indexFileName : common.dIndexFileName;
const indexFilePath = `${temp}/${indexFileName}`;
if (!fs.existsSync(temp)) {
sh.exec("md " + temp);
}
sh.rm('-rf',`${temp}/*`);
//copy from dist folder to temp
sh.cp('-R',`${distPath}/*`, `${temp}/`);
console.log("copied dist files to temp");
if (fs.existsSync(indexFilePath)) {
const options = {
files: indexFilePath,
from: ['<base href="/">', '<base href="./">'],
to: '<base href="./">'
}
// usually this base exists for web applications. This has to be replaced in this format for server application.
const changes = replace.sync(options);
// in case if the base tag is not present insert a server format base uri.
if (!changes) {
const optionsAdd = {
files: indexFilePath,
from: '</head>',
to: '<base href="./"></head>'
}
replace.sync(optionsAdd);
console.log("add base href");
}
}
// adding cordova js script reference. This is mandatory for cordova usage.
const options = {
files: indexFilePath,
from: '</head>',
to: '<script type="text/javascript" src="cordova.js"></script></head>'
}
const changes = replace.sync(options);
console.log("add cordova.js");
const temp_app = common.cordAppName;
if (!fs.existsSync(temp_app)) {
cordovaCreate.create(temp_app);
}
console.log("created cordova app");
cordovawww.copywww();
console.log("copied temp files to cordova www");
// run cordova from the project folder
cordovaRun.runCordova(temp_app,platform);