Skip to content

Add platform independent sample script for headless init #3895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/pages/cli/usage/headless.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,54 @@ Installs, initializes, and provisions resources for a sample amplify application
If the repository contains a `yarn.lock` and/or `package.json` file, the sample will be installed with the corresponding package manager and started after resources have been provisioned.

### Sample script
```javascript
const shell = require('shelljs');
const amplify = require('./amplify-headless-init-payload.json');
const cmd =
'amplify init --amplify "' +
JSON.stringify(amplify.amplify).replaceAll('"', '\\"') +
'" --frontend "' +
JSON.stringify(amplify.frontend).replaceAll('"', '\\"') +
'" --providers "' +
JSON.stringify(amplify.providers).replaceAll('"', '\\"') +
'" --yes';

if (shell.exec(cmd).code !== 0) {
shell.echo('Error amplify init');
shell.exit(1);
}
```

amplify-headless-init-payload.json content
```json
{
"amplify": {
"projectName": "headlessProjectName",
"envName": "myenvname",
"defaultEditor": "code"
},
"frontend": {
"frontend": "javascript",
"framework": "react",
"config": {
"SourceDir": "src",
"DistributionDir": "build",
"BuildCommand": "npm run-script build",
"StartCommand": "npm run-script start"
}
},
"providers": {
"awscloudformation": {
"configLevel": "project",
"useProfile": false,
"profileName": "default"
}
}
}

```

#### Sample bash script for Unix platform

```bash
#!/bin/bash
Expand Down