-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,479 additions
and
504 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const fs = require('fs-extra'); | ||
const R = require('ramda'); | ||
const path = require('path'); | ||
|
||
const SkillMetadataController = require('@src/controllers/skill-metadata-controller'); | ||
const ResourcesConfig = require('@src/model/resources-config'); | ||
const CONSTANTS = require('@src/utils/constants'); | ||
|
||
module.exports = { | ||
createV2ProjectSkeleton, | ||
downloadSkillPackage, | ||
handleExistingLambdaCode | ||
}; | ||
|
||
/** | ||
* To create v2 project structure for an Alexa hosted skill project | ||
* @param {String} rootPath the root path | ||
* @param {String} skillId the skill id | ||
* @param {String} profile the profile | ||
*/ | ||
function createV2ProjectSkeleton(rootPath, skillId, profile) { | ||
// prepare skill package folder | ||
const skillPackagePath = path.join(rootPath, CONSTANTS.FILE_PATH.SKILL_PACKAGE.PACKAGE); | ||
fs.ensureDirSync(skillPackagePath); | ||
// prepare skill code folder | ||
const skillCodePath = path.join(rootPath, CONSTANTS.FILE_PATH.SKILL_CODE.LAMBDA); | ||
fs.ensureDirSync(skillCodePath); | ||
// prepare ask-resources config | ||
const askResourcesJson = R.clone(ResourcesConfig.BASE); | ||
askResourcesJson.profiles[profile] = { | ||
skillId | ||
}; | ||
const askResourcesFilePath = path.join(rootPath, CONSTANTS.FILE_PATH.ASK_RESOURCES_JSON_CONFIG); | ||
fs.writeJSONSync(askResourcesFilePath, askResourcesJson, { spaces: CONSTANTS.CONFIGURATION.JSON_DISPLAY_INDENT }); | ||
} | ||
|
||
/** | ||
* To download skill project for an Alexa hosted skill project | ||
* @param {String} rootPath the root path | ||
* @param {String} skillId the skill id | ||
* @param {String} skillStage the skill stage | ||
* @param {String} profile the profile | ||
* @param {Boolean} doDebug the debug flag | ||
* @param {callback} callback { err } | ||
*/ | ||
function downloadSkillPackage(rootPath, skillId, skillStage, profile, doDebug, callback) { | ||
const skillMetaController = new SkillMetadataController({ profile, doDebug }); | ||
skillMetaController.getSkillPackage(rootPath, skillId, skillStage, (packageErr) => { | ||
if (packageErr) { | ||
return callback(packageErr); | ||
} | ||
callback(); | ||
}); | ||
} | ||
|
||
/** | ||
* To handle existing lambda code and update ask-resources.js for an Alexa hosted skill project | ||
* @param {String} rootPath the root path | ||
* @param {Object} lambdaResourcesMap the lambda code resources from old project { profile: { arn, codeUri, handler, revisionId, runtime, v2CodeUri} } | ||
* @param {String} profile the profile | ||
*/ | ||
function handleExistingLambdaCode(rootPath, profile) { | ||
// 1.update skill infra type | ||
ResourcesConfig.getInstance().setSkillInfraType(profile, CONSTANTS.DEPLOYER_TYPE.HOSTED.NAME); | ||
// 2.copy Lambda code from legacy folder and set deployState for each region | ||
const legacyFolderPath = path.join(rootPath, CONSTANTS.FILE_PATH.LEGACY_PATH); | ||
// 3.1 copy code from v1 project to v2 | ||
const v1CodePath = path.join(legacyFolderPath, CONSTANTS.FILE_PATH.SKILL_CODE.LAMBDA); | ||
const v2CodePath = path.join(rootPath, CONSTANTS.FILE_PATH.SKILL_CODE.LAMBDA); | ||
fs.copySync(v1CodePath, v2CodePath); | ||
ResourcesConfig.getInstance().write(); | ||
} |
Oops, something went wrong.