New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@smartface/builder

Package Overview
Dependencies
Maintainers
4
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smartface/builder - npm Package Compare versions

Comparing version 1.0.0-alpha.21 to 1.0.0-alpha.22

assets/ts/themes/defaultTheme/styles/__generated_default_theme.json

4

package.json
{
"name": "@smartface/builder",
"version": "1.0.0-alpha.21",
"version": "1.0.0-alpha.22",
"description": "Smartface Builder",

@@ -43,3 +43,3 @@ "bin": {

},
"gitHead": "dc16c0ca0e921e9f72d203386ec0463932fdcead"
"gitHead": "737d64d898a0406cdd5a7adb0adfbdaea97cb452"
}

@@ -14,3 +14,2 @@ const fs = require('fs-extra');

const normalizePath = require('./util/normalizePath');
const { writeFile } = require('fs');
const writeError = util.writeError;

@@ -59,18 +58,17 @@

comp.coreLibPath = normalizePath(coreLibPath);
let res;
let genResult;
if (comp.type === 'BottomTabbar') {
res = generateOneComponent(comp, routerUiFolder, templateBottomTabbarRouter);
createComponentRouterFile(res, routerUiFolder);
genResult = generateOneComponent(comp, routerUiFolder, templateBottomTabbarRouter);
createComponentRouterFile(genResult, routerUiFolder);
} else {
res = generateOneComponent(comp, libraryUiFolder, templateComponent);
createComponentFile(res, libraryUiFolder);
await createLibraryUserFileIfDoesNotExist(res);
createUserListItemsOfComponent(comp);
/*
if (!res.initialized && !res.oldName) {
} else if (res.oldName) {
console.info('MOVE comp.', res);
//moveComponentUserFile(res);
genResult = generateOneComponent(comp, libraryUiFolder, templateComponent);
createComponentFile(genResult, libraryUiFolder);
if (!genResult.oldName) {
await createLibraryUserFileIfDoesNotExist(genResult);
createUserListItemsOfComponent(genResult, comp);
} else if (genResult.oldName) {
await moveComponentUserFile(genResult);
await moveComponentFlatListItemUserFile(genResult, comp);
util.removeFile(genResult.userOldFolderPath);
}
*/
}

@@ -92,2 +90,18 @@ });

oldName: comp.oldName,
userOldFolderPath: comp.oldName
? path.dirname(
prepareOutputFilePath(
projectType,
path.join(getPath('LIBRARY_USER_FOLDER'), comp.oldName),
'index'
)
)
: '',
userFolderPath: path.dirname(
prepareOutputFilePath(
projectType,
path.join(getPath('LIBRARY_USER_FOLDER'), comp.libraryType),
'index'
)
),
changed: false

@@ -118,5 +132,5 @@ };

function removePassiveComponentFiles() {
for (var tranp in transpilers) {
for (let tranp in transpilers) {
if (!transpilers[tranp].active) {
util.removeFile(tranp.outputPath).then(res => {
util.removeFile(transpilers[tranp].outputPath).then(res => {
res && delete transpilers[tranp];

@@ -149,7 +163,3 @@ });

async function createLibraryUserFileIfDoesNotExist(opt) {
const userFilePath = prepareOutputFilePath(
projectType,
path.join(getPath('LIBRARY_USER_FOLDER'), opt.name),
'index'
);
const userFilePath = path.join(opt.userFolderPath, 'index.tsx');
return util.isExistsFileDir(userFilePath).then(res => {

@@ -163,11 +173,19 @@ if (!res.existing || (res.existing && res.dir)) {

function createUserListItemsOfComponent(comp) {
function createUserListItemsOfComponent(genResult, comp) {
const templateListItem = templateEngine('userListItem');
comp.flatListItems.forEach(async item => {
let filePath = prepareOutputFilePath(
projectType,
path.join(getPath('LIBRARY_USER_FOLDER'), comp.name),
`${util.capitalizeFirstLetter(comp.name)}${util.capitalizeFirstLetter(item.varName)}Item`
let oldFilePath = path.join(
genResult.userFolderPath,
`${util.capitalizeFirstLetter(comp.name)}${util.capitalizeFirstLetter(
item.oldName
)}Item.tsx`
);
const res = util.isExistsFileDir(filePath);
let newFilePath = path.join(
genResult.userFolderPath,
`${util.capitalizeFirstLetter(comp.name)}${util.capitalizeFirstLetter(
item.varName
)}Item.tsx`
);
const oldRes = item.oldName ? await util.isExistsFileDir(oldFilePath) : {};
const newRes = await util.isExistsFileDir(newFilePath);
let data = templateListItem({

@@ -177,23 +195,62 @@ designFilePath: `@smartface-generated/components/${util.capitalizeFirstLetter(comp.name)}`,

});
if (!res.existing || (res.existing && res.dir)) {
fs.writeFile(filePath, data);
if (newRes.existing && newRes.file) {
return;
}
if (oldRes.existing && oldRes.file) {
let content = await fs.readFile(oldFilePath, 'utf-8');
data = content.replaceAll(
`${util.capitalizeFirstLetter(item.oldName)}Item`,
`${util.capitalizeFirstLetter(item.varName)}Item`
);
await fs.writeFile(newFilePath, data, { encoding: 'utf-8' });
await util.removeFile(oldFilePath);
await removeOldNameProp(genResult);
} else {
fs.writeFile(newFilePath, data, { encoding: 'utf-8' });
}
});
}
async function moveComponentUserFile(compRes) {
const oldUserFilePath = prepareOutputFilePath(
projectType,
getPath('LIBRARY_USER_FOLDER'),
util.capitalizeFirstLetter(compRes.oldName)
async function moveComponentFlatListItemUserFile(genResult, comp) {
await Promise.all(
comp.flatListItems.map(async item => {
let filePath = path.join(
genResult.userOldFolderPath,
`${util.capitalizeFirstLetter(comp.oldName)}${util.capitalizeFirstLetter(
item.varName
)}Item.tsx`
);
let newFilePath = path.join(
genResult.userFolderPath,
`${util.capitalizeFirstLetter(comp.name)}${util.capitalizeFirstLetter(
item.varName
)}Item.tsx`
);
const res = await util.isExistsFileDir(filePath);
if (!res.existing || (res.existing && res.dir)) {
//Ignore not exists old file
return;
}
let content = await fs.readFile(filePath, 'utf-8');
content = content.replaceAll(
`@smartface-generated/components/${util.capitalizeFirstLetter(comp.oldName)}`,
`@smartface-generated/components/${util.capitalizeFirstLetter(comp.name)}`
);
return fs.writeFile(newFilePath, content, 'utf-8');
})
);
const newUserFilePath = prepareOutputFilePath(
projectType,
getPath('LIBRARY_USER_FOLDER'),
util.capitalizeFirstLetter(compRes.name)
);
}
async function moveComponentUserFile(compRes) {
const oldUserFilePath = path.join(compRes.userOldFolderPath, 'index.tsx');
const newUserFilePath = path.join(compRes.userFolderPath, 'index.tsx');
const existingResOld = await util.isExistsFileDir(oldUserFilePath);
const existingResNew = await util.isExistsFileDir(newUserFilePath);
console.log('|--- moveComponentUserFile \n|- ', oldUserFilePath, '\n|- ', newUserFilePath);
console.log(
'|--- Move - ComponentUserFile \n|- ',
compRes.userOldFolderPath,
'\n|- ',
compRes.userFolderPath,
'\n|----------------------------'
);
if (

@@ -204,4 +261,6 @@ existingResOld.existing &&

) {
await fs.move(oldUserFilePath, newUserFilePath, { overwrite: true });
await fixImportStatement(newUserFilePath, compRes);
const code = await fs.readFile(oldUserFilePath, { encoding: 'utf-8' });
const resultCodeString = applyComponentNameChanges(code, compRes);
util.mkdirpSync(path.dirname(newUserFilePath));
await fs.writeFile(newUserFilePath, resultCodeString, { encoding: 'utf-8' });
await removeOldNameProp(compRes);

@@ -226,14 +285,12 @@ } else if (!existingResOld.existing || existingResOld.dir) {

async function fixImportStatement(newUserFilePath, compRes) {
function applyComponentNameChanges(codeString, compRes) {
const oldVarName = util.capitalizeFirstLetter(compRes.oldName);
const newVarName = util.capitalizeFirstLetter(compRes.name);
const text = await fs.readFile(newUserFilePath, 'utf-8');
const lines = text.split('\n');
lines.forEach((line, index) => {
if (importExportRegex.test(line) && line.includes(oldVarName)) {
lines[index] = line.replaceAll(oldVarName, newVarName);
}
});
await fs.writeFile(newUserFilePath, lines.join('\n', 'utf-8'));
let resultCodeString = codeString
.replaceAll(`/${oldVarName}`, `/${newVarName}`)
.replaceAll(`${oldVarName}Design`, `${newVarName}Design`)
.replaceAll(`I${oldVarName}`, `I${newVarName}`)
.replaceAll(`${oldVarName}Props`, `${newVarName}Props`);
return resultCodeString;
}

@@ -243,20 +300,25 @@

setWatcherEnabledStatus(false);
try {
const cpxFilePath = path.join(
libraryCpxFolder,
util.lowercaseFirstLetter(compRes.name) + `.cpx`
);
const content = await fs.readJSON(cpxFilePath);
content.components[0].oldName = undefined;
await fs.writeJSON(cpxFilePath, content, { spaces: '\t', overwrite: true });
} catch (e) {
writeError(
{
file: cpxFilePath,
stack: e.stack
},
'ComponentSourceFile Writing Error'
);
}
setTimeout(() => setWatcherEnabledStatus(true), 300);
const cpxFilePath = path.join(
libraryCpxFolder,
util.lowercaseFirstLetter(compRes.name) + `.cpx`
);
const content = await fs.readJSON(cpxFilePath);
content.components.forEach(c => (c.oldName = undefined));
return new Promise((resolve, reject) => {
fs.writeJSON(cpxFilePath, content, { spaces: '\t', overwrite: true }, err => {
if (err) {
writeError(
{
file: cpxFilePath,
stack: e.stack
},
'ComponentSourceFile Writing Error'
);
}
setTimeout(() => {
setWatcherEnabledStatus(true);
resolve();
}, 300);
});
});
}

@@ -263,0 +325,0 @@

@@ -170,3 +170,14 @@ const fs = require('fs-extra');

parsedObjectData.coreLibPath = normalizePath(coreLibPath);
if (!parsedObjectData.oldName) {
let hasOldName = false;
if (parsedObjectData.oldName) {
await movePageUserFile(parsedObjectData.oldName, parsedObjectData.name);
await moveUserListItemsOfPage(
parsedObjectData.oldName,
parsedObjectData.name,
parsedObjectData.footer.flatListItems
);
await moveHeaderBarOfPage(parsedObjectData.oldName, parsedObjectData.name);
util.removeFile(path.join(pagesFolder, parsedObjectData.oldName));
hasOldName = true;
} else {
createUserPageIfDoesNotExist({

@@ -177,14 +188,18 @@ pageName: parsedObjectData.name,

});
} else if (parsedObjectData.oldName) {
await movePageUserFile(parsedObjectData.name, parsedObjectData.oldName, pgx, filePath);
let listItemRes = await createUserListItemsOfPage(
parsedObjectData.name,
parsedObjectData.footer.flatListItems
);
hasOldName = hasOldName || listItemRes.hasOldName;
createHeaderBarOfPage(
parsedObjectData.name,
parsedObjectData.footer.headerBar,
pgx,
filePath
);
}
createUserListItemsOfPage(parsedObjectData.name, parsedObjectData.footer.flatListItems);
createHeaderBarOfPage(
parsedObjectData.name,
parsedObjectData.footer.headerBar,
pgx,
filePath
);
emitGeneratedEvent(transpiler.generate(parsedObjectData), resFilePath, true);
if (hasOldName) {
removeOldNameProp(pgx, filePath);
}
return resFilePath;

@@ -195,22 +210,77 @@ }

function createUserListItemsOfPage(pageName, listItems) {
async function createUserListItemsOfPage(pageName, listItems) {
const templateListItem = templateEngine('userListItem');
listItems.forEach(async item => {
let filePath = path.join(
pagesFolder,
`${pageName}/${capitalizeFirstLetter(pageName)}${capitalizeFirstLetter(
item.varName
)}Item.tsx`
);
const res = await isExistsFileDir(filePath);
let data = templateListItem({
designFilePath: `@smartface-generated/pages/${pageName}`,
varName: item.varName
});
if (!res.existing || (res.existing && res.dir)) {
fs.writeFile(filePath, data);
}
});
let genResult = { hasOldName: false };
await Promise.all(
listItems.map(async item => {
let oldFilePath = item.oldName
? path.join(
pagesFolder,
`${pageName}/${capitalizeFirstLetter(pageName)}${capitalizeFirstLetter(
item.oldName
)}Item.tsx`
)
: '';
let newFilePath = path.join(
pagesFolder,
`${pageName}/${capitalizeFirstLetter(pageName)}${capitalizeFirstLetter(
item.varName
)}Item.tsx`
);
const oldRes = item.oldName ? await isExistsFileDir(oldFilePath) : {};
const newRes = await isExistsFileDir(newFilePath);
let data = templateListItem({
designFilePath: `@smartface-generated/pages/${pageName}`,
varName: item.varName
});
if (newRes.existing && newRes.file) {
return;
}
if (oldRes.existing && oldRes.file) {
let content = await fs.readFile(oldFilePath, 'utf-8');
genResult.hasOldName = true;
data = content.replaceAll(
`${util.capitalizeFirstLetter(item.oldName)}Item`,
`${util.capitalizeFirstLetter(item.varName)}Item`
);
await fs.writeFile(newFilePath, data, { encoding: 'utf-8' });
await util.removeFile(oldFilePath);
} else {
fs.writeFile(newFilePath, data, { encoding: 'utf-8' });
}
})
);
return genResult;
}
async function moveUserListItemsOfPage(oldPageName, pageName, listItems) {
return await Promise.all(
listItems.map(async item => {
let oldFilePath = path.join(
pagesFolder,
`${oldPageName}/${capitalizeFirstLetter(oldPageName)}${capitalizeFirstLetter(
item.varName
)}Item.tsx`
);
let newFilePath = path.join(
pagesFolder,
`${pageName}/${capitalizeFirstLetter(pageName)}${capitalizeFirstLetter(
item.varName
)}Item.tsx`
);
const oldRes = await util.isExistsFileDir(oldFilePath);
if (!oldRes.existing || (oldRes.existing && oldRes.dir)) {
//Ignore not exists old file
return;
}
let content = await fs.readFile(oldFilePath, 'utf-8');
content = content.replaceAll(
`@smartface-generated/pages/${oldPageName}`,
`@smartface-generated/pages/${pageName}`
);
return fs.writeFile(newFilePath, content, 'utf-8');
})
);
}
async function createHeaderBarOfPage(pageName, headerBar, pgx, pgxFilePath) {

@@ -227,13 +297,28 @@ const templateHeaderBar = templateEngine('headerBar');

if (!res.existing || (res.existing && res.dir)) {
console.log('Header Not Found', res);
fs.writeFile(filePath, data);
} else if (rootComp && rootComp.oldName && rootComp.oldName !== rootComp.varName) {
console.log('Header oldName', rootComp.oldName);
let existingData = await fs.readFile(filePath, 'utf8');
existingData = existingData.replace(`${rootComp.oldName}=`, `${rootComp.varName}=`);
fs.writeFile(filePath, existingData);
removeOldNameProp(pgx, rootComp.id, pgxFilePath);
}
}
async function moveHeaderBarOfPage(oldPageName, pageName) {
let oldFilePath = path.join(pagesFolder, `${oldPageName}/${oldPageName}HeaderBar.tsx`);
let newFilePath = path.join(pagesFolder, `${pageName}/${pageName}HeaderBar.tsx`);
const oldRes = await util.isExistsFileDir(oldFilePath);
if (!oldRes.existing || (oldRes.existing && oldRes.dir)) {
//Ignore not exists old file
return;
}
let content = await fs.readFile(oldFilePath, 'utf-8');
content = content
.replaceAll(
`@smartface-generated/pages/${oldPageName}`,
`@smartface-generated/pages/${pageName}`
)
.replaceAll(
`${util.capitalizeFirstLetter(oldPageName)}HeaderView`,
`${util.capitalizeFirstLetter(pageName)}HeaderView`
);
return fs.writeFile(newFilePath, content, 'utf-8');
}
function createUserPageIfDoesNotExist(opt) {

@@ -265,9 +350,15 @@ var userFilePath = path.join(pagesFolder, `${opt.pageName}/index.tsx`);

async function movePageUserFile(pageName, oldPageName, pgx, pgxFilePath) {
const oldUserFilePath = path.join(pagesFolder, `${oldPageName}.${projectType}`);
const newUserFilePath = path.join(pagesFolder, `${pageName}.${projectType}`);
async function movePageUserFile(oldPageName, pageName) {
const oldUserFilePath = path.join(pagesFolder, `${oldPageName}/index.tsx`);
const newUserFilePath = path.join(pagesFolder, `${pageName}/index.tsx`);
const existingResOld = await isExistsFileDir(oldUserFilePath);
const existingResNew = await isExistsFileDir(newUserFilePath);
console.log('|--- movePageUserFile \n|- ', oldUserFilePath, '\n|- ', newUserFilePath);
console.log(
'|--- Move - PageUserFile \n|- ',
oldUserFilePath,
'\n|- ',
newUserFilePath,
'\n|----------------------- '
);
if (

@@ -278,7 +369,27 @@ existingResOld.existing &&

) {
await fs.move(oldUserFilePath, newUserFilePath, { overwrite: true });
await fixImportStatement(newUserFilePath, { name: pageName, oldName: oldPageName });
await removeOldNameProp(pgx, pgx.components[0].id, pgxFilePath);
let content = await fs.readFile(oldUserFilePath, 'utf-8');
util.mkdirpSync(path.dirname(newUserFilePath));
content = content
.replaceAll(
`@smartface-generated/pages/${oldPageName}`,
`@smartface-generated/pages/${pageName}`
)
.replaceAll(
`@app/pages/${oldPageName}/${oldPageName}HeaderBar`,
`@app/pages/${pageName}/${pageName}HeaderBar`
)
.replaceAll(
`${util.capitalizeFirstLetter(oldPageName)}Design`,
`${util.capitalizeFirstLetter(pageName)}Design`
)
.replaceAll(
`I${util.capitalizeFirstLetter(oldPageName)}Props`,
`I${util.capitalizeFirstLetter(pageName)}Props`
)
.replaceAll(
`${util.capitalizeFirstLetter(oldPageName)}Options`,
`${util.capitalizeFirstLetter(pageName)}Options`
);
await fs.writeFile(newUserFilePath, content, 'utf-8');
} else if (existingResNew.existing && !existingResNew.dir) {
await removeOldNameProp(pgx, pgx.components[0].id, pgxFilePath);
} else {

@@ -297,39 +408,23 @@ writeError(

async function fixImportStatement(newUserFilePath, compRes) {
const oldVarName = util.capitalizeFirstLetter(compRes.oldName);
const newVarName = util.capitalizeFirstLetter(compRes.name);
const text = await fs.readFile(newUserFilePath, 'utf-8');
const lines = text.split('\n');
lines.forEach((line, index) => {
if (importExportRegex.test(line) && line.includes(oldVarName)) {
lines[index] = line
.replaceAll(oldVarName, newVarName)
.replaceAll(compRes.oldName, compRes.name);
}
async function removeOldNameProp(content, pgxFilePath) {
content.components.forEach(c => (c.oldName = undefined));
watcherEnabledStatusFunc(false);
return new Promise((resolve, reject) => {
fs.writeJSON(pgxFilePath, content, { spaces: '\t', overwrite: true }, err => {
if (err) {
writeError(
{
file: newUserFilePath,
stack: e.stack
},
'PageSourceFile Writing Error'
);
}
setTimeout(() => {
watcherEnabledStatusFunc(true);
resolve();
}, 400);
});
});
await fs.writeFile(newUserFilePath, lines.join('\n', 'utf-8'));
}
async function removeOldNameProp(content, compId, pgxFilePath) {
const comp = content.components.find(c => c.id === compId);
if (!comp) {
return;
}
watcherEnabledStatusFunc(false);
try {
comp.oldName = undefined;
await fs.writeJSON(pgxFilePath, content, { spaces: '\t', overwrite: true });
watcherEnabledStatusFunc(false);
} catch (e) {
writeError(
{
file: newUserFilePath,
stack: e.stack
},
'PageSourceFile Writing Error'
);
}
setTimeout(() => watcherEnabledStatusFunc(true), 400);
}
}

@@ -336,0 +431,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc