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

Commit

Permalink
Merge pull request #206 from manifoldjs/v0.5.0
Browse files Browse the repository at this point in the history
V0.5.0 - Enable platform extensibility in ManifoldJS
  • Loading branch information
f2bo committed Feb 23, 2016
2 parents 510145f + d4cf98e commit b013753
Show file tree
Hide file tree
Showing 127 changed files with 541 additions and 8,904 deletions.
35 changes: 31 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
/node_modules/
# Logs
logs
*.log
npm-debug.log
coverage.html

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Visual Studio
launch.json
.ntvs_analysis.dat
*.njsproj
*.suo
*.sln
.settings
launch.json
.vs

# Blanket coverage
coverage.html

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ manifoldjs <command>
### Example
**Creating a new hosted web application**
````
manifoldjs http://shiftr.azurewebsites.net -d C:\Projects -l info -p windows10,android -b
manifoldjs http://shiftr.azurewebsites.net -d C:\Projects -l info -p windows10,android
````
**Packaging a Windows 10 app for submission to the Store**
````
manifoldjs package /myapp/windows10/manifest /yourapp/yourapp.appx -l debug
manifoldjs package -p windows10 -l debug
````

## Client Library
Expand Down
102 changes: 102 additions & 0 deletions commands/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
'use strict';

var url = require('url'),
path = require('path');

var Q = require('q');

var lib = require('manifoldjs-lib');

var log = lib.log,
manifestTools = lib.manifestTools,
projectBuilder = lib.projectBuilder,
utils = lib.utils;

var build = require('./package');

function getW3cManifest(siteUrl, manifestLocation, callback) {
function resolveStartURL(err, manifestInfo) {
if (err) {
return callback(err, manifestInfo);
}

return manifestTools.validateAndNormalizeStartUrl(siteUrl, manifestInfo, callback);
}

if (siteUrl) {
var parsedSiteUrl = url.parse(siteUrl);
if (!parsedSiteUrl.hostname) {
return callback(new Error('The site URL is not a valid URL.'));
}
}

if (manifestLocation) {
var parsedManifestUrl = url.parse(manifestLocation);
if (parsedManifestUrl && parsedManifestUrl.host) {
// download manifest from remote location
log.info('Downloading manifest from ' + manifestLocation + '...');
manifestTools.downloadManifestFromUrl(manifestLocation, resolveStartURL);
} else {
// read local manifest file
log.info('Reading manifest file ' + manifestLocation + '...');
manifestTools.getManifestFromFile(manifestLocation, resolveStartURL);
}
} else if (siteUrl) {
// scan a site to retrieve its manifest
log.info('Scanning ' + siteUrl + ' for manifest...');
manifestTools.getManifestFromSite(siteUrl, resolveStartURL);
} else {
return callback(new Error('A site URL or manifest should be specified.'));
}
}

function generateApp(program) {

var siteUrl = program.args[0];
var rootDir = program.directory ? path.resolve(program.directory) : process.cwd();
var platforms = program.platforms.split(/[\s,]+/);

var deferred = Q.defer();
getW3cManifest(siteUrl, program.manifest, function (err, manifestInfo) {
if (err) {
return deferred.reject(err);
}

// Fix #145: don't require a short name
manifestInfo.content.short_name = manifestInfo.content.short_name ||
manifestInfo.content.name ||
manifestInfo.default.short_name;

// if specified as a parameter, override the app's short name
if (program.shortname) {
manifestInfo.content.short_name = program.shortname;
}

log.debug('Manifest contents:\n' + JSON.stringify(manifestInfo.content, null, 4));

// add generatedFrom value to manifestInfo for telemetry
manifestInfo.generatedFrom = 'CLI';

// Create the apps for the specified platforms
return projectBuilder.createApps(manifestInfo, rootDir, platforms, program).then(function (projectDir) {
if (program.build) {
program.args[1] = projectDir;
return build(program).catch(function (err) {
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.');
// return deferred.reject(err);
});
}
})
.then(function () {
log.info('The application(s) are ready.');
return deferred.resolve();
})
.catch(function (err) {
return deferred.reject(err);
});
});

return deferred.promise;
};

module.exports = generateApp;
10 changes: 10 additions & 0 deletions commands/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

module.exports = {
generate: require('./generate'),
package: require('./package'),
run: require('./run'),
open: require('./open'),
visualstudio: require('./visualstudio'),
platform: require('./platform')
};
21 changes: 21 additions & 0 deletions commands/open.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

var Q = require('q');

var lib = require('manifoldjs-lib');

var log = lib.log,
projectBuilder = lib.projectBuilder;

function openApp (program) {

if (program.args.length < 2) {
return Q.reject(new Error('You must specify a platform.'));
}

var platform = program.args[1];
var projectDir = program.args.length < 3 ? process.cwd() : program.args[2];
return projectBuilder.openApp(platform, projectDir, program);
}

module.exports = openApp;
22 changes: 22 additions & 0 deletions commands/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

var lib = require('manifoldjs-lib');

var log = lib.log,
projectBuilder = lib.projectBuilder;

function packageApps(program) {

var platforms = program.platforms.split(/[\s,]+/);
var projectDir = program.args.length < 2 ? process.cwd() : program.args[1];
return lib.projectTools.getProjectPlatforms(projectDir).then(function (projectPlatforms) {
// exclude any platforms not present in the project
platforms = platforms.filter(function (platform) {
return projectPlatforms.indexOf(platform) >= 0;
});

return projectBuilder.packageApps(platforms, projectDir, program);
});
}

module.exports = packageApps;
79 changes: 79 additions & 0 deletions commands/platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
'use strict';

var fs = require('fs'),
path = require('path');

var Q = require('q');

var lib = require('manifoldjs-lib');

var log = lib.log,
platformTools = lib.platformTools,
utils = lib.utils;

// registers a new platform module
function addPlatform (program) {
if (program.args.length < 3) {
return Q.reject(new Error('You must specify a platform ID.'));
}

if (program.args.length < 4) {
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.'));
}

var platformId = program.args[2].toLowerCase();
var source = program.args[3];

return platformTools.addPlatform(platformId, source).then(function () {
log.info('The \'' + platformId + '\' platform was registered successfully.');
});
}

// removes a registered platform module
function removePlatform (program) {
if (program.args.length < 3) {
return Q.reject(new Error('You must specify a platform ID.'));
}

var platformId = program.args[2].toLowerCase();

return platformTools.removePlatform(platformId).then(function () {
log.info('The \'' + platformId + '\' platform was unregistered successfully.');
});
}

function listPlatforms (program) {
try {
var platforms = platformTools.listPlatforms();
log.write('Available platforms are: ' + platforms.join(', '));
return Q.resolve();
}
catch (err) {
return Q.reject(err);
}
}

function platformCommands (program) {
if (program.args.length < 2) {
return Q.reject(new Error('You must specify a platform operation: add, remove, or list.'));
}

var command = program.args[1].toLowerCase();
switch (command) {
case 'add':
return addPlatform(program);

case 'remove':
return removePlatform(program);

case 'list':
return listPlatforms(program);

default:
return Q.reject(new Error('Unknown option \'' + command + '\' specified.'));
}
}

module.exports = platformCommands;


21 changes: 21 additions & 0 deletions commands/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

var Q = require('q');

var lib = require('manifoldjs-lib');

var log = lib.log,
projectBuilder = lib.projectBuilder;

function runApp (program) {

if (program.args.length < 2) {
return Q.reject(new Error('You must specify a platform.'));
}

var platform = program.args[1];
var projectDir = program.args.length < 3 ? process.cwd() : program.args[2];
return projectBuilder.runApp(platform, projectDir, program);
}

module.exports = runApp;
61 changes: 61 additions & 0 deletions commands/visualstudio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

var Q = require('q');

var lib = require('manifoldjs-lib');

var CustomError = lib.CustomError,
exec = lib.processTools.exec,
fileTools = lib.fileTools,
log = lib.log;

var open = require('./open');

function isWindows10Version (version) {
return /^10/.test(version);
}

function getWindowsVersion (callback) {
log.debug('Obtaining Windows version...');
exec('powershell', ['(Get-WmiObject win32_operatingsystem).version']).then(function (result) {
return result.stdout.trim();
})
.catch (function (err) {
return Q.reject(new CustomError('Failed to run the app for Windows platform.', err));
})
.nodeify(callback);
}

// implements the original behavior of the visualstudio command
// open windows10 project, if available, otherwise, open the windows project
function runApp(program) {

log.warn('The \'visualstudio\' command is deprecated. Use \'manifoldjs open <windows|windows10>\' instead.');

var deferred = Q.defer();

var dir = process.cwd();
fileTools.searchFile(dir, 'App.jsproj', function (err, results) {
Q.ninvoke(getWindowsVersion).then(function (version) {
if (results && results.length > 0 && isWindows10Version(version)) {
program.args.push('windows10');
return open(program).then(function () {
deferred.resolve();
});
}

fileTools.searchFile(dir, 'CordovaApp.sln', function (err, results) {
if (results && results.length > 0) {
program.args.push('windows');
return open(program).then(function () {
deferred.resolve();
});
}
});
});
});

return deferred.promise;
}

module.exports = runApp;
Loading

0 comments on commit b013753

Please sign in to comment.