Skip to content

Commit a827355

Browse files
authored
feat: add missing lang histories from prolang api 🔎 (#21)
1 parent 797ef3e commit a827355

17 files changed

Lines changed: 312 additions & 296 deletions

File tree

‎.github/workflows/lint.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ jobs:
3535

3636
- name: Lint Frontend
3737
run: npx biome check
38+
39+
- name: Lint TS errors
40+
run: |
41+
php artisan wayfinder:generate
42+
npx vue-tsc --noEmit --checkJs --project tsconfig.json

‎.github/workflows/tests.yml‎

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,47 @@ on:
1313
jobs:
1414
ci:
1515
runs-on: ubuntu-latest
16+
services:
17+
postgres:
18+
image: postgres:15
19+
env:
20+
POSTGRES_USER: test
21+
POSTGRES_PASSWORD: secret
22+
POSTGRES_DB: test_db
23+
ports:
24+
- 5432:5432
25+
options: >-
26+
--health-cmd pg_isready
27+
--health-interval 10s
28+
--health-timeout 5s
29+
--health-retries 5
1630
1731
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v4
32+
- uses: actions/checkout@v4
2033

21-
- name: Setup PHP
22-
uses: shivammathur/setup-php@v2
34+
- uses: shivammathur/setup-php@v2
2335
with:
2436
php-version: 8.4
2537
tools: composer:v2
2638
coverage: xdebug
2739

28-
- name: Setup Node
29-
uses: actions/setup-node@v4
40+
- uses: actions/setup-node@v4
3041
with:
3142
node-version: '22'
3243
cache: 'npm'
3344

34-
- name: Install Node Dependencies
35-
run: npm ci
36-
37-
- name: Install Dependencies
38-
run: composer install --no-interaction --prefer-dist --optimize-autoloader
39-
40-
- name: Copy Environment File
41-
run: cp .env.example .env
42-
43-
- name: Generate Application Key
44-
run: php artisan key:generate
45-
46-
- name: Build Assets
47-
run: npm run build
45+
- run: npm ci
46+
- run: composer install --no-interaction --prefer-dist --optimize-autoloader
47+
- run: cp .env.example .env
48+
- run: php artisan key:generate
49+
- run: npm run build
4850

4951
- name: Tests
52+
env:
53+
DB_CONNECTION: pgsql
54+
DB_HOST: 127.0.0.1
55+
DB_PORT: 5432
56+
DB_DATABASE: test_db
57+
DB_USERNAME: test
58+
DB_PASSWORD: secret
5059
run: ./vendor/bin/pest

‎app/Console/Commands/LoadProLang.php‎

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ private function saveProLang(array $item) {
5151
'name' => $yearGroup['name'],
5252
),
5353
array(
54-
'apiId' => $yearGroup['id'],
55-
'position' => $yearGroup['position'],
56-
'name' => $yearGroup['name'],
54+
'apiId' => $yearGroup['id'] ?? null,
55+
'position' => $yearGroup['position'] ?? null,
56+
'name' => $yearGroup['name'] ?? null,
5757
));
5858

5959
$updatedLang = ProLang::updateOrCreate(
@@ -118,12 +118,92 @@ private function getLanguages(int $page) {
118118
}
119119

120120
/**
121-
* Execute the console command.
121+
* Add some languages like Phel missing in prolang api
122122
*/
123+
private function addProLanguage() {
124+
$langToAdd = array(
125+
// Data : https://phel-lang.org/ and preums itselft
126+
array(
127+
'authors' => array(),
128+
'company' => null,
129+
'id' => uniqid().'_Phel',
130+
'link' => '',
131+
'name' => 'Phel',
132+
'predecessors' => array(),
133+
'yearGroup' => array(
134+
'name' => '2020s',
135+
),
136+
'years' => array(2020),
137+
),
138+
// Data : https://janet-lang.org/ and preums itselft
139+
array(
140+
'authors' => array(),
141+
'company' => null,
142+
'id' => uniqid().'_Janet',
143+
'link' => '',
144+
'name' => 'Janet',
145+
'predecessors' => array(),
146+
'yearGroup' => array(
147+
'name' => '2010s',
148+
),
149+
'years' => array(2017),
150+
),
151+
);
152+
153+
foreach ($langToAdd as $item) {
154+
$this->saveProLang($item);
155+
Log::info('action=add_missing_lang, status=succes, lang='.$item['name']);
156+
}
157+
}
158+
159+
/**
160+
* Add links between languages
161+
* - Some data are missing from prolang api
162+
* - Ex : Php is Hack's predecessors
163+
*/
164+
private function updateLangFamily() {
165+
$langFamilies = array(
166+
// Data: https://github.com/janet-lang/janet
167+
'Janet' => array('C'),
168+
// Data : https://phel-lang.org/
169+
'Phel' => array('PHP', 'Clojure', 'Janet', 'Lisp'),
170+
// https://en.wikipedia.org/wiki/PHP
171+
'PHP' => array('C', 'C++', 'Perl'),
172+
// Data : https://en.wikipedia.org/wiki/Hack_(programming_language)
173+
'Hack' => array('PHP', 'OCaml', 'Java', 'Scala', 'Haskell', 'C#'),
174+
// Data : https://crystal-lang.org/ and https://en.wikipedia.org/wiki/Crystal_(programming_language)
175+
'Crystal' => array('Ruby', 'Go'),
176+
// Data : https://en.wikipedia.org/wiki/Ruby_(programming_language)
177+
'Ruby' => array('Ada', 'Eiffel', 'Lua', 'Dylan'),
178+
// Data : https://en.wikipedia.org/wiki/Dylan_(programming_language)
179+
'Dylan' => array('ALGOL 60', 'EuLisp'),
180+
// Data : https://en.wikipedia.org/wiki/Lasso_(programming_language)
181+
'Lasso' => array('Dylan', 'Scala'),
182+
);
183+
184+
foreach ($langFamilies as $name => $value) {
185+
$lang = ProLang::where('name', $name)->first();
186+
if ($lang) {
187+
$parents = ProLang::whereIn(
188+
'name', $value
189+
)->pluck('id');
190+
191+
$lang->parents()->sync($parents);
192+
$lang->save();
193+
194+
Log::info("action=save_lang, status=success, lang=$name");
195+
} else {
196+
Log::info("action=save_lang, status=failed, reason=lang $name not found");
197+
}
198+
}
199+
}
200+
123201
public function handle() {
124202
Log::info('action=load_prolang_command, status=started');
125203

126204
$this->getLanguages(1);
205+
$this->addProLanguage();
206+
$this->updateLangFamily();
127207

128208
Log::info('action=load_prolang_command, status=finished');
129209
}

‎app/Console/Commands/ProLangAssets.php‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,12 @@ function member
11171117
),
11181118
'Common Lisp' => array(),
11191119
'Windows PowerShell' => array(),
1120+
'Phel' => array(
1121+
'mainRepository' => 'https://github.com/phel-lang/phel-lang',
1122+
),
1123+
'Janet' => array(
1124+
'mainRepository' => 'https://github.com/janet-lang/janet',
1125+
),
11201126
);
11211127

11221128
DB::transaction(function () use ($langsData) {
@@ -1141,9 +1147,10 @@ function member
11411147
*/
11421148
public function handle() {
11431149
Log::info('action=prolang_assets_command, status=started');
1144-
$this->updateAssets();
1145-
Log::info('action=prolang_assets_command, status=finished');
11461150

1151+
$this->updateAssets();
11471152
$this->updateLinks();
1153+
1154+
Log::info('action=prolang_assets_command, status=finished');
11481155
}
11491156
}

‎app/Models/ProLang.php‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Database\Eloquent\Relations\BelongsTo;
77
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
8+
use Illuminate\Support\Facades\DB;
89

910
/**
1011
* @property int $id
@@ -21,6 +22,8 @@
2122
class ProLang extends Model {
2223
protected $guarded = array('id');
2324

25+
protected $appends = array('paths');
26+
2427
protected $casts = array(
2528
'years' => 'array',
2629
);
@@ -52,4 +55,38 @@ public function authors(): BelongsToMany {
5255
public function authorNames(): array {
5356
return $this->authors()->pluck('name')->toArray();
5457
}
58+
59+
// paths
60+
61+
public function getPathsAttribute() {
62+
$targetId = DB::table('pro_langs')->where('id', $this->id)->value('id');
63+
64+
$paths = DB::select("
65+
WITH RECURSIVE paths AS (
66+
SELECT
67+
l.id,
68+
l.name,
69+
l.name::text AS path
70+
FROM pro_langs l
71+
WHERE NOT EXISTS (
72+
SELECT 1 FROM predecessors p WHERE p.child_id = l.id
73+
)
74+
75+
UNION ALL
76+
77+
SELECT
78+
c.id,
79+
c.name,
80+
paths.path || ' -> ' || c.name
81+
FROM paths
82+
JOIN predecessors p ON p.parent_id = paths.id
83+
JOIN pro_langs c ON c.id = p.child_id
84+
)
85+
SELECT path
86+
FROM paths
87+
WHERE id = ?
88+
", array($targetId));
89+
90+
return array_map(fn ($r) => $r->path, $paths);
91+
}
5592
}

0 commit comments

Comments
 (0)