Skip to content

Commit

Permalink
Switch everything to Common JS
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Feb 17, 2021
1 parent b391c50 commit 1513582
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 30 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

4 changes: 2 additions & 2 deletions bin/export-from-har.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ registerCoreBlocks();
const fetchFromHAR = require( 'fetch-from-har' );
const getWXRFromWixHAR = require( './lib/get-wxr-from-wix-har' );
const fs = require( 'fs' );
const wixServices = require( '../source/services/wix' );
const startExport = require( '../source/services/wix' );

const { Command } = require( 'commander' );
const program = new Command();
Expand Down Expand Up @@ -75,7 +75,7 @@ program
fetchFromHAR,
JSON.parse( fs.readFileSync( harfile ) ),
config,
wixServices
startExport
).then(
( wxr ) => console.log( wxr ) // eslint-disable-line no-console
);
Expand Down
4 changes: 2 additions & 2 deletions bin/lib/get-wxr-from-wix-har.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
async function getWXRFromWixHAR( fetchFromHAR, har, config, wixServices ) {
async function getWXRFromWixHAR( fetchFromHAR, har, config, startExport ) {
window.fetch = fetchFromHAR( har, {
queryComparison: ( requestValue, harValue, key, url ) => {
if (
Expand Down Expand Up @@ -41,7 +41,7 @@ async function getWXRFromWixHAR( fetchFromHAR, har, config, wixServices ) {
},
} );

return await wixServices.startExport( config );
return await startExport( config );
}

module.exports = getWXRFromWixHAR;
8 changes: 5 additions & 3 deletions packages/wxr/src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* External dependencies
*/
import moment from 'moment';
import { create } from 'xmlbuilder2';
const moment = require( 'moment' );
const { create } = require( 'xmlbuilder2' );

const DATE_RFC2822 = 'ddd, DD MMM YYYY HH:mm:ss [GMT]';
const DATE_MYSQL = 'YYYY-MM-DD HH:mm:ss';

/**
* Main WXR class.
*/
export default class WXR {
class WXR {
/**
* Constructor.
*/
Expand Down Expand Up @@ -378,3 +378,5 @@ export default class WXR {
} );
}
}

module.exports = WXR;
6 changes: 3 additions & 3 deletions source/background.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* WordPress dependencies
*/
import { registerCoreBlocks } from '@wordpress/block-library';
import '@wordpress/format-library';
const { registerCoreBlocks } = require( '@wordpress/block-library' );
require( '@wordpress/format-library' );

/**
* Internal dependencies
*/
import { startExport } from './services';
const startExport = require( './services' );

/**
* Store the wix config in memory, so that it's available whenever it's needed,
Expand Down
2 changes: 1 addition & 1 deletion source/content.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { saveAs } from 'file-saver';
const { saveAs } = require( 'file-saver' );

// Listen for the message to save the config.
window.addEventListener( 'message', ( e ) => {
Expand Down
4 changes: 2 additions & 2 deletions source/services/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { startExport as startWixExport } from './wix';
const startWixExport = require( './wix' );

/**
* Start the export for the given service.
*
* @param {string} service The service name. 'wix' is the only valid value at this time.
* @param {Object} config Any config data that needs to be passed to the exporter.
*/
export const startExport = ( service, config ) => {
module.exports = ( service, config ) => {
if ( service === 'wix' ) {
return startWixExport( config );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* WordPress dependencies
*/
import { createBlock, serialize } from '@wordpress/blocks';
import { applyFormat, create, toHTMLString } from '@wordpress/rich-text';
const { createBlock, serialize } = require( '@wordpress/blocks' );
const { applyFormat, create, toHTMLString } = require( '@wordpress/rich-text' );

/**
* The definition map for converting Wix blocks to WordPress blocks.
Expand Down Expand Up @@ -258,7 +258,7 @@ const formatText = ( block, entityMap ) => {
*
* @return {string} The serialized WordPress blocks.
*/
export const serializeWixBlocksToWordPressBlocks = ( wixBlocks, data ) => {
module.exports = ( wixBlocks, data ) => {
let listType = '';
const listBuffer = [];

Expand Down
4 changes: 2 additions & 2 deletions source/services/wix/extractors/communities-blog-app/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Local dependencies
*/
import { serializeWixBlocksToWordPressBlocks } from './block-mapping';
const serializeWixBlocksToWordPressBlocks = require( './block-mapping' );

export const settings = {
module.exports = {
/**
* The Wix application definition ID.
*/
Expand Down
8 changes: 4 additions & 4 deletions source/services/wix/extractors/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { settings as communitiesBlogAppSettings } from './communities-blog-app';
import { settings as siteMetaSettings } from './site-meta-app';
import { settings as mediaManagerSettings } from './media-manager';
const communitiesBlogAppSettings = require( './communities-blog-app' );
const siteMetaSettings = require( './site-meta-app' );
const mediaManagerSettings = require( './media-manager' );

/**
* An array of the defined extractors.
*/
export const extractors = [
module.exports = [
siteMetaSettings,
communitiesBlogAppSettings,
mediaManagerSettings,
Expand Down
2 changes: 1 addition & 1 deletion source/services/wix/extractors/media-manager/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const settings = {
module.exports = {
/**
* The media manager doesn't have an app definition ID, we can use a fake one here.
*/
Expand Down
2 changes: 1 addition & 1 deletion source/services/wix/extractors/site-meta-app/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const settings = {
module.exports = {
/**
* The Wix application definition ID.
*/
Expand Down
8 changes: 5 additions & 3 deletions source/services/wix/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* WordPress dependencies
*/
import WXR from '@wordpress/wxr';
const WXR = require( '@wordpress/wxr' );

/**
* Internal dependencies
*/
import { extractors } from './extractors';
const extractors = require( './extractors' );

/**
* Loop through all of the defined extractors, and run them over the content.
*
* @param {Object} config The Wix config data.
*/
export const startExport = async ( config ) => {
const startExport = async ( config ) => {
const wxr = new WXR();

await Promise.all(
Expand Down Expand Up @@ -60,3 +60,5 @@ export const startExport = async ( config ) => {

return wxr.export();
};

module.exports = startExport;

0 comments on commit 1513582

Please sign in to comment.