Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detection Library #1

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9dbbc97
Draft directory structure for detection
vermakhushboo Jan 9, 2025
38d3127
Add SSG, Yarn and PNPM
vermakhushboo Jan 9, 2025
e850ae7
Add Enum for package manager and framework
vermakhushboo Jan 14, 2025
76442c0
Update detection order in example.php
vermakhushboo Jan 14, 2025
d40606f
Rename RenderingStrategy to Rendering
vermakhushboo Jan 15, 2025
87ae54e
Simplify calls to detectors
vermakhushboo Jan 16, 2025
065d8ce
Add contributing and code of conduct
vermakhushboo Jan 16, 2025
679486c
Improve folder structure
Meldiron Jan 20, 2025
944e9c2
Improve folder structure
Meldiron Jan 20, 2025
887d259
Add runtime methods
vermakhushboo Jan 21, 2025
ec0ddb1
Add framework files
vermakhushboo Jan 21, 2025
97d8ef0
Package manager detection
vermakhushboo Jan 21, 2025
bf9badb
Add logic to runtime detection
vermakhushboo Jan 22, 2025
e483425
Add methods to frameworks
vermakhushboo Jan 22, 2025
d32fbd3
More updates
vermakhushboo Jan 23, 2025
8c5c29a
Add rendering detection logic
vermakhushboo Jan 24, 2025
ae04fc7
Updated rendering detection logic
vermakhushboo Jan 30, 2025
6d0d8d1
Add test file
vermakhushboo Jan 30, 2025
db3dde9
Add tests for frameworks and rendering
vermakhushboo Jan 30, 2025
b9f0cec
Use specific files for Rendering detection
vermakhushboo Jan 30, 2025
6a7720f
Renamed names to lowercase
vermakhushboo Feb 4, 2025
b65a212
Remove nested structures from file matches
vermakhushboo Feb 4, 2025
399d709
Rewrite tests using data provider
vermakhushboo Feb 5, 2025
a830391
Use array_intersect instead of nested for loops
vermakhushboo Feb 5, 2025
5a19a52
Update names of test functions
vermakhushboo Feb 5, 2025
e2a943b
Change to generic exception
vermakhushboo Feb 5, 2025
4a65f64
Add README.md and other CI/CD files
vermakhushboo Feb 5, 2025
a18b638
Add GitHub workflow files
vermakhushboo Feb 5, 2025
b60cf66
Update tests.yml
vermakhushboo Feb 5, 2025
e000f50
Update github workflows
vermakhushboo Feb 5, 2025
57a9097
UPdate composer.lock
vermakhushboo Feb 5, 2025
c8e0b7e
Try tests.yml
vermakhushboo Feb 5, 2025
4cd2eae
Try tests.yml
vermakhushboo Feb 5, 2025
7e9bceb
Try tests.yml
vermakhushboo Feb 5, 2025
c4ca6d7
Fix phpstan errors
vermakhushboo Feb 5, 2025
1065da4
Fix phpstan errors
vermakhushboo Feb 5, 2025
45058f3
Fix phpstan errors
vermakhushboo Feb 5, 2025
7435573
Fix phpstan errors
vermakhushboo Feb 5, 2025
27223f7
Fix phpstan errors
vermakhushboo Feb 5, 2025
f5e6f2e
Update case of files
vermakhushboo Feb 6, 2025
09512d0
Separate Strategy class
vermakhushboo Feb 6, 2025
0f1d84c
Add SPA detection logic
vermakhushboo Feb 17, 2025
d7ecb85
Remove redundant if condition
vermakhushboo Feb 17, 2025
69958f4
rename next.js to nextjs
vermakhushboo Feb 18, 2025
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
8 changes: 8 additions & 0 deletions Adapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Utopia\Detector;

abstract class Adapter
{
abstract public function detect(array $inputs): ?Detection;
}
17 changes: 17 additions & 0 deletions Adapter/Framework.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Utopia\Detector\Adapter;

use Utopia\Detector\Adapter;
use Utopia\Detector\Detection\Framework\Detection as FrameworkDetection;

class Framework implements Adapter
{
// add param input for mixed input
public function detect(array $inputs): ?FrameworkDetection
{
// Implement logic to determine if framework matches

return null;
}
}
17 changes: 17 additions & 0 deletions Adapter/PackageManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Utopia\Detector\Adapter;

use Utopia\Detector\Adapter;
use Utopia\Detector\Detection\PackageManager\Detection as PackageManagerDetection;

class PackageManager implements Adapter
{
// add param input for mixed input
public function detect(array $inputs): ?PackageManagerDetection
{
// implement logic to detect package manager

return null;
}
}
17 changes: 17 additions & 0 deletions Adapter/RenderingStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Utopia\Detector\Adapter;

use Utopia\Detector\Adapter;
use Utopia\Detector\Detection\RenderingStrategy\Detection as RenderingStrategyDetection;

class RenderingStrategy implements Adapter
{
// add param input for mixed input
public function detect(array $inputs): ?RenderingStrategyDetection
{
// implement logic to detect rendering strategy ie server side, client side, etc

return null;
}
}
17 changes: 17 additions & 0 deletions Adapter/Runtime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Utopia\Detector\Adapter;

use Utopia\Detector\Adapter;
use Utopia\Detector\Detection\Runtime\Detection as RuntimeDetection;

class Runtime implements Adapter
{
// add param input for mixed input
public function detect(array $inputs): ?RuntimeDetection
{
// Implement logic to determine if runtime matches

return null;
}
}
8 changes: 8 additions & 0 deletions Detection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Utopia\Detector;

abstract class Detection
{
abstract public function getName(): string;
}
15 changes: 15 additions & 0 deletions Detection/Framework/Detection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Utopia\Detector\Detection\Framework;

use Utopia\Detector\Detection as BaseDetection;

abstract class Detection extends BaseDetection
{
abstract public function getInstallCommand(): string;
abstract public function getBuildCommand(): string;
abstract public function getInstallCommands(): array;
abstract public function getBuildCommands(): array;
abstract public function getOutputDirectory(): string;
abstract public function getFallbackFile(): string | null;
}
51 changes: 51 additions & 0 deletions Detection/Framework/Nextjs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Utopia\Detector\Detection\Framework;

use Utopia\Detector\Detection\Framework\Detection as FrameworkDetection;

class Nextjs extends FrameworkDetection
{
public function getName(): string
{
return 'Next.js';
}

public function getInstallCommand(): string
{
return 'npm install';
}

public function getBuildCommand(): string
{
return 'npm run build';
}

public function getInstallCommands(): array
{
return [
'npm' => 'npm install',
'yarn' => 'yarn install',
'pnpm' => 'pnpm install',
];
}

public function getBuildCommands(): array
{
return [
'npm' => 'npm run build',
'yarn' => 'yarn build',
'pnpm' => 'pnpm build',
];
}

public function getOutputDirectory(): string
{
return './.next';
}

public function getFallbackFile(): string | null
{
return null;
}
}
10 changes: 10 additions & 0 deletions Detection/PackageManager/Detection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Utopia\Detector\Detection\PackageManager;

use Utopia\Detector\Detection as BaseDetection;

abstract class Detection extends BaseDetection
{
abstract public function getName(): string;
}
13 changes: 13 additions & 0 deletions Detection/PackageManager/Npm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Utopia\Detector\Detection\PackageManager;

use Utopia\Detector\Detection\PackageManager\Detection as PackageManagerDetection;

class Npm extends PackageManagerDetection
{
public function getName(): string
{
return 'npm';
}
}
10 changes: 10 additions & 0 deletions Detection/RenderingStrategy/Detection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Utopia\Detector\Detection\RenderingStrategy;

use Utopia\Detector\Detection as BaseDetection;

abstract class Detection extends BaseDetection
{
abstract public function getName(): string;
}
13 changes: 13 additions & 0 deletions Detection/RenderingStrategy/SSR.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Utopia\Detector\Detection\RenderingStrategy;

use Utopia\Detector\Detection\RenderingStrategy\Detection as RenderingStrategyDetection;

class SSR extends RenderingStrategyDetection
{
public function getName(): string
{
return 'SSR';
}
}
11 changes: 11 additions & 0 deletions Detection/Runtime/Detection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Utopia\Detector\Detection\Runtime;

use Utopia\Detector\Detection as BaseDetection;

abstract class Detection extends BaseDetection
{
abstract public function getCommand(): string;
abstract public function getCommands(): array;
}
27 changes: 27 additions & 0 deletions Detection/Runtime/Node.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Utopia\Detector\Detection\Runtime;

use Utopia\Detector\Detection\Runtime\Detection as RuntimeDetection;

class Node extends RuntimeDetection
{
public function getName(): string
{
return 'node';
}

public function getCommand(): string
{
return 'npm install';
}

public function getCommands(): array
{
return [
'npm' => 'npm install',
'yarn' => 'yarn install',
'pnpm' => 'pnpm install',
];
}
}
19 changes: 19 additions & 0 deletions Detector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Utopia\Detector;

class Detector {

private array $inputs;
private Adapter $adapter;

public function _construct(array $inputs, Adapter $adapter) {
$this->inputs = $inputs;
$this->adapter = $adapter;
}

public function detect(): ?Detection
{
return $this->adapter->detect($this->inputs);
}
}
52 changes: 52 additions & 0 deletions example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

use Utopia\Detector\Detector;
use Utopia\Detector\Adapter\Framework;
use Utopia\Detector\Adapter\PackageManager;
use Utopia\Detector\Adapter\RenderingStrategy;
use Utopia\Detector\Adapter\Runtime;
use Utopia\Detector\Detection\Framework\Detection as FrameworkDetection;
use Utopia\Detector\Detection\PackageManager\Detection as PackageManagerDetection;
use Utopia\Detector\Detection\RenderingStrategy\Detection as RenderingStrategyDetection;
use Utopia\Detector\Detection\Runtime\Detection as RuntimeDetection;

$files = ['src/main.js', '.gitignore', 'package.json', 'yarn.lock'];
$runtimeDetector = new Detector($files, new Runtime());
$detection = $runtimeDetector->detect();

if ($detection instanceof RuntimeDetection) {
$installCommand = $detection->getCommand();
echo "Detected runtime: " . $detection->getName() . "\n";
echo "Install command: " . $installCommand . "\n";
} else {
echo "No runtime detected.\n";
}

$frameworkDetector = new Detector($files, new Framework());
$detection = $frameworkDetector->detect();

if ($detection instanceof FrameworkDetection) {
echo "Detected framework: " . $detection->getName() . "\n";
echo "Install command: " . $detection->getInstallCommand() . "\n";
echo "Build command: " . $detection->getBuildCommand() . "\n";
} else {
echo "No framework detected.\n";
}

$packageManagerDetector = new Detector($files, new PackageManager());
$detection = $packageManagerDetector->detect();

if ($detection instanceof PackageManagerDetection) {
echo "Detected package manager: " . $detection->getName() . "\n";
} else {
echo "No package manager detected.\n";
}

$renderingStrategyDetector = new Detector($files, new RenderingStrategy());
$detection = $renderingStrategyDetector->detect();

if ($detection instanceof RenderingStrategyDetection) {
echo "Detected rendering strategy: " . $detection->getName() . "\n";
} else {
echo "No rendering strategy detected.\n";
}