UNPKG

manifoldjs-chrome

Version:
70 lines (55 loc) 2.5 kB
'use strict'; var path = require('path'), util = require('util'), Q = require('q'); var manifoldjsLib = require('manifoldjs-lib'); var CustomError = manifoldjsLib.CustomError, PlatformBase = manifoldjsLib.PlatformBase, manifestTools = manifoldjsLib.manifestTools, fileTools = manifoldjsLib.fileTools; var constants = require('./constants'), manifest = require('./manifest'); function Platform (packageName, platforms) { var self = this; PlatformBase.call(this, constants.platform.id, constants.platform.name, packageName, __dirname); // save platform list self.platforms = platforms; // override create function self.create = function (w3cManifestInfo, rootDir, options, callback) { if (w3cManifestInfo.format !== manifoldjsLib.constants.BASE_MANIFEST_FORMAT) { return Q.reject(new CustomError('The \'' + w3cManifestInfo.format + '\' manifest format is not valid for this platform.')); } self.info('Generating the ' + constants.platform.name + ' app...'); var platformDir = path.join(rootDir, constants.platform.id); // convert the W3C manifest to a platform-specific manifest var platformManifestInfo; return manifest.convertFromBase(w3cManifestInfo) // if the platform dir doesn't exist, create it .then(function (manifestInfo) { platformManifestInfo = manifestInfo; self.debug('Creating the ' + constants.platform.name + ' app folder...'); return fileTools.mkdirp(platformDir); }) // download icons to the app's folder .then(function () { return self.downloadIcons(platformManifestInfo.content, w3cManifestInfo.content.start_url, platformDir); }) // copy the documentation .then(function () { return self.copyDocumentation(platformDir); }) // write generation info (telemetry) .then(function () { return self.writeGenerationInfo(w3cManifestInfo, platformDir); }) // persist the platform-specific manifest .then(function () { self.debug('Copying the ' + constants.platform.name + ' manifest to the app folder...'); var manifestFilePath = path.join(platformDir, 'manifest.json'); return manifestTools.writeToFile(platformManifestInfo, manifestFilePath); }) .nodeify(callback); }; } util.inherits(Platform, PlatformBase); module.exports = Platform;