Skip to content

Commit e9f653a

Browse files
sytolkjosefaidtkatiekleintimngyn
authored
Add platform independent sample script for headless init (aws-amplify#3895)
* Add platform independent script for headless init * rename to amplify-headless-init-payload.json * Update src/pages/cli/usage/headless.mdx Co-authored-by: josef <[email protected]> * Update src/pages/cli/usage/headless.mdx Co-authored-by: josef <[email protected]> * commit to re-trigger checks * Update src/pages/cli/usage/headless.mdx * Add newline after meta object --------- Co-authored-by: josef <[email protected]> Co-authored-by: Katie Goines <[email protected]> Co-authored-by: Tim Nguyen <[email protected]>
1 parent 08a4676 commit e9f653a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/pages/cli/usage/headless.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,54 @@ Installs, initializes, and provisions resources for a sample amplify project fro
173173
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.
174174
175175
### Sample script
176+
```javascript
177+
const shell = require('shelljs');
178+
const amplify = require('./amplify-headless-init-payload.json');
179+
const cmd =
180+
'amplify init --amplify "' +
181+
JSON.stringify(amplify.amplify).replaceAll('"', '\\"') +
182+
'" --frontend "' +
183+
JSON.stringify(amplify.frontend).replaceAll('"', '\\"') +
184+
'" --providers "' +
185+
JSON.stringify(amplify.providers).replaceAll('"', '\\"') +
186+
'" --yes';
187+
188+
if (shell.exec(cmd).code !== 0) {
189+
shell.echo('Error amplify init');
190+
shell.exit(1);
191+
}
192+
```
193+
194+
amplify-headless-init-payload.json content
195+
```json
196+
{
197+
"amplify": {
198+
"projectName": "headlessProjectName",
199+
"envName": "myenvname",
200+
"defaultEditor": "code"
201+
},
202+
"frontend": {
203+
"frontend": "javascript",
204+
"framework": "react",
205+
"config": {
206+
"SourceDir": "src",
207+
"DistributionDir": "build",
208+
"BuildCommand": "npm run-script build",
209+
"StartCommand": "npm run-script start"
210+
}
211+
},
212+
"providers": {
213+
"awscloudformation": {
214+
"configLevel": "project",
215+
"useProfile": false,
216+
"profileName": "default"
217+
}
218+
}
219+
}
220+
221+
```
222+
223+
#### Sample bash script for Unix platform
176224
177225
```bash
178226
#!/bin/bash

0 commit comments

Comments
 (0)