forked from adobe/generator-aio-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (74 loc) · 3.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const path = require('path')
const Generator = require('yeoman-generator')
const utils = require('../../../lib/utils')
const { webAssetsDirname, dotenvFilename } = require('../../../lib/constants')
const { sdkCodes } = require('../../../lib/constants')
class ExcReactGenerator extends Generator {
constructor (args, opts) {
super(args, opts)
// todo check that those are set
this.option('adobe-services', { type: String, default: '' })
this.option('project-name', { type: String })
// this.option('skip-prompt', { default: false }) // useless for now
this.option('skip-install', { type: Boolean, default: false })
this.option('has-backend', { type: Boolean, default: true })
// props are used by templates
this.props = {}
this.props.adobeServices = this.options['adobe-services'].split(',').map(x => x.trim())
this.props.projectName = this.options['project-name']
this.props.sdkCodes = sdkCodes
this.props.hasBackend = this.options['has-backend']
}
// nothing for now
// async prompting () {}
writing () {
this.sourceRoot(path.join(__dirname, './templates/'))
this.fs.copyTpl(this.templatePath('./**/*'), this.destinationPath(webAssetsDirname), this.props)
// add .babelrc
this.fs.writeJSON(this.destinationPath('.babelrc'), { presets: [['@babel/preset-env', { targets: { node: 'current' } }]] })
// add dependencies
utils.addDependencies(this, {
'core-js': '^3.6.4',
react: '^16.13.1',
'react-dom': '^16.13.1',
'react-error-boundary': '^1.2.5',
'regenerator-runtime': '^0.13.5',
'@adobe/exc-app': '^0.2.17',
'@react-spectrum/button': '3.0.0',
'@react-spectrum/form': '3.0.0',
'@react-spectrum/layout': '3.0.0',
'@react-spectrum/link': '3.0.0',
'@react-spectrum/picker': '3.0.0',
'@react-spectrum/progress': '3.0.0',
'@react-spectrum/provider': '3.0.0',
'@react-spectrum/text': '3.0.0',
'@react-spectrum/textfield': '3.0.0',
'@react-spectrum/theme-default': '3.0.0'
})
utils.addDependencies(this, {
'@babel/core': '^7.8.7',
'@babel/polyfill': '^7.8.7',
'@babel/preset-env': '^7.8.7'
}, true)
// add env variable to load ui in exc shell
utils.appendOrWrite(this, this.destinationPath(dotenvFilename),
`## URL prefix used to run your application in the Adobe Experience Cloud Shell
AIO_LAUNCH_URL_PREFIX="https://experience.adobe.com/?devMode=true#/custom-apps/?localDevUrl="
`, 'AIO_LAUNCH_URL_PREFIX')
}
async install () {
// this condition makes sure it doesn't print any unwanted 'skip install message'
if (!this.options['skip-install']) return this.installDependencies({ bower: false, skipMessage: true })
}
}
module.exports = ExcReactGenerator