Skip to content

Commit

Permalink
standalone script now building to es5
Browse files Browse the repository at this point in the history
  • Loading branch information
benkeen committed Jan 2, 2023
1 parent 075a439 commit a399863
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 35 deletions.
9 changes: 5 additions & 4 deletions client/src/utils/generalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const setTourComponents = (tour: any): void => {

export const getTourComponents = (): any => tourComponents;

export const isSafari = navigator?.vendor && navigator.vendor.indexOf('Apple') > -1 &&
navigator.userAgent &&
navigator.userAgent.indexOf('CriOS') == -1 &&
navigator.userAgent.indexOf('FxiOS') == -1;
export const isSafari = false;
// navigator && navigator?.vendor && navigator?.vendor.indexOf('Apple') > -1 &&
// navigator?.userAgent &&
// navigator?.userAgent.indexOf('CriOS') == -1 &&
// navigator?.userAgent.indexOf('FxiOS') == -1;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"cookie-parser": "^1.4.5",
"date-fns": "^2.17.0",
"dotenv": "^8.2.0",
"esbuild": "^0.16.12",
"express": "^4.17.1",
"google-auth-library": "^6.1.3",
"googleapis": "^65.0.0",
Expand Down Expand Up @@ -130,6 +131,7 @@
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.7.4",
"@babel/preset-react": "^7.7.4",
"@esbuild-plugins/tsconfig-paths": "^0.0.4",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^8.4.0",
"@teamsupercell/typings-for-css-modules-loader": "^2.1.0",
Expand Down Expand Up @@ -202,10 +204,10 @@
"sass-loader": "^8.0.0",
"sinon": "^8.0.4",
"style-loader": "^1.0.0",
"tsconfig-paths": "4.1.1",
"ts-jest": "^25.5.1",
"ts-loader": "^6.2.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "4.1.1",
"typescript": "^3.9.8",
"use-onclickoutside": "^0.3.1",
"webpack": "^4.46.0",
Expand Down
2 changes: 1 addition & 1 deletion standalone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ This is the npm package + binary version of generatedata.

### Local dev

- `yarn build` - generates the standalone i18n JSON files. Note: requires the main client to have been built first.
- `yarn build` - generates the standalone i18n JSON files. Note: requires the main client/ application to have been built first.
- `yarn dev` - runs index.ts for testing purposes
File renamed without changes.
15 changes: 15 additions & 0 deletions standalone/build/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { TsconfigPathsPlugin } from '@esbuild-plugins/tsconfig-paths';
import { build } from 'esbuild';

build({
entryPoints: ['../src/index.ts'],
plugins: [
TsconfigPathsPlugin({ tsconfig: 'tsconfig.json' })
],
outdir: '../dist/',
platform: 'node',
target: 'node12',
format: 'cjs',
bundle: true,
external: ['canvas', './xhr-sync-worker.js']
});
6 changes: 6 additions & 0 deletions standalone/build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "generatedata-standalone",
"description": "Build script",
"private": true,
"type": "module"
}
6 changes: 3 additions & 3 deletions standalone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "The npm package and binary version of generatedata.com",
"private": true,
"scripts": {
"build": "grunt",
"dev": "npx ts-node -r tsconfig-paths/register src/index.ts",
"dev2": "../node_modules/typescript/bin/tsc --noEmit"
"build": "npx grunt && cd build && node build.js",
"test": ""
}
}

33 changes: 19 additions & 14 deletions standalone/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
require('browser-env')();
// require('browser-env')();

import {
DataTypeGenerationOptions,
DataTypeWorkerInterface,
ExportType,
GDTemplate,
WorkerInterface
GDTemplate
} from '~types/generator';
import { DataType } from '../../client/_plugins';
import { dataTypeNodeData, exportTypeNodeData } from '../_standalone';
import countryNames from '../../client/_namePlugins';
import { generate } from '../../client/src/utils/generatorUtils';
import { generate as generateUtils } from '../../client/src/utils/generatorUtils';
import workerUtils from '../../client/src/utils';
import { getI18nStrings } from './utils/i18n';
import { GDLocale, GenerationTemplate } from '~types/general';
import { DTGenerateResult, DTGenerationData } from '~types/dataTypes';
import { convertRowsToGenerationTemplate } from '~store/generator/generator.selectors';
import path from "path";
import fs from "fs";

// no point requiring users to supply a colIndex. We can add that ourselves.
// export type DataTypeGenerationOptionsWithColIndex = DataTypeGenerationOptions & {
// colIndex: number;
// }
export const getI18nStrings = (locale: GDLocale): any => {
const localeFile = path.join(__dirname, `../dist/${locale}.json`);
return JSON.parse(fs.readFileSync(localeFile, 'utf8'));
};

/**
* Used by both the node and binary scripts. It takes the user's template and fluffs it out with all the necessary
Expand Down Expand Up @@ -52,17 +52,22 @@ const getColumns = (rows: DataTypeGenerationOptions[]) => {
// id
};

const doStuff = (template: GDTemplate) => {
/**
* This'll be the primary export.
* @param template
*/
export const generate = (template: GDTemplate) => {
const normalizedTemplate = getNormalizedGDTemplate(template);
const i18n = getI18nStrings(normalizedTemplate.generationSettings.locale as GDLocale)
const dataTypeInterface = getWorkerInterface();
const exportTypeInterface = getExportTypeWorkerInterface(normalizedTemplate.exportSettings.plugin);

const onComplete = (data: string) => {
console.log('!!!!!!', data);
console.log('!!!!!!');
return data;
};

generate(normalizedTemplate, {
generateUtils(normalizedTemplate, {
i18n,
workerUtils,
dataTypeInterface,
Expand Down Expand Up @@ -135,7 +140,7 @@ const getExportTypeWorkerInterface = (exportType: ExportType) => {
(async () => {
const template: GDTemplate = {
generationSettings: {
numResults: 10
numResults: 1000
},
dataTemplate: [
{
Expand All @@ -161,5 +166,5 @@ const getExportTypeWorkerInterface = (exportType: ExportType) => {
}
};

await doStuff(template);
await generate(template);
})();
8 changes: 0 additions & 8 deletions standalone/src/utils/i18n.ts

This file was deleted.

3 changes: 2 additions & 1 deletion standalone/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"allowSyntheticDefaultImports": true,
"removeComments": true,
"baseUrl": "../",
"jsx": "react",
"importsNotUsedAsValues": "remove",
"paths": {
"~components/*": ["client/src/components/*"],
"~utils/*": ["client/src/utils/*"],
Expand All @@ -25,7 +27,6 @@
},
"exclude": [
"node_modules",
"types",
"typings"
]
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"jsx": "react",
"allowSyntheticDefaultImports": true,
"removeComments": false,
"baseUrl": "",
"baseUrl": "./",
"paths": {
"~components/*": ["client/src/components/*"],
"~utils/*": ["client/src/utils/*"],
Expand Down
Loading

0 comments on commit a399863

Please sign in to comment.