-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6610 from ampproject/feature/4719-site-scan
Add Site Scan Feature
- Loading branch information
Showing
79 changed files
with
4,377 additions
and
942 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
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,16 @@ | ||
/** | ||
* Get plugin slug from file path. | ||
* | ||
* If the plugin file is in a directory, then the slug is just the directory name. Otherwise, if the file is not | ||
* inside of a directory and is just a single-file plugin, then the slug is the filename of the PHP file. | ||
* | ||
* If the file path contains a file extension, it will be stripped as well. | ||
* | ||
* See the corresponding PHP logic in `\AmpProject\AmpWP\get_plugin_slug_from_file()`. | ||
* | ||
* @param {string} path Plugin file path. | ||
* @return {string} Plugin slug. | ||
*/ | ||
export function getPluginSlugFromFile( path = '' ) { | ||
return path.replace( /\/.*$/, '' ).replace( /\.php$/, '' ); | ||
} |
13 changes: 13 additions & 0 deletions
13
assets/src/common/helpers/test/get-plugin-slug-from-file.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,13 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getPluginSlugFromFile } from '../get-plugin-slug-from-file'; | ||
|
||
describe( 'getPluginSlugFromFile', () => { | ||
it( 'should return correct plugin slug', () => { | ||
expect( getPluginSlugFromFile( 'foo' ) ).toBe( 'foo' ); | ||
expect( getPluginSlugFromFile( 'foo.php' ) ).toBe( 'foo' ); | ||
expect( getPluginSlugFromFile( 'foo/bar' ) ).toBe( 'foo' ); | ||
expect( getPluginSlugFromFile( 'foo/baz.php' ) ).toBe( 'foo' ); | ||
} ); | ||
} ); |
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
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
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
41 changes: 41 additions & 0 deletions
41
assets/src/components/plugins-context-provider/__mocks__/index.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,41 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createContext } from '@wordpress/element'; | ||
|
||
export const Plugins = createContext(); | ||
|
||
/** | ||
* MOCK. | ||
* | ||
* @param {Object} props | ||
* @param {any} props.children Component children. | ||
* @param {boolean} props.fetchingPlugins Whether fetching plugins or not. | ||
* @param {Array} props.plugins An array of fetched plugins. | ||
*/ | ||
export function PluginsContextProvider( { | ||
children, | ||
fetchingPlugins = false, | ||
plugins = [], | ||
} ) { | ||
return ( | ||
<Plugins.Provider value={ | ||
{ | ||
fetchingPlugins, | ||
plugins, | ||
} | ||
}> | ||
{ children } | ||
</Plugins.Provider> | ||
); | ||
} | ||
PluginsContextProvider.propTypes = { | ||
children: PropTypes.any, | ||
fetchingPlugins: PropTypes.bool, | ||
plugins: PropTypes.array, | ||
}; |
Oops, something went wrong.