Skip to content

Commit 75038b1

Browse files
committed
Update developer-docs.md
1 parent 35975f3 commit 75038b1

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

docs/developer-docs.md

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- [Extending the Settings Interface](#extending-the-settings-interface)
66
- [JavaScript and CSS Development](#javascript-and-css-development)
77
- [Block Development](#block-development)
8-
- [Standalone Assets](#standalone-assets)
8+
- [Feature-Based Asset Organization](#feature-based-asset-organization)
99
- [Development Workflow](#development-workflow)
1010
- [Available Commands](#available-commands)
1111
- [Build Process](#build-process)
@@ -70,14 +70,14 @@ add_action( 'admin_enqueue_scripts', function( $hook ) {
7070

7171
### Block Development
7272

73-
The ActivityPub plugin uses the WordPress Block Editor (Gutenberg) architecture for developing custom blocks. All block-related code is located in the `/src` directory.
73+
The ActivityPub plugin uses the WordPress Block Editor (Gutenberg) architecture for developing custom blocks. All block-related code is located in the `/src/blocks` directory.
7474

7575
#### Block Structure
7676

7777
Each block typically follows this directory structure:
7878

7979
```
80-
/src/block-name/
80+
/src/blocks/block-name/
8181
├── block.json # Block configuration.
8282
├── edit.js # Edit component.
8383
├── index.js # Block registration.
@@ -93,48 +93,62 @@ Each block typically follows this directory structure:
9393
4. **Accessibility**: Ensure your blocks are accessible to all users.
9494
5. **Indentation**: Use tabs for indentation in SCSS files, not spaces.
9595

96-
### Standalone Assets
96+
### Feature-Based Asset Organization
9797

98-
For non-block JavaScript and CSS files, the ActivityPub plugin uses the `/src` directory for source files, which are then built into the `/build` directory by `wp-scripts build`.
98+
The ActivityPub plugin organizes scripts and styles by feature rather than by file type. Each feature has its own directory containing all related assets.
9999

100100
#### Structure
101101

102102
```
103103
/src/
104-
├── css/ # Source CSS files.
105-
├── js/ # Source JavaScript files.
106-
└── [block-name]/ # Block directories.
107-
108-
/build/
109-
├── css/ # Built CSS files.
110-
└── js/ # Built JavaScript files.
104+
├── blocks/ # Block-specific code and styles
105+
│ ├── reply/ # Reply block
106+
│ └── ... # Other blocks
107+
├── wp-admin/ # Admin-related features
108+
│ ├── admin.js # Admin JavaScript
109+
│ ├── admin.scss # Admin styles
110+
│ └── ... # Other admin features
111+
├── feature-name/ # Any other feature
112+
│ ├── script.js # Feature JavaScript
113+
│ ├── style.scss # Feature styles
114+
│ └── ... # Other feature files
115+
└── ... # Other feature directories
116+
117+
/build/ # Compiled assets, organized by feature
111118
```
112119

113-
#### Adding New JavaScript Files
120+
#### Adding New Feature Assets
114121

115-
1. Create your JavaScript source file in the `/src/js/` directory:
122+
1. Create a new directory for your feature in the `/src/` directory:
116123
```
117-
/src/js/your-feature.js
124+
/src/your-feature/
118125
```
119126

120-
2. When you run `npm run build`, WordPress Scripts will:
121-
- Compile your JavaScript file to `/build/js/your-feature.js`.
122-
- Generate an asset file at `/build/js/your-feature.asset.php` containing dependencies and version information.
127+
2. Add your JavaScript and/or SCSS files to this directory:
128+
```
129+
/src/your-feature/script.js
130+
/src/your-feature/style.scss
131+
```
123132

124-
3. Enqueue your script in PHP, using the generated asset file:
133+
3. When you run `npm run build`, WordPress Scripts will:
134+
- Compile your JavaScript file to `/build/your-feature/script.js`.
135+
- Compile and minify your SCSS to `/build/your-feature/style.css`.
136+
- Generate source maps.
137+
138+
4. Enqueue your script and/or stylesheet in PHP, using the generated asset file:
125139

126140
```php
127141
/**
128142
* Enqueue admin scripts.
129143
*/
130144
function activitypub_enqueue_admin_scripts() {
131145
// Load the asset file to get dependencies and version.
132-
$asset_data = include ACTIVITYPUB_PLUGIN_DIR . 'build/js/your-feature.asset.php';
146+
$asset_data = include ACTIVITYPUB_PLUGIN_DIR . 'build/your-feature/script.asset.php';
133147

134148
wp_enqueue_script(
135149
'activitypub-your-feature',
136150
plugins_url(
137-
'build/js/your-feature.js',
151+
'build/your-feature/script.js',
138152
ACTIVITYPUB_PLUGIN_FILE
139153
),
140154
$asset_data['dependencies'],
@@ -143,28 +157,15 @@ function activitypub_enqueue_admin_scripts() {
143157
);
144158
}
145159
add_action( 'admin_enqueue_scripts', 'activitypub_enqueue_admin_scripts' );
146-
```
147-
148-
#### Adding New CSS Files
149160

150-
1. Create your CSS source file in the `/src/css/` directory:
151-
```
152-
/src/css/your-feature.css
153-
```
154-
155-
2. When you run `npm run build`, WordPress Scripts will compile your CSS file to `/build/css/your-feature.css`.
156-
157-
3. Enqueue your stylesheet in PHP:
158-
159-
```php
160161
/**
161162
* Enqueue admin styles.
162163
*/
163164
function activitypub_enqueue_admin_styles() {
164165
wp_enqueue_style(
165166
'activitypub-your-feature',
166167
plugins_url(
167-
'build/css/your-feature.css',
168+
'build/your-feature/style.css',
168169
ACTIVITYPUB_PLUGIN_FILE
169170
),
170171
array(),

0 commit comments

Comments
 (0)