Skip to content
This repository was archived by the owner on May 13, 2021. It is now read-only.

Commit b013753

Browse files
committed
Merge pull request #206 from manifoldjs/v0.5.0
V0.5.0 - Enable platform extensibility in ManifoldJS
2 parents 510145f + d4cf98e commit b013753

File tree

127 files changed

+541
-8904
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+541
-8904
lines changed

.gitignore

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,36 @@
1-
/node_modules/
1+
# Logs
2+
logs
3+
*.log
24
npm-debug.log
3-
coverage.html
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Visual Studio
15+
launch.json
416
.ntvs_analysis.dat
517
*.njsproj
618
*.suo
719
*.sln
8-
.settings
9-
launch.json
20+
.vs
21+
22+
# Blanket coverage
23+
coverage.html
24+
25+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26+
.grunt
27+
28+
# node-waf configuration
29+
.lock-wscript
30+
31+
# Compiled binary addons (http://nodejs.org/api/addons.html)
32+
build/Release
33+
34+
# Dependency directory
35+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
36+
node_modules

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ manifoldjs <command>
5151
### Example
5252
**Creating a new hosted web application**
5353
````
54-
manifoldjs http://shiftr.azurewebsites.net -d C:\Projects -l info -p windows10,android -b
54+
manifoldjs http://shiftr.azurewebsites.net -d C:\Projects -l info -p windows10,android
5555
````
5656
**Packaging a Windows 10 app for submission to the Store**
5757
````
58-
manifoldjs package /myapp/windows10/manifest /yourapp/yourapp.appx -l debug
58+
manifoldjs package -p windows10 -l debug
5959
````
6060

6161
## Client Library

commands/generate.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
'use strict';
2+
3+
var url = require('url'),
4+
path = require('path');
5+
6+
var Q = require('q');
7+
8+
var lib = require('manifoldjs-lib');
9+
10+
var log = lib.log,
11+
manifestTools = lib.manifestTools,
12+
projectBuilder = lib.projectBuilder,
13+
utils = lib.utils;
14+
15+
var build = require('./package');
16+
17+
function getW3cManifest(siteUrl, manifestLocation, callback) {
18+
function resolveStartURL(err, manifestInfo) {
19+
if (err) {
20+
return callback(err, manifestInfo);
21+
}
22+
23+
return manifestTools.validateAndNormalizeStartUrl(siteUrl, manifestInfo, callback);
24+
}
25+
26+
if (siteUrl) {
27+
var parsedSiteUrl = url.parse(siteUrl);
28+
if (!parsedSiteUrl.hostname) {
29+
return callback(new Error('The site URL is not a valid URL.'));
30+
}
31+
}
32+
33+
if (manifestLocation) {
34+
var parsedManifestUrl = url.parse(manifestLocation);
35+
if (parsedManifestUrl && parsedManifestUrl.host) {
36+
// download manifest from remote location
37+
log.info('Downloading manifest from ' + manifestLocation + '...');
38+
manifestTools.downloadManifestFromUrl(manifestLocation, resolveStartURL);
39+
} else {
40+
// read local manifest file
41+
log.info('Reading manifest file ' + manifestLocation + '...');
42+
manifestTools.getManifestFromFile(manifestLocation, resolveStartURL);
43+
}
44+
} else if (siteUrl) {
45+
// scan a site to retrieve its manifest
46+
log.info('Scanning ' + siteUrl + ' for manifest...');
47+
manifestTools.getManifestFromSite(siteUrl, resolveStartURL);
48+
} else {
49+
return callback(new Error('A site URL or manifest should be specified.'));
50+
}
51+
}
52+
53+
function generateApp(program) {
54+
55+
var siteUrl = program.args[0];
56+
var rootDir = program.directory ? path.resolve(program.directory) : process.cwd();
57+
var platforms = program.platforms.split(/[\s,]+/);
58+
59+
var deferred = Q.defer();
60+
getW3cManifest(siteUrl, program.manifest, function (err, manifestInfo) {
61+
if (err) {
62+
return deferred.reject(err);
63+
}
64+
65+
// Fix #145: don't require a short name
66+
manifestInfo.content.short_name = manifestInfo.content.short_name ||
67+
manifestInfo.content.name ||
68+
manifestInfo.default.short_name;
69+
70+
// if specified as a parameter, override the app's short name
71+
if (program.shortname) {
72+
manifestInfo.content.short_name = program.shortname;
73+
}
74+
75+
log.debug('Manifest contents:\n' + JSON.stringify(manifestInfo.content, null, 4));
76+
77+
// add generatedFrom value to manifestInfo for telemetry
78+
manifestInfo.generatedFrom = 'CLI';
79+
80+
// Create the apps for the specified platforms
81+
return projectBuilder.createApps(manifestInfo, rootDir, platforms, program).then(function (projectDir) {
82+
if (program.build) {
83+
program.args[1] = projectDir;
84+
return build(program).catch(function (err) {
85+
log.warn('One or more platforms could not be built successfully. Correct any errors and then run manifoldjs package [project-directory] [options] to build the applications.');
86+
// return deferred.reject(err);
87+
});
88+
}
89+
})
90+
.then(function () {
91+
log.info('The application(s) are ready.');
92+
return deferred.resolve();
93+
})
94+
.catch(function (err) {
95+
return deferred.reject(err);
96+
});
97+
});
98+
99+
return deferred.promise;
100+
};
101+
102+
module.exports = generateApp;

commands/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
module.exports = {
4+
generate: require('./generate'),
5+
package: require('./package'),
6+
run: require('./run'),
7+
open: require('./open'),
8+
visualstudio: require('./visualstudio'),
9+
platform: require('./platform')
10+
};

commands/open.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
var Q = require('q');
4+
5+
var lib = require('manifoldjs-lib');
6+
7+
var log = lib.log,
8+
projectBuilder = lib.projectBuilder;
9+
10+
function openApp (program) {
11+
12+
if (program.args.length < 2) {
13+
return Q.reject(new Error('You must specify a platform.'));
14+
}
15+
16+
var platform = program.args[1];
17+
var projectDir = program.args.length < 3 ? process.cwd() : program.args[2];
18+
return projectBuilder.openApp(platform, projectDir, program);
19+
}
20+
21+
module.exports = openApp;

commands/package.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
var lib = require('manifoldjs-lib');
4+
5+
var log = lib.log,
6+
projectBuilder = lib.projectBuilder;
7+
8+
function packageApps(program) {
9+
10+
var platforms = program.platforms.split(/[\s,]+/);
11+
var projectDir = program.args.length < 2 ? process.cwd() : program.args[1];
12+
return lib.projectTools.getProjectPlatforms(projectDir).then(function (projectPlatforms) {
13+
// exclude any platforms not present in the project
14+
platforms = platforms.filter(function (platform) {
15+
return projectPlatforms.indexOf(platform) >= 0;
16+
});
17+
18+
return projectBuilder.packageApps(platforms, projectDir, program);
19+
});
20+
}
21+
22+
module.exports = packageApps;

commands/platform.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
'use strict';
2+
3+
var fs = require('fs'),
4+
path = require('path');
5+
6+
var Q = require('q');
7+
8+
var lib = require('manifoldjs-lib');
9+
10+
var log = lib.log,
11+
platformTools = lib.platformTools,
12+
utils = lib.utils;
13+
14+
// registers a new platform module
15+
function addPlatform (program) {
16+
if (program.args.length < 3) {
17+
return Q.reject(new Error('You must specify a platform ID.'));
18+
}
19+
20+
if (program.args.length < 4) {
21+
return Q.reject(new Error('You must specify a package source for the platform. This can be an npm package, a GitHub URL, or a local path.'));
22+
}
23+
24+
var platformId = program.args[2].toLowerCase();
25+
var source = program.args[3];
26+
27+
return platformTools.addPlatform(platformId, source).then(function () {
28+
log.info('The \'' + platformId + '\' platform was registered successfully.');
29+
});
30+
}
31+
32+
// removes a registered platform module
33+
function removePlatform (program) {
34+
if (program.args.length < 3) {
35+
return Q.reject(new Error('You must specify a platform ID.'));
36+
}
37+
38+
var platformId = program.args[2].toLowerCase();
39+
40+
return platformTools.removePlatform(platformId).then(function () {
41+
log.info('The \'' + platformId + '\' platform was unregistered successfully.');
42+
});
43+
}
44+
45+
function listPlatforms (program) {
46+
try {
47+
var platforms = platformTools.listPlatforms();
48+
log.write('Available platforms are: ' + platforms.join(', '));
49+
return Q.resolve();
50+
}
51+
catch (err) {
52+
return Q.reject(err);
53+
}
54+
}
55+
56+
function platformCommands (program) {
57+
if (program.args.length < 2) {
58+
return Q.reject(new Error('You must specify a platform operation: add, remove, or list.'));
59+
}
60+
61+
var command = program.args[1].toLowerCase();
62+
switch (command) {
63+
case 'add':
64+
return addPlatform(program);
65+
66+
case 'remove':
67+
return removePlatform(program);
68+
69+
case 'list':
70+
return listPlatforms(program);
71+
72+
default:
73+
return Q.reject(new Error('Unknown option \'' + command + '\' specified.'));
74+
}
75+
}
76+
77+
module.exports = platformCommands;
78+
79+

commands/run.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
var Q = require('q');
4+
5+
var lib = require('manifoldjs-lib');
6+
7+
var log = lib.log,
8+
projectBuilder = lib.projectBuilder;
9+
10+
function runApp (program) {
11+
12+
if (program.args.length < 2) {
13+
return Q.reject(new Error('You must specify a platform.'));
14+
}
15+
16+
var platform = program.args[1];
17+
var projectDir = program.args.length < 3 ? process.cwd() : program.args[2];
18+
return projectBuilder.runApp(platform, projectDir, program);
19+
}
20+
21+
module.exports = runApp;

commands/visualstudio.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
3+
var Q = require('q');
4+
5+
var lib = require('manifoldjs-lib');
6+
7+
var CustomError = lib.CustomError,
8+
exec = lib.processTools.exec,
9+
fileTools = lib.fileTools,
10+
log = lib.log;
11+
12+
var open = require('./open');
13+
14+
function isWindows10Version (version) {
15+
return /^10/.test(version);
16+
}
17+
18+
function getWindowsVersion (callback) {
19+
log.debug('Obtaining Windows version...');
20+
exec('powershell', ['(Get-WmiObject win32_operatingsystem).version']).then(function (result) {
21+
return result.stdout.trim();
22+
})
23+
.catch (function (err) {
24+
return Q.reject(new CustomError('Failed to run the app for Windows platform.', err));
25+
})
26+
.nodeify(callback);
27+
}
28+
29+
// implements the original behavior of the visualstudio command
30+
// open windows10 project, if available, otherwise, open the windows project
31+
function runApp(program) {
32+
33+
log.warn('The \'visualstudio\' command is deprecated. Use \'manifoldjs open <windows|windows10>\' instead.');
34+
35+
var deferred = Q.defer();
36+
37+
var dir = process.cwd();
38+
fileTools.searchFile(dir, 'App.jsproj', function (err, results) {
39+
Q.ninvoke(getWindowsVersion).then(function (version) {
40+
if (results && results.length > 0 && isWindows10Version(version)) {
41+
program.args.push('windows10');
42+
return open(program).then(function () {
43+
deferred.resolve();
44+
});
45+
}
46+
47+
fileTools.searchFile(dir, 'CordovaApp.sln', function (err, results) {
48+
if (results && results.length > 0) {
49+
program.args.push('windows');
50+
return open(program).then(function () {
51+
deferred.resolve();
52+
});
53+
}
54+
});
55+
});
56+
});
57+
58+
return deferred.promise;
59+
}
60+
61+
module.exports = runApp;

0 commit comments

Comments
 (0)