ember-tribe 2.3.0 → 2.3.1
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/blueprints/ember-tribe/files/.env.sample +1 -1
- package/blueprints/ember-tribe/files/app/adapters/application.js +4 -1
- package/blueprints/ember-tribe/files/app/routes/application.js +0 -2
- package/blueprints/ember-tribe/files/app/services/types.js +18 -0
- package/config/environment.js +2 -3
- package/package.json +1 -1
- package/blueprints/ember-tribe/files/sync-types.php +0 -23
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
TRIBE_API_URL=""
|
|
2
|
-
|
|
2
|
+
TRIBE_API_KEY=""
|
|
@@ -5,8 +5,11 @@ import { underscore } from '@ember/string';
|
|
|
5
5
|
export default class ApplicationAdapter extends JSONAPIAdapter {
|
|
6
6
|
host = ENV.TribeENV.API_URL;
|
|
7
7
|
namespace = 'api.php';
|
|
8
|
+
headers = {
|
|
9
|
+
Authorization: `Bearer ${ENV.TribeENV.API_KEY}`,
|
|
10
|
+
};
|
|
8
11
|
|
|
9
12
|
pathForType(type) {
|
|
10
13
|
return underscore(type);
|
|
11
14
|
}
|
|
12
|
-
}
|
|
15
|
+
}
|
|
@@ -2,6 +2,8 @@ import Service from '@ember/service';
|
|
|
2
2
|
import { service } from '@ember/service';
|
|
3
3
|
import { action } from '@ember/object';
|
|
4
4
|
import { tracked } from '@glimmer/tracking';
|
|
5
|
+
import Model, { attr } from '@ember-data/model';
|
|
6
|
+
import { getOwner } from '@ember/application';
|
|
5
7
|
|
|
6
8
|
export default class TypesService extends Service {
|
|
7
9
|
@service store;
|
|
@@ -11,6 +13,22 @@ export default class TypesService extends Service {
|
|
|
11
13
|
|
|
12
14
|
@action
|
|
13
15
|
async fetchAgain() {
|
|
16
|
+
this.json = await this.store.findRecord('webapp', 0, {});
|
|
17
|
+
let owner = getOwner(this);
|
|
18
|
+
|
|
19
|
+
Object.entries(this.json.modules).forEach(([modelName, modelData]) => {
|
|
20
|
+
const modelDynamicName = modelName.replace(/_/g, '-');
|
|
21
|
+
|
|
22
|
+
class DynamicModel extends Model {
|
|
23
|
+
@attr slug;
|
|
24
|
+
@attr modules;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!owner.hasRegistration(`model:${modelDynamicName}`)) {
|
|
28
|
+
owner.register(`model:${modelDynamicName}`, DynamicModel);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
14
32
|
this.json = await this.store.findRecord('webapp', 0, {
|
|
15
33
|
include: ['total_objects'],
|
|
16
34
|
});
|
package/config/environment.js
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports = function (/* environment, appConfig */) {
|
|
4
4
|
let ENV = {
|
|
5
|
-
|
|
6
5
|
//Wildfire Tribe config for EmberJS
|
|
7
6
|
TribeENV: {
|
|
8
7
|
API_URL: process.env.TRIBE_API_URL,
|
|
8
|
+
API_KEY: process.env.TRIBE_API_KEY,
|
|
9
9
|
},
|
|
10
|
-
|
|
11
10
|
};
|
|
12
11
|
|
|
13
12
|
return ENV;
|
|
14
|
-
};
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
$_ENV = parse_ini_file('.env');
|
|
3
|
-
if (($_ENV['TRIBE_API_URL'] ?? false) && $_ENV['TRIBE_API_URL'] != '') {
|
|
4
|
-
$types = json_decode(file_get_contents($_ENV['TRIBE_API_URL'].'/api.php/webapp/0'), true)['data']['attributes']['modules'];
|
|
5
|
-
} else {
|
|
6
|
-
$types = json_decode(file_get_contents('https://raw.githubusercontent.com/tribe-framework/types.json/master/blueprints/junction-init.json'), true);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// re-create models folder
|
|
10
|
-
$commands = "[ -d app/models ] && rm -r app/models && mkdir app/models; ";
|
|
11
|
-
// remove test for models
|
|
12
|
-
$commands .= "[ -d tests/unit/models ] && rm -r tests/unit/models; ";
|
|
13
|
-
|
|
14
|
-
foreach (array_keys($types) as $type) {
|
|
15
|
-
if ($type == 'webapp' || in_array($type, ($types['webapp']['interface_urls'][basename(dirname(__FILE__))]['types'] ?? array_keys($types)))) {
|
|
16
|
-
|
|
17
|
-
$type_hyphen = str_replace('_', '-', $type);
|
|
18
|
-
$type_ucwords = str_replace(' ', '', ucwords(str_replace('_', ' ', $type)));
|
|
19
|
-
$commands .= "echo \"import Model, { attr } from '@ember-data/model';\n\nexport default class ".$type_ucwords."Model extends Model {\n @attr slug;\n @attr modules;\n}\" > app/models/".$type_hyphen.".js; ";
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
exec($commands);
|