Skip to content

Commit

Permalink
Merge pull request #50 from AthennaIO/develop
Browse files Browse the repository at this point in the history
fix(templates): adjust regex
  • Loading branch information
jlenon7 authored Sep 5, 2022
2 parents 43954d5 + a504527 commit b63d5ac
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/artisan",
"version": "1.4.3",
"version": "1.4.4",
"description": "The Athenna CLI application. Built on top of commander.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Eslint/Fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export class MakeFix extends Command {
this.title(`LINTING ${options.resource}\n`, 'bold', 'green')
}

const { name } = parse(filePath)

await this.execCommand(`${Path.bin('eslint')} ${filePath} --fix --quiet`)

if (!options.quiet) {
const { name } = parse(filePath)

this.success(
`${options.resource} ({yellow} "${name}") successfully linted.`,
)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Make/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class MakeProvider extends Command {

await FilePropertiesHelper.addContentToArrayProperty(
path,
'providers:',
'providers: ',
`import('#providers/${name}')`,
)

Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/FilePropertiesHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class FilePropertiesHelper {
`(?:${matcher.replace(
' ',
'\\s*',
)}\\s*)\\[(?:[^][]+|\\[(?:[^][]+|\\[[^][]*\\])*\\])*\\]`,
)}\\s*)\\[(?:[^\\]\\[]+|\\[(?:[^\\]\\[]+|\\[[^\\]\\[]*\\])*\\])*\\]`,
),
)

Expand Down Expand Up @@ -191,7 +191,7 @@ export class FilePropertiesHelper {

const matches = fileContent.match(
new RegExp(
`(?:${getMethod})\\[(?:[^][]+|\\[(?:[^][]+|\\[[^][]*\\])*\\])*\\]`,
`(?:${getMethod})\\[(?:[^\\]\\[]+|\\[(?:[^\\]\\[]+|\\[[^\\]\\[]*\\])*\\])*\\]`,
),
)

Expand Down
40 changes: 31 additions & 9 deletions tests/Stubs/replaceFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,30 @@ export class ReplaceFile {
* @return {any[]}
*/
get commands() {
const internalCommands = []
const internalCommands = [
'dasdada',
'dsadsad',
'dsadsaa',
'dswesas',
'ewqasdw',
'aqwerfs',
'dswpoik',
'lklopls',
'ieumjhg',
]

if (process.env.NODE_ENV !== 'production') {
internalCommands.push(
...ArtisanLoader.loadCommands(),
'oi',
'zap',
'truc',
'dale',
'vtnc',
'zsadsadasdasdas',
'dsaldksaldksaldkasld',
'dasdada',
'dsadsad',
'dsadsaa',
'dswesas',
'ewqasdw',
'aqwerfs',
'dswpoik',
'lklopls',
'ieumjhg',
)
}

Expand All @@ -44,7 +56,17 @@ export class ReplaceFile {
* @return {any[]}
*/
get object() {
const object = {}
const object = {
dasdada: 'dasdada',
dsadsad: 'dsadsad',
dsadsaa: 'dsadsaa',
dswesas: 'dswesas',
ewqasdw: 'ewqasdw',
aqwerfs: 'aqwerfs',
dswpoik: 'dswpoik',
lklopls: 'lklopls',
ieumjhg: 'ieumjhg',
}

return object
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Commands/Make/ProviderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ test.group('MakeProviderTest', group => {
}).timeout(60000)

test('should be able to create a provider file and register it inside config/app', async ({ assert }) => {
const oldKernelLength = new File(Path.config('app.js')).getContentSync().toString().length
const oldAppConfigLength = new File(Path.config('app.js')).getContentSync().toString().length

await Artisan.call('make:provider RegisterProvider')

const newKernelLength = new File(Path.config('app.js')).getContentSync().toString().length
const newAppConfigLength = new File(Path.config('app.js')).getContentSync().toString().length

assert.notEqual(newKernelLength, oldKernelLength)
assert.notEqual(newAppConfigLength, oldAppConfigLength)
}).timeout(60000)

test('should throw an error when the file already exists', async ({ assert }) => {
Expand Down
14 changes: 11 additions & 3 deletions tests/Unit/Helpers/FilePropertiesHelperTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test.group('FilePropertiesHelperTest', group => {

assert.isTrue(
content.includes(
"internalCommands.push(...ArtisanLoader.loadCommands,'oi','zap','truc','dale','vtnc','zsadsadasdasdas','dsaldksaldksaldkasld','hello')",
"internalCommands.push(...ArtisanLoader.loadCommands,'dasdada','dsadsad','dsadsaa','dswesas','ewqasdw','aqwerfs','dswpoik','lklopls','ieumjhg','hello')",
),
)
})
Expand All @@ -45,7 +45,11 @@ test.group('FilePropertiesHelperTest', group => {

const content = file.getContentSync().toString()

assert.isTrue(content.includes("const internalCommands = ['hello'"))
assert.isTrue(
content.includes(
"const internalCommands = ['dasdada','dsadsad','dsadsaa','dswesas','ewqasdw','aqwerfs','dswpoik','lklopls','ieumjhg','hello']",
),
)
})

test('should be able to add content to object properties in files', async ({ assert }) => {
Expand All @@ -57,7 +61,11 @@ test.group('FilePropertiesHelperTest', group => {

const content = file.getContentSync().toString()

assert.isTrue(content.includes("const object = {nice: 'hello'}"))
assert.isTrue(
content.includes(
"const object = {dasdada:'dasdada',dsadsad:'dsadsad',dsadsaa:'dsadsaa',dswesas:'dswesas',ewqasdw:'ewqasdw',aqwerfs:'aqwerfs',dswpoik:'dswpoik',lklopls:'lklopls',ieumjhg:'ieumjhg',nice: 'hello'}",
),
)
})

test('should be able to add content to array getter in files', async ({ assert }) => {
Expand Down

0 comments on commit b63d5ac

Please sign in to comment.