Skip to content

Commit

Permalink
Update resources structure
Browse files Browse the repository at this point in the history
  • Loading branch information
simonkataev committed Apr 16, 2024
1 parent 9cd2e66 commit 26bfeaf
Show file tree
Hide file tree
Showing 79 changed files with 519 additions and 509 deletions.
1 change: 0 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ build:
- .eslintrc.js
- .prettierrc
- .stylelintrc
- bud.config.js
- tsconfig.json
dependencies:
- changed-files:
Expand Down
33 changes: 27 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
/node_modules
/vendor
/public
node_modules
vendor
public
dist
dist-ssr
.env
.budfiles
npm-debug.log
yarn-error.log
*.local

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $ yarn build

You're ready to go!

To start dev server update proxy url in `bud.config.js:37` (setProxyUrl) and run
To start dev server and HMR just run

```shell
$ yarn dev
Expand Down Expand Up @@ -85,8 +85,8 @@ themes/your-theme-name/ # → Root of your Sage based theme
├── resources/ # → Theme assets and templates
│ ├── fonts/ # → Theme fonts
│ ├── images/ # → Theme images
│ ├── scripts/ # → Theme javascript
│ ├── styles/ # → Theme stylesheets
│ ├── scripts/ # → Theme scripts
│ ├── styles/ # → Theme styles
│ ├── svg/ # → Theme svgs
│ └── views/ # → Theme templates
│ ├── components/ # → Component templates
Expand Down
4 changes: 2 additions & 2 deletions app/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Enqueue theme stylesheets
*/
if (hmr_enabled()) {
$asset = 'resources/scripts/main.ts';
$asset = 'resources/index.js';
$namespace = strtolower(wp_get_theme()->get('Name'));

wp_enqueue_script($namespace, hmr_assets($asset), array (), null, true);
Expand All @@ -46,7 +46,7 @@
*/
add_action('enqueue_block_editor_assets', function (): void {
if (hmr_enabled()) {
$asset = 'resources/scripts/editor.ts';
$asset = 'resources/scripts/editor.js';
$namespace = strtolower(wp_get_theme()->get('Name'));

wp_enqueue_script($namespace, hmr_assets($asset), array (), null, true);
Expand Down
34 changes: 0 additions & 34 deletions jsconfig.json

This file was deleted.

Binary file added resources/fonts/Roboto/Roboto-Bold.woff
Binary file not shown.
Binary file added resources/fonts/Roboto/Roboto-Bold.woff2
Binary file not shown.
Binary file added resources/fonts/Roboto/Roboto-Light.woff
Binary file not shown.
Binary file added resources/fonts/Roboto/Roboto-Light.woff2
Binary file not shown.
Binary file added resources/fonts/Roboto/Roboto-Medium.woff
Binary file not shown.
Binary file added resources/fonts/Roboto/Roboto-Medium.woff2
Binary file not shown.
Binary file added resources/fonts/Roboto/Roboto-Regular.woff
Binary file not shown.
Binary file added resources/fonts/Roboto/Roboto-Regular.woff2
Binary file not shown.
Binary file removed resources/fonts/whyte.woff2
Binary file not shown.
3 changes: 3 additions & 0 deletions resources/images/icons/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/images/sprite/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions resources/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Styles */
import '@styles/main.scss'

/* Scripts */
import '@scripts'
4 changes: 4 additions & 0 deletions resources/scripts/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
init() {},
finalize() {},
}
1 change: 1 addition & 0 deletions resources/scripts/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('editor scripts loaded')
3 changes: 0 additions & 3 deletions resources/scripts/editor.ts

This file was deleted.

53 changes: 0 additions & 53 deletions resources/scripts/guide.ts

This file was deleted.

14 changes: 14 additions & 0 deletions resources/scripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Router from './utils/Router'
import components from './components'
import pages from './pages'

const routes = new Router({
components,
pages,
})

window.addEventListener('DOMContentLoaded', () => {
routes.loadEvents()
components.init()
pages.init()
})
9 changes: 0 additions & 9 deletions resources/scripts/main.ts

This file was deleted.

3 changes: 3 additions & 0 deletions resources/scripts/pages/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function () {
console.log('home scripts loaded')
}
8 changes: 8 additions & 0 deletions resources/scripts/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import home from './home'

export default {
init() {
home()
},
finalize() {},
}
71 changes: 71 additions & 0 deletions resources/scripts/utils/Router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import camelCase from './camelCase';

/**
* DOM-based Routing
*
* Based on {@link http://goo.gl/EUTi53|Markup-based Unobtrusive Comprehensive DOM-ready Execution} by Paul Irish
*
* The routing fires all common scripts, followed by the page specific scripts.
* Add additional events for more control over timing e.g. a finalize event
*/
class Router {

/**
* Create a new Router
* @param {Object} routes
*/
constructor(routes) {
this.routes = routes;
}

/**
* Fire Router events
* @param {string} route DOM-based route derived from body classes (`<body class="...">`)
* @param {string} [event] Events on the route. By default, `init` and `finalize` events are called.
* @param {string} [arg] Any custom argument to be passed to the event.
*/
fire(route, event = 'init', arg) {
document.dispatchEvent(new CustomEvent('routed', {
bubbles: true,
detail: {
route,
fn: event,
},
}));

const fire = route !== '' && this.routes[route] && typeof this.routes[route][event] === 'function';
if (fire) {
this.routes[route][event](arg);
}
}

/**
* Automatically load and fire Router events
*
* Events are fired in the following order:
* * common init
* * page-specific init
* * page-specific finalize
* * common finalize
*/
loadEvents() {
// Fire common init JS
this.fire('common');

// Fire page-specific init JS, and then finalize JS
document.body.className
.toLowerCase()
.replace(/-/g, '_')
.split(/\s+/)
.map(camelCase)
.forEach((className) => {
this.fire(className);
this.fire(className, 'finalize');
});

// Fire common finalize JS
this.fire('common', 'finalize');
}
}

export default Router;
9 changes: 9 additions & 0 deletions resources/scripts/utils/camelCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* the most terrible camelizer on the internet, guaranteed!
* @param {string} str String that isn't camel-case, e.g., CAMeL_CaSEiS-harD
* @return {string} String converted to camel-case, e.g., camelCaseIsHard
*/
export default str => `${str.charAt(0).toLowerCase()}${str.replace(/[\W_]/g, '|').split('|')
.map(part => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)
.join('')
.slice(1)}`;
1 change: 0 additions & 1 deletion resources/styles/_components.scss

This file was deleted.

1 change: 0 additions & 1 deletion resources/styles/_fonts.scss

This file was deleted.

3 changes: 0 additions & 3 deletions resources/styles/_functions.scss

This file was deleted.

1 change: 0 additions & 1 deletion resources/styles/_layouts.scss

This file was deleted.

5 changes: 0 additions & 5 deletions resources/styles/_mixins.scss

This file was deleted.

Loading

0 comments on commit 26bfeaf

Please sign in to comment.