process package.json for themes

This commit is contained in:
Adam Weston
2023-07-16 11:14:28 -04:00
parent 86a9868e35
commit 89969d6be2
3 changed files with 46 additions and 18 deletions

View File

@@ -74,7 +74,6 @@ if (! confirm('Modify files?', true)) {
if ($formsOnly) {
safeUnlink(__DIR__ . '/src/SkeletonTheme.php');
safeUnlink(__DIR__ . '/src/SkeletonPlugin.php');
safeUnlink(__DIR__ . '/package-theme.json');
removeComposerDeps([
'filament/filament',
@@ -83,7 +82,6 @@ if ($formsOnly) {
} elseif ($tablesOnly) {
safeUnlink(__DIR__ . '/src/SkeletonTheme.php');
safeUnlink(__DIR__ . '/src/SkeletonPlugin.php');
safeUnlink(__DIR__ . '/package-theme.json');
removeComposerDeps([
'filament/filament',
@@ -94,6 +92,7 @@ if ($formsOnly) {
safeUnlink(__DIR__ . '/src/SkeletonServiceProvider.php');
safeUnlink(__DIR__ . '/src/SkeletonPlugin.php');
safeUnlink(__DIR__ . '/src/Skeleton.php');
removeDirectory(__DIR__ . '/bin');
removeDirectory(__DIR__ . '/config');
removeDirectory(__DIR__ . '/database');
removeDirectory(__DIR__ . '/stubs');
@@ -103,9 +102,11 @@ if ($formsOnly) {
removeDirectory(__DIR__ . '/src/Commands');
removeDirectory(__DIR__ . '/src/Facades');
removeDirectory(__DIR__ . '/src/Testing');
setupPackageJsonForTheme();
} else {
safeUnlink(__DIR__ . '/src/SkeletonTheme.php');
safeUnlink(__DIR__ . '/package-theme.json');
}
removeComposerDeps([
@@ -279,6 +280,20 @@ function removeComposerDeps(array $names, string $location): void
file_put_contents(__DIR__ . '/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
}
function removeNpmDeps(array $names, string $location): void
{
$data = json_decode(file_get_contents(__DIR__ . '/package.json'), true);
foreach ($data[$location] as $name => $version) {
if (in_array($name, $names, true)) {
unset($data[$location][$name]);
}
}
file_put_contents(__DIR__ . '/package.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES |
JSON_UNESCAPED_UNICODE));
}
function removeTag(string $file, string $tag): void
{
$contents = file_get_contents($file);
@@ -289,6 +304,32 @@ function removeTag(string $file, string $tag): void
);
}
function setupPackageJsonForTheme(): void
{
removeNpmDeps([
'purge',
'dev',
'dev:scripts',
'build',
'build:scripts',
], 'scripts');
removeNpmDeps([
'@awcodes/filament-plugin-purge',
'esbuild',
'npm-run-all',
'prettier',
'prettier-plugin-tailwindcss',
], 'devDependencies');
$newData = json_decode(file_get_contents(__DIR__ . '/package.json'), true);
replaceInFile($newData, [
'dev:styles' => 'dev',
'build:styles' => 'build',
]);
}
function safeUnlink(string $filename): void
{
if (file_exists($filename) && is_file($filename)) {

View File

@@ -1,15 +0,0 @@
{
"private": true,
"scripts": {
"dev": "npx tailwindcss -i resources/css/index.css -o resources/dist/skeleton.css --postcss --watch",
"build": "npx tailwindcss -i resources/css/index.css -o resources/dist/skeleton.css --postcss --minify"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.4",
"@tailwindcss/typography": "^0.5.9",
"autoprefixer": "^10.4.14",
"postcss": "^8.4.26",
"postcss-import": "^15.1.0",
"tailwindcss": "^3.3.3"
}
}

View File

@@ -11,6 +11,8 @@
},
"devDependencies": {
"@awcodes/filament-plugin-purge": "^1.1.1",
"@tailwindcss/forms": "^0.5.4",
"@tailwindcss/typography": "^0.5.9",
"autoprefixer": "^10.4.14",
"esbuild": "^0.17.19",
"npm-run-all": "^4.1.5",