Skip to content

Commit 752d29c

Browse files
committed
Add command option to create script.js file from template
1 parent 73f1360 commit 752d29c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Commands/PageCreateCommand.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ public function run(array $params)
3232
}
3333

3434
$pageName = $params[0];
35+
$options = service('request')->getOptions();
36+
$createScript = array_key_exists('script', $options) || array_key_exists('s', $options) ? true : false;
3537
$basePath = APPPATH . "Pages/{$pageName}";
3638
$controllerPath = "{$basePath}/PageController.php";
3739
$viewPath = "{$basePath}/index.php";
40+
$scriptPath = "{$basePath}/script.js";
3841

3942
// Path to templates
4043
$templatePath = dirname(__DIR__) . '/templates';
@@ -66,6 +69,17 @@ public function run(array $params)
6669
'{{pageSlug}}' => str_replace('/', '_', $pageName),
6770
],
6871
);
72+
73+
// Create script.js file
74+
if ($createScript) {
75+
$this->createFileFromTemplate(
76+
"{$templatePath}/script.js",
77+
$scriptPath,
78+
[
79+
'{{pageSlug}}' => str_replace('/', '_', $pageName)
80+
]
81+
);
82+
}
6983
}
7084

7185
/**

src/templates/script.js.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
document.addEventListener('alpine:init', () => {
2+
Alpine.data('{{pageSlug}}', () => ({
3+
4+
}))
5+
})

0 commit comments

Comments
 (0)