-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into category-auth/sig…
…n-in-with-apple
- Loading branch information
Showing
18 changed files
with
430 additions
and
24 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
18 changes: 18 additions & 0 deletions
18
packages/amplify-cli/src/__tests__/init-steps/s1-initFrontend.test.ts
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,18 @@ | ||
import { getSuitableFrontend } from '../../init-steps/s1-initFrontend'; | ||
|
||
describe('getSuitableFrontend', () => { | ||
it('supports headless inputs', () => { | ||
const context = { | ||
exeInfo: { | ||
inputParams: { | ||
amplify: { | ||
frontend: 'ios', | ||
}, | ||
}, | ||
}, | ||
} as any; | ||
const frontendPlugins = { ios: '' } as any; | ||
const result = getSuitableFrontend(context, frontendPlugins, ''); | ||
expect(result).toStrictEqual('ios'); | ||
}); | ||
}); |
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
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,71 @@ | ||
// | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). | ||
// You may not use this file except in compliance with the License. | ||
// A copy of the License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0 | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
// | ||
|
||
// ############################################################################ | ||
// Auto-generated file using `build` NPM script. Do not edit this file manually | ||
// ############################################################################ | ||
|
||
const execa = require('execa'); | ||
const path = require('path'); | ||
const { pathManager } = require('amplify-cli-core'); | ||
|
||
const BINARY_PATH = 'resources/amplify-xcode'; | ||
const PACKAGE_NAME = 'amplify-frontend-ios'; | ||
const amplifyXcodePath = () => path.join(pathManager.getAmplifyPackageLibDirPath(PACKAGE_NAME), BINARY_PATH); | ||
|
||
/** | ||
* Import Amplify configuration files | ||
* @param {Object} params | ||
* @param {String} params.path - Project base path | ||
*/ | ||
async function importConfig(params) { | ||
let command = `${amplifyXcodePath()} import-config`; | ||
if (params['path']) { | ||
command += ` --path=${params['path']}`; | ||
} | ||
await execa.command(command, { stdout: 'inherit' }); | ||
} | ||
|
||
/** | ||
* Import Amplify models | ||
* @param {Object} params | ||
* @param {String} params.path - Project base path | ||
*/ | ||
async function importModels(params) { | ||
let command = `${amplifyXcodePath()} import-models`; | ||
if (params['path']) { | ||
command += ` --path=${params['path']}`; | ||
} | ||
await execa.command(command, { stdout: 'inherit' }); | ||
} | ||
|
||
/** | ||
* Generates a JSON description of the CLI and its commands | ||
* @param {Object} params | ||
* @param {String} params.output-path - Path to save the output of generated schema file | ||
*/ | ||
async function generateSchema(params) { | ||
let command = `${amplifyXcodePath()} generate-schema`; | ||
if (params['output-path']) { | ||
command += ` --output-path=${params['output-path']}`; | ||
} | ||
await execa.command(command, { stdout: 'inherit' }); | ||
} | ||
|
||
module.exports = { | ||
importConfig, | ||
importModels, | ||
generateSchema, | ||
}; |
127 changes: 127 additions & 0 deletions
127
packages/amplify-frontend-ios/native-bindings-codegen/index.js
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,127 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const _ = require('lodash'); | ||
|
||
const CODEGEN_TEMPLATES_FOLDER = 'templates'; | ||
|
||
const canonicalFunctionName = commandName => _.camelCase(commandName); | ||
|
||
const getTemplate = templatName => { | ||
const templatePath = path.join(__dirname, CODEGEN_TEMPLATES_FOLDER, templatName); | ||
const template = fs.readFileSync(templatePath).toString(); | ||
return _.template(template, { interpolate: /<%=([\s\S]+?)%>/g }); | ||
}; | ||
|
||
/** | ||
* Generates function signature docs | ||
* @param {String} abstract | ||
* @param {Array<{name: String, type: String, help: String}>} parameters | ||
*/ | ||
const generateFunctionDocs = (abstract, parameters) => { | ||
return ` | ||
/** | ||
* ${abstract} | ||
* @param {Object} params | ||
${parameters.map(p => ` * @param {${p.type}} params.${p.name} - ${p.help}`).join('\n')} | ||
*/`; | ||
}; | ||
|
||
/** | ||
* Given a list of parameters of type `Parameter` generates | ||
* proper CLI call signature. | ||
* Parameter { | ||
* kind: option | flag | argument | ||
* name: string | ||
* type: string | ||
* help: string | ||
* } | ||
* @param {Array<{ | ||
* name: String, | ||
* kind:"option" | "flag" | "argument" | ||
* type: String, | ||
* help: String}>} parameters | ||
* @returns {Array<Array<String>>} | ||
*/ | ||
const generateCommandParameters = parameters => { | ||
return parameters.map(param => { | ||
const { kind, name } = param; | ||
const funcParamValue = `params['${name}']`; | ||
let output; | ||
switch (kind) { | ||
case 'option': | ||
output = [`if (${funcParamValue}) {`, ` command += \` --${name}=\${${funcParamValue}}\`;`, ` }`]; | ||
break; | ||
case 'flag': | ||
output = [`if (${funcParamValue}) {`, ` command += \` --${name}\`;`, ` }`]; | ||
break; | ||
case 'argument': | ||
output = [` command += \` \${${funcParamValue}}\`;`]; | ||
} | ||
return output; | ||
}); | ||
}; | ||
|
||
/** | ||
* Given a command schema generates data used in | ||
* template function declaration | ||
* @param {Object} commandSchema | ||
* @param {String} commandSchema.abstract | ||
* @param {String} commandSchema.name | ||
* @param {Array} commandSchema.parameters | ||
*/ | ||
const generateFunctionBodyData = commandSchema => { | ||
const { abstract, name, parameters } = commandSchema; | ||
return { | ||
__FUNCTION_DOCS__: generateFunctionDocs(abstract, parameters), | ||
__FUNCTION_NAME__: canonicalFunctionName(name), | ||
__COMMAND_NAME__: name, | ||
__COMMAND_PARAMS__: generateCommandParameters(parameters) | ||
.map(p => ` ${p.join('\n')}`) | ||
.join('\n'), | ||
}; | ||
}; | ||
|
||
/** | ||
* Given an `amplify-xcode` schema, generates the commonjs | ||
* exported module declaration | ||
* @param {Object} schema amplify-xcode schema @see amplify-xcode.json | ||
*/ | ||
const generateModuleExports = schema => { | ||
let output = ['module.exports = {']; | ||
schema.commands.forEach(command => { | ||
output.push(` ${canonicalFunctionName(command.name)},`); | ||
}); | ||
output.push('};'); | ||
|
||
return output; | ||
}; | ||
|
||
/** | ||
* Given an `amplify-xcode` schema, generates JS | ||
* bindings to safely call `amplify-xcode`. | ||
* @param {Object} schema amplify-xcode schema | ||
* @param {String} outputPath generated JS bindings file path | ||
*/ | ||
const generateNativeBindings = (schema, outputPath) => { | ||
const preamble = getTemplate('preamble.jst')(); | ||
const functionTemplate = getTemplate('function.jst'); | ||
// generate functions body | ||
let output = preamble; | ||
output += schema.commands | ||
.map(command => { | ||
return functionTemplate(generateFunctionBodyData(command)); | ||
}) | ||
.join(''); | ||
|
||
// generate exports | ||
output += '\n' + generateModuleExports(schema).join('\n') + '\n'; | ||
|
||
fs.writeFileSync(outputPath, output); | ||
}; | ||
|
||
module.exports = { | ||
generateCommandParameters, | ||
generateFunctionBodyData, | ||
generateModuleExports, | ||
generateNativeBindings, | ||
}; |
6 changes: 6 additions & 0 deletions
6
packages/amplify-frontend-ios/native-bindings-codegen/templates/function.jst
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,6 @@ | ||
<%= __FUNCTION_DOCS__ %> | ||
async function <%= __FUNCTION_NAME__ %>(params) { | ||
let command = `${amplifyXcodePath()} <%= __COMMAND_NAME__ %>`; | ||
<%=__COMMAND_PARAMS__ %> | ||
await execa.command(command, { stdout: 'inherit' }); | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/amplify-frontend-ios/native-bindings-codegen/templates/preamble.jst
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,26 @@ | ||
// | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). | ||
// You may not use this file except in compliance with the License. | ||
// A copy of the License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0 | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
// | ||
|
||
// ############################################################################ | ||
// Auto-generated file using `build` NPM script. Do not edit this file manually | ||
// ############################################################################ | ||
|
||
const execa = require('execa'); | ||
const path = require('path'); | ||
const { pathManager } = require('amplify-cli-core'); | ||
|
||
const BINARY_PATH = 'resources/amplify-xcode'; | ||
const PACKAGE_NAME = 'amplify-frontend-ios'; | ||
const amplifyXcodePath = () => path.join(pathManager.getAmplifyPackageLibDirPath(PACKAGE_NAME), BINARY_PATH); |
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
Binary file not shown.
Oops, something went wrong.