@anu8151/adonisjs-blueprint 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/generators/factory_generator.js +4 -1
- package/build/src/generators/migration_generator.js +5 -2
- package/build/src/generators/model_generator.js +3 -1
- package/build/src/generators/validator_generator.js +3 -1
- package/build/stubs/make/factory/main.stub +3 -11
- package/build/stubs/make/migration/main.stub +1 -3
- package/build/stubs/make/model/main.stub +1 -1
- package/build/stubs/make/validator/main.stub +2 -6
- package/package.json +1 -1
- package/stubs/make/factory/main.stub +3 -11
- package/stubs/make/migration/main.stub +1 -3
- package/stubs/make/model/main.stub +1 -1
- package/stubs/make/validator/main.stub +2 -6
|
@@ -42,7 +42,10 @@ var FactoryGenerator = class extends BaseGenerator {
|
|
|
42
42
|
entity,
|
|
43
43
|
attributes,
|
|
44
44
|
relationships,
|
|
45
|
-
factoryImports: Array.from(factoryImports)
|
|
45
|
+
factoryImports: Array.from(factoryImports),
|
|
46
|
+
imports: Array.from(factoryImports).map((f) => `import { ${f} } from './${f.replace("Factory", "").toLowerCase()}_factory'`).join("\n"),
|
|
47
|
+
attributesLines: attributes.map((a) => `${a.name}: faker.${a.fakerMethod}()`).join(",\n "),
|
|
48
|
+
relationsLines: relationships.filter((r) => r.type === "hasMany" || r.type === "belongsToMany").map((r) => `.relation('${r.name}', () => ${r.model}Factory)`).join("\n ")
|
|
46
49
|
});
|
|
47
50
|
}
|
|
48
51
|
};
|
|
@@ -23,7 +23,8 @@ var MigrationGenerator = class extends BaseGenerator {
|
|
|
23
23
|
...entity,
|
|
24
24
|
tableName: string.plural(string.snakeCase(entity.name))
|
|
25
25
|
},
|
|
26
|
-
attributes
|
|
26
|
+
attributes,
|
|
27
|
+
attributesLines: attributes.map((a) => a.migrationLine).join("\n ")
|
|
27
28
|
});
|
|
28
29
|
if (definition.relationships) {
|
|
29
30
|
for (const [relName, relType] of Object.entries(definition.relationships)) if (relType === "belongsToMany") await this.generatePivotMigration(entity.name, relName);
|
|
@@ -33,12 +34,14 @@ var MigrationGenerator = class extends BaseGenerator {
|
|
|
33
34
|
const models = [string.snakeCase(modelA), string.snakeCase(modelB)].sort();
|
|
34
35
|
const tableName = `${models[0]}_${models[1]}`;
|
|
35
36
|
const entity = this.app.generators.createEntity(tableName);
|
|
37
|
+
const pivotAttributes = [`table.integer('${models[0]}_id').unsigned().references('id').inTable('${string.plural(models[0])}').onDelete('CASCADE')`, `table.integer('${models[1]}_id').unsigned().references('id').inTable('${string.plural(models[1])}').onDelete('CASCADE')`];
|
|
36
38
|
await this.generateStub("make/migration/main.stub", {
|
|
37
39
|
entity: {
|
|
38
40
|
...entity,
|
|
39
41
|
tableName
|
|
40
42
|
},
|
|
41
|
-
attributes:
|
|
43
|
+
attributes: pivotAttributes.map((a) => ({ migrationLine: a })),
|
|
44
|
+
attributesLines: pivotAttributes.join("\n ")
|
|
42
45
|
});
|
|
43
46
|
}
|
|
44
47
|
};
|
|
@@ -46,7 +46,9 @@ var ModelGenerator = class extends BaseGenerator {
|
|
|
46
46
|
if (!processedAttributes.has("updatedAt")) attributes.push({ line: "@column.dateTime({ autoCreate: true, autoUpdate: true })\ndeclare updatedAt: DateTime" });
|
|
47
47
|
await this.generateStub("make/model/main.stub", {
|
|
48
48
|
entity,
|
|
49
|
-
attributes
|
|
49
|
+
attributes,
|
|
50
|
+
attributesLines: attributes.map((a) => a.line).join("\n\n "),
|
|
51
|
+
relationships,
|
|
50
52
|
relationshipsImports: relationships.map((r) => r.importLine).join("\n"),
|
|
51
53
|
relationshipsLines: relationships.map((r) => r.line).join("\n\n "),
|
|
52
54
|
modelImports,
|
|
@@ -62,7 +62,9 @@ var ValidatorGenerator = class extends BaseGenerator {
|
|
|
62
62
|
}
|
|
63
63
|
await this.generateStub("make/validator/main.stub", {
|
|
64
64
|
entity,
|
|
65
|
-
attributes
|
|
65
|
+
attributes,
|
|
66
|
+
createSchema: attributes.map((a) => `${a.name}: vine.${a.vineType}`).join(",\n "),
|
|
67
|
+
updateSchema: attributes.map((a) => `${a.name}: vine.${a.vineType}${a.vineType.includes(".optional()") ? "" : ".optional()"}`).join(",\n ")
|
|
66
68
|
}, definition.stub);
|
|
67
69
|
}
|
|
68
70
|
};
|
|
@@ -5,21 +5,13 @@
|
|
|
5
5
|
}}}
|
|
6
6
|
import {{ entity.className }} from '#models/{{ entity.name.toLowerCase() }}'
|
|
7
7
|
import Factory from '@adonisjs/lucid/factories'
|
|
8
|
-
|
|
9
|
-
import { {{ factory }} } from './{{ factory.replace('Factory', '').toLowerCase() }}_factory'
|
|
10
|
-
@end
|
|
8
|
+
{{{ imports }}}
|
|
11
9
|
|
|
12
10
|
export const {{ entity.className }}Factory = Factory
|
|
13
11
|
.define({{ entity.className }}, ({ faker }) => {
|
|
14
12
|
return {
|
|
15
|
-
|
|
16
|
-
{{ attribute.name }}: faker.{{ attribute.fakerMethod }}(),
|
|
17
|
-
@end
|
|
13
|
+
{{{ attributesLines }}}
|
|
18
14
|
}
|
|
19
15
|
})
|
|
20
|
-
|
|
21
|
-
@if(rel.type === 'hasMany' || rel.type === 'belongsToMany')
|
|
22
|
-
.relation('{{ rel.name }}', () => {{ rel.model }}Factory)
|
|
23
|
-
@end
|
|
24
|
-
@end
|
|
16
|
+
{{{ relationsLines }}}
|
|
25
17
|
.build()
|
|
@@ -11,9 +11,7 @@ export default class extends BaseSchema {
|
|
|
11
11
|
async up() {
|
|
12
12
|
this.schema.createTable(this.tableName, (table) => {
|
|
13
13
|
table.increments('id').primary()
|
|
14
|
-
|
|
15
|
-
{{ attribute.migrationLine }}
|
|
16
|
-
@end
|
|
14
|
+
{{{ attributesLines }}}
|
|
17
15
|
table.timestamp('created_at')
|
|
18
16
|
table.timestamp('updated_at')
|
|
19
17
|
})
|
|
@@ -7,16 +7,12 @@ import vine from '@vinejs/vine'
|
|
|
7
7
|
|
|
8
8
|
export const create{{ entity.className }}Validator = vine.compile(
|
|
9
9
|
vine.object({
|
|
10
|
-
|
|
11
|
-
{{ attribute.name }}: vine.{{ attribute.vineType }}(),
|
|
12
|
-
@end
|
|
10
|
+
{{{ createSchema }}}
|
|
13
11
|
})
|
|
14
12
|
)
|
|
15
13
|
|
|
16
14
|
export const update{{ entity.className }}Validator = vine.compile(
|
|
17
15
|
vine.object({
|
|
18
|
-
|
|
19
|
-
{{ attribute.name }}: vine.{{ attribute.vineType }}().optional(),
|
|
20
|
-
@end
|
|
16
|
+
{{{ updateSchema }}}
|
|
21
17
|
})
|
|
22
18
|
)
|
package/package.json
CHANGED
|
@@ -5,21 +5,13 @@
|
|
|
5
5
|
}}}
|
|
6
6
|
import {{ entity.className }} from '#models/{{ entity.name.toLowerCase() }}'
|
|
7
7
|
import Factory from '@adonisjs/lucid/factories'
|
|
8
|
-
|
|
9
|
-
import { {{ factory }} } from './{{ factory.replace('Factory', '').toLowerCase() }}_factory'
|
|
10
|
-
@end
|
|
8
|
+
{{{ imports }}}
|
|
11
9
|
|
|
12
10
|
export const {{ entity.className }}Factory = Factory
|
|
13
11
|
.define({{ entity.className }}, ({ faker }) => {
|
|
14
12
|
return {
|
|
15
|
-
|
|
16
|
-
{{ attribute.name }}: faker.{{ attribute.fakerMethod }}(),
|
|
17
|
-
@end
|
|
13
|
+
{{{ attributesLines }}}
|
|
18
14
|
}
|
|
19
15
|
})
|
|
20
|
-
|
|
21
|
-
@if(rel.type === 'hasMany' || rel.type === 'belongsToMany')
|
|
22
|
-
.relation('{{ rel.name }}', () => {{ rel.model }}Factory)
|
|
23
|
-
@end
|
|
24
|
-
@end
|
|
16
|
+
{{{ relationsLines }}}
|
|
25
17
|
.build()
|
|
@@ -11,9 +11,7 @@ export default class extends BaseSchema {
|
|
|
11
11
|
async up() {
|
|
12
12
|
this.schema.createTable(this.tableName, (table) => {
|
|
13
13
|
table.increments('id').primary()
|
|
14
|
-
|
|
15
|
-
{{ attribute.migrationLine }}
|
|
16
|
-
@end
|
|
14
|
+
{{{ attributesLines }}}
|
|
17
15
|
table.timestamp('created_at')
|
|
18
16
|
table.timestamp('updated_at')
|
|
19
17
|
})
|
|
@@ -7,16 +7,12 @@ import vine from '@vinejs/vine'
|
|
|
7
7
|
|
|
8
8
|
export const create{{ entity.className }}Validator = vine.compile(
|
|
9
9
|
vine.object({
|
|
10
|
-
|
|
11
|
-
{{ attribute.name }}: vine.{{ attribute.vineType }}(),
|
|
12
|
-
@end
|
|
10
|
+
{{{ createSchema }}}
|
|
13
11
|
})
|
|
14
12
|
)
|
|
15
13
|
|
|
16
14
|
export const update{{ entity.className }}Validator = vine.compile(
|
|
17
15
|
vine.object({
|
|
18
|
-
|
|
19
|
-
{{ attribute.name }}: vine.{{ attribute.vineType }}().optional(),
|
|
20
|
-
@end
|
|
16
|
+
{{{ updateSchema }}}
|
|
21
17
|
})
|
|
22
18
|
)
|