Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions build.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-nested-ternary */
/* eslint-disable no-underscore-dangle */
process.env.ENV_FILE !== null && require('dotenv').config({ path: process.env.ENV_FILE });
// process.env.ENV_FILE !== null && require('dotenv').config({ path: process.env.ENV_FILE });

const __API_SERVER_PORT__ = process.env.GRAPHQL_URL ? new URL(process.env.GRAPHQL_URL).port : 8080;
const __WEB_SERVER_PORT__ = process.env.LOCAL_BACKEND_URL ? new URL(process.env.LOCAL_BACKEND_URL).port : 3000;
Expand Down Expand Up @@ -29,5 +29,4 @@ const config = {
process.env.LOCAL_BACKEND_URL || `${__SERVER_PROTOCOL__}://${__LOCAL_SERVER_HOST__}:${__WEB_SERVER_PORT__}`,
};

console.log('---CONFIG', config);
module.exports = config;
1 change: 0 additions & 1 deletion buildconfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ const config = {
process.env.LOCAL_BACKEND_URL || `${__SERVER_PROTOCOL__}://${__LOCAL_SERVER_HOST__}:${__WEB_SERVER_PORT__}`,
};

console.log('---CONFIG', config);
export default config;
4 changes: 3 additions & 1 deletion codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ generates:
withMutationFn: false
withHOC: false
withComponent: false
noGraphQLTag: true
plugins:
- add:
content: /* tslint:disable */
Expand All @@ -33,8 +34,9 @@ generates:
config:
withMutationFn: false
withHOC: false
withComponent: true
withComponent: false
withHooks: true
noGraphQLTag: true
preset: import-types-preset
presetConfig:
typesPath: "../generated-models"
Expand Down
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
]
},
"resolutions": {
"@apollo/client": "~3.6.10",
"@apollo/client": "^3.9.0",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.8",
"chokidar": "^3.5.3",
Expand All @@ -129,6 +129,7 @@
"devDependencies": {
"@babel/cli": "^7.19.3",
"@babel/core": "^7.20.2",
"@babel/parser": "^7.20.1",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.20.2",
"@babel/plugin-proposal-export-default-from": "^7.18.10",
Expand All @@ -137,6 +138,7 @@
"@babel/plugin-proposal-object-rest-spread": "^7.20.2",
"@babel/plugin-proposal-optional-chaining": "^7.18.9",
"@babel/plugin-proposal-pipeline-operator": "^7.18.9",
"@babel/generator": "^7.20.1",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-export-default-from": "^7.18.6",
"@babel/plugin-syntax-export-namespace-from": "^7.8.3",
Expand All @@ -147,13 +149,15 @@
"@babel/plugin-transform-modules-commonjs": "^7.19.6",
"@babel/plugin-transform-regenerator": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/polyfill": "7.12.1",
"@babel/types": "^7.20.0",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.20.2",
"@babel/preset-flow": "^7.18.6",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/register": "^7.18.9",
"@babel/runtime": "^7.20.1",
"@babel/traverse": "^7.20.1",
"@common-stack/env-list-loader": "0.5.8",
"@emotion/babel-plugin": "^11.11.0",
"@graphql-codegen/add": "^5.0.2",
Expand All @@ -173,10 +177,14 @@
"@redux-devtools/core": "^3.13.1",
"@redux-devtools/dock-monitor": "^3.0.1",
"@redux-devtools/log-monitor": "^4.0.1",
"@remix-run/dev": "^2.8.1",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-graphql": "2.0.2",
"@rollup/plugin-image": "^3.0.1",
"@rollup/plugin-json": "^5.0.2",
"@rollup/plugin-typescript": "^9.0.2",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@rollup/pluginutils": "^5.1.0",
"@shelf/jest-mongodb": "^4.1.3",
"@svgr/webpack": "^6.5.1",
"@testing-library/react": "^13.4.0",
Expand Down Expand Up @@ -316,8 +324,8 @@
"remap-istanbul": "^0.13.0",
"resolve-url-loader": "^5.0.0",
"rimraf": "^3.0.2",
"rollup": "^3.2.5",
"rollup-plugin-esbuild": "^5.0.0",
"rollup": "^4.13.0",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-string": "^3.0.0",
"sass-loader": "^13.1.0",
"shelljs": "^0.8.5",
Expand Down
110 changes: 110 additions & 0 deletions packages-modules/counter/browser/extract-dynamic-import.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import * as fs from 'fs';
import * as path from 'path';
import { createFilter } from '@rollup/pluginutils';
import { parse } from '@babel/parser';
import traverse from '@babel/traverse';
import generate from '@babel/generator';
import * as t from '@babel/types';

function findPackageJson(directory) {
let currentDir = directory;
while (currentDir !== path.parse(currentDir).root) {
const packageJsonPath = path.join(currentDir, 'package.json');
if (fs.existsSync(packageJsonPath)) {
return packageJsonPath;
}
console.log()
currentDir = path.dirname(currentDir);
}
throw new Error(`No package.json found in path ${directory}`);
}

export default function extractImportsPlugin(options = {}) {
// Create a filter to only include the desired files
const filter = createFilter(options.include, options.exclude);
const outputDir = options.outputDir || './lib'; // Default output directory

return {
name: 'extract-imports',

transform(code, id) {
// Skip files that do not match the filter
if (!filter(id)) return null;
console.log('---ID', id);

let modified = false; // Flag to check if AST was modified

console.log('--ID--', id);
console.log('--COde', code);

// Parse the code to an AST
const ast = parse(code, {
sourceType: 'module',
plugins: ['tsx', 'dynamicImport'], // Ensure dynamicImport plugin is enabled
});

// Traverse the AST to find dynamic imports
traverse.default(ast, {
enter(astroPath) {
// Adjust this part to target the specific objects and properties in your AST
if (astroPath.isObjectProperty() && astroPath.node.key.name === 'component') {
const componentValue = astroPath.node.value;

if (
componentValue.type === 'ArrowFunctionExpression' &&
componentValue.body.type === 'CallExpression' &&
componentValue.body.callee.type === 'Import'
) {
const importArg = componentValue.body.arguments[0];

// Ensure we're dealing with a string literal import path
if (importArg.type === 'StringLiteral') {
let importPath = importArg.value;

const fullPath = path.resolve(path.dirname(id), importPath);

const packageJsonPath = findPackageJson(path.dirname(path.resolve(outputDir, importPath)));
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const relativePath = path.relative(path.dirname(packageJsonPath), fullPath);
const relativePathToOutputDir = path.relative(outputDir, path.resolve(path.dirname(id), importPath));
importPath = `${relativePathToOutputDir}.js`.replace(/\\/g, '/'); // Normalize path for Windows

const newImportPath = `${packageJson.name}/${importPath}`;

// Create a new `file` property
const fileProperty = t.objectProperty(
t.identifier('file'),
t.stringLiteral(newImportPath),
);

// Get the parent object expression to add the new property
const parentObject = astroPath.findParent((p) => p.isObjectExpression());
if (parentObject) {
parentObject.node.properties.push(fileProperty);
modified = true; // Mark as modified
}
}
}
}
},
});

// If AST was modified, regenerate code
if (modified) {
const output = generate.default(
ast,
{
/* options */
},
code,
);
return {
code: output.code,
map: output.map, // Ensure source maps are handled correctly
};
}
// This plugin doesn't modify the code, so return null
return null;
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { promisify } from 'util';
import glob from 'glob';
import fs from 'fs';
import path from 'path';

const globPromise = promisify(glob.glob); // Make sure to call .glob here

export default function generateJsonFromSpecificFiles(options = {}) {
const {
pattern = '**/**/compute.js', // Pattern to match files
dist = 'lib', // Default output directory
outputFile = 'routes.json', // Output filename
} = options;

return {
name: 'aggregate-compute-routes',
async writeBundle() { // Changed from generateBundle to writeBundle
const files = await globPromise(path.join(dist, pattern), { absolute: true }); // Ensure paths are absolute
let allFilteredRoutes = [];

for (const file of files) {
try {
// Dynamically import the JS file assuming it exports filteredRoutes
const module = await import(file); // file is already absolute
if (module.filteredRoutes) {
const newRoutes = module.filteredRoutes.map((filteredRoute) => {
let routConfig = Object.values(filteredRoute)[0];
return { [routConfig.path]: routConfig };
});
allFilteredRoutes.push(...newRoutes);
}
} catch (error) {
this.warn(`Error importing ${file}: ${error}`);
}
}

// Ensure the dist directory exists
if (!fs.existsSync(dist)) {
fs.mkdirSync(dist, { recursive: true });
}

// Specify the output file path and write the aggregated filteredRoutes to a JSON file
const outputPath = path.join(dist, outputFile);
fs.writeFileSync(outputPath, JSON.stringify(allFilteredRoutes, null, 2), 'utf8');
console.log(`Aggregated filtered routes have been written to ${outputPath}`);
},
};
}
110 changes: 110 additions & 0 deletions packages-modules/counter/browser/modifyLibFilesPlugin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import fs from 'fs';
import path from 'path';
import { parse } from '@babel/parser';
import traverse from '@babel/traverse';
import generate from '@babel/generator';
import * as t from '@babel/types';
import { promisify } from 'util';
import glob from 'glob';
import { createFilter } from '@rollup/pluginutils';
const globPromise = promisify(glob.glob); // Make sure to call .glob here

function findPackageJson(directory) {
let currentDir = directory;
while (currentDir !== path.parse(currentDir).root) {
const packageJsonPath = path.join(currentDir, 'package.json');
if (fs.existsSync(packageJsonPath)) {
return packageJsonPath;
}
console.log();
currentDir = path.dirname(currentDir);
}
throw new Error(`No package.json found in path ${directory}`);
}

export default function modifyLibFilesPlugin(options = {}) {
// Create a filter to only include the desired files
const filter = createFilter(options.include, options.exclude);
const dist = options.outputDir || './lib'; // Default output directory
const pattern = '**/**/compute.js'; // Pattern to match files
return {
name: 'modify-lib-files',

async writeBundle() {
// Assuming you want to modify specific files, list them here
const filesToModify = await globPromise(path.join(dist, pattern), { absolute: true }); // Ensure paths are absolute
filesToModify.forEach((filePath) => {
if (!filter(filePath)) return; // Skip files that do not match the filter

// Read the file content
const code = fs.readFileSync(filePath, 'utf8');
// Parse the code to an AST
const ast = parse(code, {
sourceType: 'module',
plugins: ['js', 'dynamicImport'], // Adjust plugins as necessary
});

// Traverse and modify the AST as needed
let modified = false;
traverse.default(ast, {
enter(astroPath) {
// Adjust this part to target the specific objects and properties in your AST
if (astroPath.isObjectProperty() && astroPath.node.key.name === 'component') {
const componentValue = astroPath.node.value;

if (
componentValue.type === 'ArrowFunctionExpression' &&
componentValue.body.type === 'CallExpression' &&
componentValue.body.callee.type === 'Import'
) {
const importArg = componentValue.body.arguments[0];

// Ensure we're dealing with a string literal import path
if (importArg.type === 'StringLiteral') {
let importPath = importArg.value;

const fullPath = path.resolve(path.dirname(filePath), importPath);

const packageJsonPath = findPackageJson(
path.dirname(path.resolve(dist, importPath)),
);
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const relativePath = path.relative(path.dirname(packageJsonPath), fullPath);
importPath = relativePath.replace(/\\/g, '/'); // Normalize path for Windows

const newImportPath = `${packageJson.name}/${importPath}`;

// Create a new `file` property
const fileProperty = t.objectProperty(
t.identifier('file'),
t.stringLiteral(newImportPath),
);

// Get the parent object expression to add the new property
const parentObject = astroPath.findParent((p) => p.isObjectExpression());
if (parentObject) {
parentObject.node.properties.push(fileProperty);
modified = true; // Mark as modified
}
}
}
}
},
});
// If AST was modified, regenerate code
if (modified) {
const output = generate.default(
ast,
{
/* options */
},
code,
);
fs.writeFileSync(filePath, output.code); // This line actually writes the changes
}
// This plugin doesn't modify the code, so return null
return null;
});
},
};
}
Loading