Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 0 additions & 14 deletions .eslintrc.json

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ node_modules
/test-results.xml
coverage/
junit.xml
package-lock.json
package-lock.json
.claude
27 changes: 27 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2022 Adobe Inc. 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 aioLibConfig = require('@adobe/eslint-config-aio-lib-config')
const jestPlugin = require('eslint-plugin-jest')

module.exports = [
...aioLibConfig,
{
files: ['test/**/*.js', 'jest.setup.js'],
...jestPlugin.configs['flat/recommended']
},
{
rules: {
'jsdoc/no-defaults': 'off'
}
}
]
22 changes: 8 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
"@adobe/aio-lib-env": "^3",
"@adobe/aio-lib-ims": "^7",
"@adobe/aio-lib-templates": "^3",
"@oclif/core": "^1.9.3",
"@oclif/core": "^4.9.0",
"chalk": "^4.1.2",
"cli-table3": "^0.6.5",
"execa": "^4.1.0",
"fs-extra": "^10.1.0",
"inquirer": "^8.2.4",
Expand All @@ -26,24 +27,17 @@
"yeoman-environment": "^4.2.1"
},
"devDependencies": {
"@adobe/eslint-config-aio-lib-config": "^4.0.0",
"@adobe/eslint-config-aio-lib-config": "5.0.0",
"@types/jest": "^28.1.5",
"acorn": "^7",
"cross-env": "^7.0.3",
"eol": "^0.9.1",
"eslint": "^8.57.1",
"eslint-config-oclif": "^3.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^27.9.0",
"eslint": "^9",
"eslint-plugin-jest": "^29",
"eslint-plugin-jsdoc": "^48.11.0",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.6.0",
"eslint-plugin-standard": "^4.0.1",
"jest": "^29.7.0",
"jest-junit": "^6.0.0",
"jest-resolve": "^24.5.0",
"neostandard": "^0",
"oclif": "^4.3.6",
"stdout-stderr": "^0.1.9"
},
Expand Down Expand Up @@ -72,8 +66,8 @@
"prepack": "oclif manifest && oclif readme --no-aliases",
"postpack": "rm -f oclif.manifest.json",
"version": "oclif readme && git add README.md",
"lint:check": "eslint --ext .js .",
"lint:fix": "eslint --ext .js --fix ."
"lint:check": "eslint .",
"lint:fix": "eslint --fix ."
},
"jest": {
"rootDir": ".",
Expand Down
2 changes: 1 addition & 1 deletion src/BaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ BaseCommand.flags = {
verbose: Flags.boolean({ char: 'v', description: 'Verbose output' })
}

BaseCommand.args = []
BaseCommand.args = {}

module.exports = BaseCommand
36 changes: 14 additions & 22 deletions src/commands/templates/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

const BaseCommand = require('../../BaseCommand')
const ora = require('ora')
const { Flags, CliUx: { ux: cli } } = require('@oclif/core')
const { Flags } = require('@oclif/core')
const Table = require('cli-table3')
const inquirer = require('inquirer')
const { TEMPLATE_PACKAGE_JSON_KEY, readPackageJson } = require('../../lib/npm-helper')
const { getTemplates } = require('../../lib/template-registry-helper')
Expand Down Expand Up @@ -91,28 +92,19 @@ class DiscoverCommand extends BaseCommand {
day: 'numeric'
}

const columns = {
name: {
width: 10,
get: row => `${row.name}`
},
version: {
minWidth: 10,
get: row => `${row.latestVersion}`
},
description: {
get: row => `${row.description}`
},
publishDate: {
header: 'Publish Date',
get: row => `${new Date(row.publishDate).toLocaleDateString('en', options)}`
},
adobeRecommended: {
header: 'Adobe Recommended',
get: row => row.adobeRecommended ? 'yes' : ''
}
const table = new Table({
head: ['Name', 'Version', 'Description', 'Publish Date', 'Adobe Recommended']
})
for (const row of templates) {
table.push([
row.name,
row.latestVersion,
row.description,
new Date(row.publishDate).toLocaleDateString('en', options),
row.adobeRecommended ? 'yes' : ''
])
}
cli.table(templates, columns)
this.log(table.toString())
}

async run () {
Expand Down
12 changes: 5 additions & 7 deletions src/commands/templates/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { writeObjectToPackageJson, readPackageJson, getNpmDependency, processNpmP
const { getTemplateRequiredServiceNames } = require('../../lib/template-helper')
const ora = require('ora')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app-templates:templates:install', { provider: 'debug' })
const { Flags } = require('@oclif/core')
const { Args, Flags } = require('@oclif/core')

// aio-lib-console-project-installation dependencies
const path = require('path')
Expand Down Expand Up @@ -45,7 +45,6 @@ class InstallCommand extends BaseCommand {
}
aioLogger.debug(`templateName: ${templateName}`)

// eslint-disable-next-line node/no-unsupported-features/es-syntax
const yeoman = await import('yeoman-environment')
const env = yeoman.createEnv()
env.options = { skipInstall: !flags.install }
Expand Down Expand Up @@ -144,13 +143,12 @@ InstallCommand.examples = [

InstallCommand.aliases = ['templates:i']

InstallCommand.args = [
{
name: 'path',
InstallCommand.args = {
path: Args.string({
description: 'path to the template (npm package name, file path, url). See examples',
required: true
}
]
})
}

InstallCommand.flags = {
...BaseCommand.flags,
Expand Down
10 changes: 5 additions & 5 deletions src/commands/templates/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* governing permissions and limitations under the License.
*/

const { Args } = require('@oclif/core')
const BaseCommand = require('../../BaseCommand')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app-templates:templates:remove', { provider: 'debug' })
const { removeTemplate } = require('../../lib/template-registry-helper')
Expand Down Expand Up @@ -37,13 +38,12 @@ RemoveCommand.examples = [

RemoveCommand.aliases = ['templates:rm']

RemoveCommand.args = [
{
name: 'name',
RemoveCommand.args = {
name: Args.string({
description: 'The name of the package implementing the template on npmjs.com',
required: true
}
]
})
}

RemoveCommand.flags = {
...BaseCommand.flags
Expand Down
20 changes: 8 additions & 12 deletions src/commands/templates/rollback.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* governing permissions and limitations under the License.
*/

const { Flags, CliUx: { ux: cli } } = require('@oclif/core')
const { Flags } = require('@oclif/core')
const Table = require('cli-table3')
const BaseCommand = require('../../BaseCommand')
const inquirer = require('inquirer')
const { prompt } = require('../../lib/helper')
Expand All @@ -24,18 +25,13 @@ class RollbackCommand extends BaseCommand {
* @param {Array<object>} templates the installed templates
*/
async __list (templates) {
const columns = {
template: {
width: 10,
get: row => `${row.name}`
},
version: {
minWidth: 10,
get: row => `${row.version}`
}
const table = new Table({
head: ['Template', 'Version']
})
for (const row of templates) {
table.push([row.name, row.version])
}

cli.table(templates, columns)
this.log(table.toString())
}

/**
Expand Down
15 changes: 7 additions & 8 deletions src/commands/templates/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* governing permissions and limitations under the License.
*/

const { Args } = require('@oclif/core')
const BaseCommand = require('../../BaseCommand')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app-templates:templates:submit', { provider: 'debug' })
const { addTemplate } = require('../../lib/template-registry-helper')
Expand Down Expand Up @@ -39,18 +40,16 @@ SubmitCommand.examples = [

SubmitCommand.aliases = ['templates:sub']

SubmitCommand.args = [
{
name: 'name',
SubmitCommand.args = {
name: Args.string({
description: 'The name of the package implementing the template on npmjs.com',
required: true
},
{
name: 'githubRepoUrl',
}),
githubRepoUrl: Args.string({
description: "A link to the Github repository containing the package's source code",
required: true
}
]
})
}

SubmitCommand.flags = {
...BaseCommand.flags
Expand Down
10 changes: 5 additions & 5 deletions src/commands/templates/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* governing permissions and limitations under the License.
*/

const { Args } = require('@oclif/core')
const BaseCommand = require('../../BaseCommand')
const { runScript } = require('../../lib/helper')
const { TEMPLATE_PACKAGE_JSON_KEY, writeObjectToPackageJson, readPackageJson } = require('../../lib/npm-helper')
Expand Down Expand Up @@ -43,13 +44,12 @@ UninstallCommand.description = 'Uninstall an Adobe Developer App Builder templat

UninstallCommand.aliases = ['templates:un']

UninstallCommand.args = [
{
name: 'package-name',
UninstallCommand.args = {
'package-name': Args.string({
description: 'package name of the template',
required: true
}
]
})
}

UninstallCommand.flags = {
...BaseCommand.flags
Expand Down
9 changes: 9 additions & 0 deletions test/BaseCommand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ test('login', async () => {
test('catch', async () => {
const cmd = new TheCommand([])
cmd.error = jest.fn()
cmd.config = {
runHook: jest.fn().mockResolvedValue({ successes: [], failures: [] })
}
await cmd.catch(new Error('fake error'))
expect(cmd.error).toHaveBeenCalledWith('fake error')
})

test('will change error message when aio templates outside of the application root, verbose', async () => {
const cmd = new TheCommand([])
cmd.error = jest.fn()
cmd.config = {
runHook: jest.fn().mockResolvedValue({ successes: [], failures: [] })
}
cmd.argv = ['-v']
const err = new Error('ENOENT: no such file or directory, open \'package.json\'')
err.stack = 'mock-stack-trace'
Expand All @@ -72,6 +78,9 @@ test('will change error message when aio templates outside of the application ro
test('will change error message when aio templates outside of the application root', async () => {
const cmd = new TheCommand([])
cmd.error = jest.fn()
cmd.config = {
runHook: jest.fn().mockResolvedValue({ successes: [], failures: [] })
}
const err = new Error('ENOENT: no such file or directory, open \'package.json\'')
await cmd.catch(err)
const errorList = [
Expand Down
11 changes: 6 additions & 5 deletions test/commands/templates/discover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ const fakeSupportedOrgServices = [{ code: 'StockSDK', properties: {} }, { code:
* @param {Array<string>} splitOutput output split into an array
*/
function testAllTemplatesAreRendered (splitOutput) {
expect(splitOutput[2]).toMatch('foo')
expect(splitOutput[3]).toMatch('bar')
expect(splitOutput[4]).toMatch('baz')
expect(splitOutput[3]).toMatch('foo')
expect(splitOutput[5]).toMatch('bar')
expect(splitOutput[7]).toMatch('baz')
}

let command
Expand All @@ -90,7 +90,8 @@ beforeEach(() => {
command = new TheCommand([])
command.error = jest.fn()
command.config = {
runCommand: jest.fn()
runCommand: jest.fn(),
runHook: jest.fn().mockResolvedValue({ successes: [], failures: [] })
}
command.login = jest.fn()
libEnv.getCliEnv.mockReset()
Expand Down Expand Up @@ -130,7 +131,7 @@ test('flags', async () => {
})

test('args', async () => {
expect(TheCommand.args).toEqual([])
expect(TheCommand.args).toEqual({})
})

describe('sorting', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/templates/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('flags', async () => {
})

test('args', async () => {
expect(TheCommand.args).toEqual([])
expect(TheCommand.args).toEqual({})
})

describe('instance methods', () => {
Expand Down
Loading
Loading