Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(themeprepare): changes in themePrepare #100

Merged
merged 1 commit into from
Jan 6, 2024
Merged
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
68 changes: 35 additions & 33 deletions __appset/themePrepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const color = [
// generate exports for all platforms
const srcPath = path.resolve(__dirname, '../__appset');
const components = fs.readdirSync(srcPath).filter((files) => !ignoreFiles.includes(files) && !files.includes('WIP-'));

const srcPathInner = path.resolve(__dirname, '../__appset/universal');
const componentsInner = fs.readdirSync(srcPathInner).filter((files) => !ignoreFiles.includes(files) && !files.includes('WIP-'));

let count = 0;
// Prod:
const createDir = path.resolve(`${__dirname}`, `../../../${process.env.FE_THEME_PATH}/fe-theme`);
Expand All @@ -45,15 +49,15 @@ mkdirp(createDir).then(() => {
// const defaultDir = path.resolve(`${__dirname}`, '../__appset');

const appDir = path.resolve(`${__dirname}`, `../../../${process.env.FE_THEME_PATH}/fe-theme`);
const defaultDirData = fs.readFileSync(`${defaultDir}/${component}`).toString().split('export')[0].split('=')[1];
const defaultDirData = fs.readFileSync(`${defaultDir}/${component}`).toString().split('export')[0].split(/=(.*)/s)[1];

fs.readFile(`${appDir}/${component}`, 'utf8', (err, data) => {
const componentFile = path.resolve(createDir, component);
const replaceComponentName = component.replace('config', '').replace('.js', '');
let componentContent;

if (!err) {
const userAppConfig = data.split('export')[0].split('=')[1];
const userAppConfig = data.split('export')[0].split(/=(.*)/s)[1];
componentContent = `/* eslint-disable */
const ${replaceComponentName} = ${JSON.stringify(mergeObj(JSON.parse(defaultDirData), JSON.parse(userAppConfig)), null, '\t')}
\nexport default ${replaceComponentName};\n`;
Expand All @@ -66,9 +70,9 @@ const ${replaceComponentName} =${defaultDirData}export default ${replaceComponen
if (writeFileErr) throw writeFileErr;
console.log(color[getRandomInt(color.length)].value, ` ${count + 1}. generated: ${componentFile} \n`);
count += 1;
if (count === components.length) {
if (count === components.length + componentsInner.length - 2) {
console.log(color[0].value, ` ${count + 1}. Generated: Package index files for package for direct import \n`);
console.log('\x1b[44m%s\x1b[0m', ` ${count + 2}. Final: Setup Completed Successfully`);
console.log('\x1b[44m%s\x1b[0m', 'Setup Completed Successfully');
console.log('');
count = 0;
}
Expand All @@ -81,9 +85,6 @@ const ${replaceComponentName} =${defaultDirData}export default ${replaceComponen
console.log('err', err);
});

const srcPathInner = path.resolve(__dirname, '../__appset/universal');
const componentsInner = fs.readdirSync(srcPathInner).filter((files) => !ignoreFiles.includes(files) && !files.includes('WIP-'));

// Prod:
const createInnerDir = path.resolve(`${__dirname}`, `../../../${process.env.FE_THEME_PATH}/fe-theme/universal`);

Expand All @@ -98,38 +99,39 @@ mkdirp(createInnerDir).then(() => {

// const appDir = path.resolve(`${__dirname}`, `../../${process.env.FE_THEME_PATH}/fe-theme/__appset/universal`);
const appDir = path.resolve(`${__dirname}`, `../../../${process.env.FE_THEME_PATH}/fe-theme/universal`);
const defaultDirData = fs.readFileSync(`${defaultDir}/${component}`).toString().split('export')[0].split('=')[1];
const defaultDirData = fs.readFileSync(`${defaultDir}/${component}`).toString().split('export')[0].split(/=(.*)/s)[1];

console.log(appDir, component);
fs.readFile(`${appDir}/${component}`, 'utf8', (err, data) => {
// console.log(data);
const componentFile = path.resolve(createInnerDir, component);
// console.log(componentFile);
// const componentContent = data;
const replaceComponentName = component.replace('config', '').replace('.js', '');
let componentContent;

if (!err) {
const userAppConfig = data.split('export')[0].split('=')[1];
componentContent = `/* eslint-disable */
const ${replaceComponentName} = ${JSON.stringify(mergeObj(JSON.parse(defaultDirData), JSON.parse(userAppConfig)), null, '\t')}
\nexport default ${replaceComponentName};\n`;
if (component === 'theme.js' || component === 'configPXL.js') {
fs.writeFile(componentFile, fs.readFileSync(`${defaultDir}/${component}`).toString(), () => {});
} else {
componentContent = `/* eslint-disable */
const ${replaceComponentName} =${defaultDirData}export default ${replaceComponentName};\n`;
}

fs.writeFile(componentFile, componentContent, (writeFileErr) => {
if (writeFileErr) throw writeFileErr;
console.log(color[getRandomInt(color.length)].value, ` ${count + 1}. generated: ${componentFile} \n`);
count += 1;
if (count === components.length) {
console.log(color[0].value, ` ${count + 1}. Generated: Package index files for package for direct import \n`);
console.log('\x1b[44m%s\x1b[0m', ` ${count + 2}. Final: Setup Completed Successfully`);
console.log('');
count = 0;
// const componentContent = data;
const replaceComponentName = component.replace('config', '').replace('.js', '');
let componentContent;

if (!err) {
const userAppConfig = data.split('export')[0].split(/=(.*)/s)[1];
componentContent = `/* eslint-disable */
const ${replaceComponentName} = ${JSON.stringify(mergeObj(JSON.parse(defaultDirData), JSON.parse(userAppConfig)), null, '\t')}
\nexport default ${replaceComponentName};\n`;
} else {
componentContent = `/* eslint-disable */
const ${replaceComponentName} =${defaultDirData}export default ${replaceComponentName};\n`;
}
});

fs.writeFile(componentFile, componentContent, (writeFileErr) => {
if (writeFileErr) throw writeFileErr;
console.log(color[getRandomInt(color.length)].value, ` ${count + 1}. generated: ${componentFile} \n`);
count += 1;
if (count === components.length + componentsInner.length - 2) {
console.log('\x1b[44m%s\x1b[0m', 'Setup Completed Successfully');
console.log('');
count = 0;
}
});
}
});

return null;
Expand Down