-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b418c3a
commit 234919e
Showing
10 changed files
with
211 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: "JS Lint Checker: Installer Module" | ||
on: | ||
workflow_dispatch: | ||
push: | ||
paths: | ||
- "src/**/*.js" | ||
- "src/**/*.scss" | ||
pull_request: | ||
types: [opened, edited, reopened, ready_for_review] | ||
paths: | ||
- "src/**/*.js" | ||
- "src/**/*.scss" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
lint-check-spa: | ||
name: Run Lint Checks | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
# Install Node and npm | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
cache: 'npm' | ||
|
||
# Checks if node_modules exists in the cache. | ||
- name: Cache node_modules directory | ||
id: cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: node_modules | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: ${{ runner.os }}-node- | ||
|
||
- name: Setup Registry | ||
run: printf "@newfold-labs:registry=https://npm.pkg.github.com/\n//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
|
||
# Installs @wordpress/scripts for lint checks if it does not exist in the cache. | ||
- name: Install dependencies | ||
run: npm i @wordpress/[email protected] @newfold-labs/js-utility-ui-analytics --legacy-peer-deps | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
|
||
# Gets the files changed wrt to trunk and filters out the js files. | ||
- uses: technote-space/get-diff-action@v6 | ||
with: | ||
PATTERNS: | | ||
+(src)/**/*.js | ||
# Runs wp-scripts for checking JS coding issues. | ||
- name: Run JS Lint | ||
id: js-lint | ||
run: npx wp-scripts lint-js ${{ env.GIT_DIFF }} | ||
if: "!! env.GIT_DIFF" | ||
|
||
# Gets the files changed wrt to trunk and filters out the SASS files. | ||
- uses: technote-space/get-diff-action@v6 | ||
with: | ||
PATTERNS: | | ||
+(src)/**/*.scss | ||
if: ${{ success() || steps.js-lint.conclusion == 'failure' }} | ||
|
||
# Runs wp-scripts for checking SASS coding issues. | ||
- name: Run SASS Lint | ||
id: sass-lint | ||
run: npx wp-scripts lint-style ${{ env.GIT_DIFF }} | ||
if: ${{ (!! env.GIT_DIFF) && (success() || steps.js-lint.conclusion == 'failure') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace NewfoldLabs\WP\Module\Installer\Data; | ||
|
||
use NewfoldLabs\WP\ModuleLoader\Container; | ||
|
||
/** | ||
* Manages all the constants for the module. | ||
*/ | ||
class Constants { | ||
/** | ||
* Constructor for the Constants class. | ||
* | ||
* @param Container $container The module container. | ||
*/ | ||
public function __construct( $container ) { | ||
if ( ! defined( 'NFD_INSTALLER_VERSION' ) ) { | ||
define( 'NFD_INSTALLER_VERSION', '1.1.5' ); | ||
} | ||
if ( ! defined( 'NFD_INSTALLER_BUILD_DIR' ) && defined( 'NFD_INSTALLER_VERSION' ) ) { | ||
define( 'NFD_INSTALLER_BUILD_DIR', dirname( __DIR__, 2 ) . '/build/' . NFD_INSTALLER_VERSION ); | ||
} | ||
if ( ! defined( 'NFD_INSTALLER_BUILD_URL' && defined( 'NFD_INSTALLER_VERSION' ) ) ) { | ||
define( 'NFD_INSTALLER_BUILD_URL', $container->plugin()->url . '/vendor/newfold-labs/wp-module-pls/build/' . NFD_INSTALLER_VERSION ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace NewfoldLabs\WP\Module\Installer\WPAdmin\Listeners; | ||
|
||
/** | ||
* Manages all the data-* listening related functionalities for the module. | ||
*/ | ||
class DataAttrListener { | ||
/** | ||
* Constructor for the DataAttrListener class. | ||
*/ | ||
public function __construct() { | ||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_data_attr_listener' ) ); | ||
} | ||
|
||
/** | ||
* Enqueues the data-* attribute listener script. | ||
* | ||
* @return void | ||
*/ | ||
public function enqueue_data_attr_listener() { | ||
$asset_file = NFD_INSTALLER_BUILD_DIR . '/dataAttrListener.asset.php'; | ||
|
||
if ( is_readable( $asset_file ) ) { | ||
|
||
$asset = include $asset_file; | ||
|
||
wp_register_script( | ||
'nfd-installer-data-attr-listener', | ||
NFD_INSTALLER_BUILD_URL . '/dataAttrListener.js', | ||
array_merge( $asset['dependencies'], array() ), | ||
$asset['version'], | ||
true | ||
); | ||
|
||
wp_add_inline_script( | ||
'nfd-installer-data-attr-listener', | ||
'var nfdInstallerDataAttrListener =' . wp_json_encode( | ||
array( | ||
'restUrl' => \get_home_url() . '/index.php?rest_route=', | ||
) | ||
) . ';', | ||
'before' | ||
); | ||
|
||
wp_enqueue_script( 'nfd-pls-data-attr-installer' ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace NewfoldLabs\WP\Module\Installer\WPAdmin; | ||
|
||
use NewfoldLabs\WP\Module\PLS\WPAdmin\Listeners\DataAttrListener; | ||
|
||
/** | ||
* Manages all the wp-admin related functionalities for the module. | ||
*/ | ||
class WPAdmin { | ||
/** | ||
* Constructor for the WPAdmin class. | ||
*/ | ||
public function __construct() { | ||
new DataAttrListener(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
{ | ||
"version": "1.0.0", | ||
"name": "@newfold-labs/wp-module-installer", | ||
"description": "An installer for WordPress plugins and themes.", | ||
"license": "GPL-2.0-or-later", | ||
"private": true, | ||
"author": { | ||
"name": "Micah Wood", | ||
"email": "[email protected]" | ||
}, | ||
"devDependencies": { | ||
"@wordpress/scripts": "^26.10.0" | ||
}, | ||
"scripts": { | ||
"build": "wp-scripts build ./src/ ./src/Scripts/dataAttrListener.js", | ||
"start": "wp-scripts start ./src/ ./src/Scripts/dataAttrListener.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import domReady from '@wordpress/dom-ready'; | ||
import apiFetch from '@wordpress/api-fetch'; | ||
|
||
import { installerAPI } from '../constants'; | ||
|
||
domReady( () => { | ||
const domObserver = new window.MutationObserver( ( mutationList ) => { | ||
} ); | ||
|
||
domObserver.observe( document.body, { childList: true, subtree: true } ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const wpRestURL = window.nfdInstallerDataAttrListener?.restUrl; | ||
export const dataRestRoute = 'newfold-installer/v1'; | ||
export const installerAPI = `${ wpRestURL }/${ dataRestRoute }/events`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const path = require( 'path' ); | ||
const { merge } = require( 'webpack-merge' ); | ||
const wpScriptsConfig = require( '@wordpress/scripts/config/webpack.config' ); | ||
const version = require( './package.json' ).version; // never require full config! | ||
|
||
const nfdSurveyWebpackConfig = { | ||
output: { | ||
path: path.resolve( process.cwd(), `build/${ version }` ), | ||
library: [ 'newfold', 'Survey', '[name]' ], | ||
libraryTarget: 'window', | ||
}, | ||
}; | ||
|
||
module.exports = merge( wpScriptsConfig, nfdSurveyWebpackConfig ); |