Skip to content

Commit

Permalink
refactor and support for delete
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzraho committed Dec 17, 2019
1 parent 60b46cf commit 84a881c
Show file tree
Hide file tree
Showing 25 changed files with 384 additions and 132 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ A Yeoman code generator for Adobe I/O Applications.
- `aio app init` to bootstrap your project's code
- `aio app add actions` to add new actions to an existing app
- `aio app add web-assets` to add a UI to an existing app
- `aio app delete action` to delete an existing action
- `aio app delete web-assets` to delete the app's UI

## Standalone Usage

- `npm install -g yo @adobe/generator-aio-app`

- `yo aio-app` to bootstrap your project's code
- `yo aio-app --mode add-actions` to add new actions to an existing app
- `yo aio-app --mode add-web-assets` to add a UI to an existing app
- `yo aio-app:add-actions` to add new actions to an existing app
- `yo aio-app:add-web-assets` to add a UI to an existing app
- `yo aio-app:delete-action` to delete an existing action
- `yo aio-app:add-web-assets` to delete the app's UI

## Contributing

Expand Down
File renamed without changes.
File renamed without changes.
100 changes: 100 additions & 0 deletions generators/add-actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
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 { actionsDirname } = require('../../lib/constants')

// we have one actions generator per service, an action generator could generate different types of actions
// todo use real sdkCodes from console
const sdkCodeToActionGenerator = {
target: path.join(__dirname, 'target/index.js'),
analytics: path.join(__dirname, 'analytics/index.js'),
campaign: path.join(__dirname, 'campaign-standard/index.js')
}

const sdkCodeToTitle = {
target: 'Adobe Target',
analytics: 'Adobe Analytics',
campaign: 'Adobe Campaign Standard'
}

const genericActionGenerator = path.join(__dirname, 'generic/index.js')

/*
'initializing',
'prompting',
'configuring',
'default',
'writing',
'conflicts',
'install',
'end'
*/

class AddActions extends Generator {
constructor (args, opts) {
super(args, opts)

// options are inputs from CLI or yeoman parent generator
this.option('skip-prompt', { default: false })
this.option('adobe-services', { type: String, default: 'target,analytics,campaign' }) // todo use real sdkCodes from console

this.option('project-name', { type: String, default: path.basename(process.cwd()) }) // todo get name from console

// todo throw meaningful error if add actions in a non existing project, but what defines a project?
}

async prompting () {
const atLeastOne = input => {
if (input.length === 0) {
// eslint-disable-next-line no-throw-literal
return 'please choose at least one option'
}
return true
}
const prompts = [
{
type: 'checkbox',
name: 'actionGenerators',
message: 'Which type of sample actions do you want to create?\nselect type of actions to generate',
choices: [{ type: 'separator', line: '--service specific--' }]
.concat(
this.options['adobe-services'].split(',').map(x => x.trim())
.map(s => ({ name: sdkCodeToTitle[s], value: sdkCodeToActionGenerator[s] }))
.filter(entry => !!entry.value)
.concat([
{ type: 'separator', line: '--others--' },
{ name: 'Generic', value: genericActionGenerator, checked: true }
])),
when: !this.options['skip-prompt'],
validate: atLeastOne
}
]
const promptProps = await this.prompt(prompts)
// defaults for when skip-prompt is set
promptProps.actionGenerators = promptProps.actionGenerators || [genericActionGenerator]

// run action generators
promptProps.actionGenerators.forEach(gen => this.composeWith(gen, {
'skip-prompt': this.options['skip-prompt'],
'actions-dir': actionsDirname
}))
}

async install () {
// this condition makes sure it doesn't print any unwanted 'skip install message' into parent generator
if (!this.options['skip-install']) return this.installDependencies({ bower: false })
}
}

module.exports = AddActions
File renamed without changes.
73 changes: 73 additions & 0 deletions generators/add-web-assets/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
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 { webAssetsDirname } = require('../../lib/constants')

const rawWebAssetsGenerator = path.join(__dirname, 'raw/index.js')

/*
'initializing',
'prompting',
'configuring',
'default',
'writing',
'conflicts',
'install',
'end'
*/

class AddWebAssets extends Generator {
constructor (args, opts) {
super(args, opts)

// options are inputs from CLI or yeoman parent generator
this.option('skip-prompt', { default: false })
this.option('adobe-services', { type: String, default: 'target,analytics,campaign' }) // todo use real sdkCodes from console

this.option('project-name', { type: String, default: path.basename(process.cwd()) }) // todo get name from console

// todo throw meaningful error if add actions/webassets in a non existing project, but how to know if we are in a project?
}

async prompting () {
const prompts = [
{
// for now we just have one webAsset generator
type: 'list',
name: 'webAssetsGenerator',
message: 'Which type of UI do you want to add to your project?\nselect template to generate',
choices: [{ name: 'Raw HTML/JS', value: rawWebAssetsGenerator }],
when: !this.options['skip-prompt']
}
]
const promptProps = await this.prompt(prompts)
// defaults for when skip-prompt is set
promptProps.webAssetsGenerator = promptProps.webAssetsGenerator || rawWebAssetsGenerator

// run ui generator
this.composeWith(promptProps.webAssetsGenerator, {
'skip-prompt': this.options['skip-prompt'],
'web-dir': webAssetsDirname,
'adobe-services': this.options['adobe-services'],
'project-name': this.options['project-name']
})
}

async install () {
// this condition makes sure it doesn't print any unwanted 'skip install message' into parent generator
if (!this.options['skip-install']) return this.installDependencies({ bower: false })
}
}

module.exports = AddWebAssets
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RawGenerator extends Generator {
this.option('web-dir', { type: String })
this.option('project-name', { type: String })
// this.option('skip-prompt', { default: false }) // useless for now

// props are used by templates
this.props = {}
this.props.adobeServices = this.options['adobe-services'].split(',').map(x => x.trim())
Expand Down
Loading

0 comments on commit 84a881c

Please sign in to comment.