-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.php
More file actions
executable file
·58 lines (54 loc) · 1.55 KB
/
setup.php
File metadata and controls
executable file
·58 lines (54 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Setup WordPress files.
*
* @package tarosky/workflow
*/
$files = [
'.editorconfig' => 'https://raw.githubusercontent.com/ntwb/wordpress/master/.editorconfig',
'phpcs.ruleset.xml' => '',
'phpunit.xml.dist' => '',
'.browserslistrc' => '',
'.distignore' => '',
'.eslintrc.json' => '',
'.gitignore' => '',
'.stylelintrc.json' => '',
'.wp-env.json' => '',
'tests/bootstrap.php' => '',
'tests/SampleTest.php' => '',
'bin/imagemin.mjs' => '',
'bin/compiler.js' => '',
'package.json' => '',
'composer.json' => '',
];
// Ensure directory exists.
foreach ( [ 'tests', 'bin' ] as $dir ) {
if ( ! is_dir( $dir ) ) {
if ( ! mkdir( $dir, 0755, true ) ) {
die( 'Failed to create tests directory.' );
}
}
}
// Download all.
foreach ( $files as $name => $url ) {
if ( file_exists( $name ) ) {
printf( '%s already exists.' . PHP_EOL, $name );
continue;
}
$prefix = 'https://raw.githubusercontent.com/tarosky/workflows/main/boilerplate/';
if ( ! $url ) {
$url = $prefix . $name;
}
file_put_contents( $name, file_get_contents( $url ) );
printf( '%s created.' . PHP_EOL, $name );
}
// Replace project name.
$project_name = basename( __DIR__ );
foreach ( [ 'package.json', 'composer.json', 'tests/bootstrap.php' ] as $config ) {
echo "Changing name...";
if ( ! file_exists( $config ) ) {
printf( '%s not found.' . PHP_EOL, $config );
continue;
}
file_put_contents( $config, str_replace( '$PROJECT$', $project_name, file_get_contents( $config ) ) );
}