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
5
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 0.7.0 to 0.8.0-rc.1

9

index.js

@@ -10,2 +10,11 @@ const chokidar = require('chokidar');

if (!String.prototype.replaceAll) {
String.prototype.replaceAll = function (str, newStr) {
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
return this.replace(str, newStr);
}
return this.replace(new RegExp(str, 'g'), newStr);
};
}
module.exports = function (args) {

@@ -12,0 +21,0 @@ taskHandler(args);

2

package.json
{
"name": "@smartface/builder",
"version": "0.7.0",
"version": "0.8.0-rc.1",
"description": "smartface transpiler",

@@ -5,0 +5,0 @@ "bin": {

@@ -30,2 +30,3 @@ const path = require("path");

const uiFolder = getPath("UI_FOLDER");
let watcherEnabled = true;

@@ -46,2 +47,5 @@ this.start = watcherHandler => {

const _start = watcherHandler => {
watcherHandler.setWatcherEnabledStatusFunc((enabled) => {
watcherEnabled = enabled;
});
styleGeneration.initFolderPaths();

@@ -69,2 +73,5 @@ status = WATCHER_STATUS.RUNNING;

watcherPgxFolder.on("all", (eventType, filename) => {
if (!watcherEnabled) {
return console.warn('ā”œā”€> Ignore Change > ', eventType, filename);
}
if (eventType === "unlinkDir" && filename === pgxFolder)

@@ -74,3 +81,3 @@ return stop();

return;
if (new RegExp(`library${'\\'+path.sep}.*\.(pgx|cpx)`).test(filename)) {
if (new RegExp(`library${'\\' + path.sep}.*\.(pgx|cpx)`).test(filename)) {
return; //skip library folder.

@@ -117,3 +124,3 @@ }

return console.log("Watcher has already been stopped!");
}!_opt.silent && util.writeError(new Error(`Check Following Folders Exist\n - ${pgxFolder}\n - ${themesFolder}`),
} !_opt.silent && util.writeError(new Error(`Check Following Folders Exist\n - ${pgxFolder}\n - ${themesFolder}`),
status === WATCHER_STATUS.RUNNING ? "Watcher Unlink Error" : "Watcher Starting Error");

@@ -133,3 +140,3 @@ status = WATCHER_STATUS.STOPPED;

function generateStyles() {
styleGeneration.generateStyles().then(res => {}, err => util.writeError(err, "Watcher -> Generating Styles Error"));
styleGeneration.generateStyles().then(res => { }, err => util.writeError(err, "Watcher -> Generating Styles Error"));
}

@@ -136,0 +143,0 @@ }

@@ -7,2 +7,3 @@ const LibraryService = require("@smartface/library-reader");

let timeout;
let watcherEnabled = true;

@@ -25,5 +26,8 @@ function watch(libraryFolder, handler) {

watcher.on('all', (e, filename) => {
if (!watcherEnabled) {
return console.warn('ā”œā”€> Ignore Change > ', filename);
}
timeout && clearTimeout(timeout);
timeout = setTimeout(() => {
console.log('Watcher ..> ', e, ' . ', filename);
console.log('ā”œā”€ Watcher > ', e, ' . ', filename);
LibraryService.read(libraryFolder, (e, res) => {

@@ -37,2 +41,9 @@ handler(e, res);

module.exports = watch;
function setWatcherEnabledStatus(enabled) {
watcherEnabled = enabled;
}
module.exports = {
watchLibrary: watch,
setWatcherEnabledStatus
};

@@ -94,2 +94,3 @@ const dot = require("dot-object");

item.initialized = component.initialized;
item.oldName = component.oldName;
item.parent && (item.parent = idNameObjects[item.parent]);

@@ -155,2 +156,3 @@ item.children && (item.children = item.children.map(child => {

initialized: components[0].initialized,
oldName: components[0].oldName,
name: footer.page ? footer.page.name : '',

@@ -157,0 +159,0 @@ pageName: footer.pageName,

@@ -12,14 +12,17 @@ const fs = require("fs-extra");

const generateStylerBuilder = require("./util/generateStylerBuilder");
const watchLibrary = require("./service-clients/watch-library");
const { watchLibrary, setWatcherEnabledStatus } = require("./service-clients/watch-library");
const normalizePath = require("./util/normalizePath");
const { writeFile } = require("fs");
const writeError = util.writeError;
function prepareOutputFilePath(projectType, uiFolder, fileName){
let res;
if(projectType === PROJECT_TYPES.ts) {
res = path.join(uiFolder, `${fileName}.ts`);
} else {
res = path.join(uiFolder, `${fileName}.js`);
}
return res;
const importExportRegex = /import|export/;
function prepareOutputFilePath(projectType, uiFolder, fileName) {
let res;
if (projectType === PROJECT_TYPES.ts) {
res = path.join(uiFolder, `${fileName}.ts`);
} else {
res = path.join(uiFolder, `${fileName}.js`);
}
return res;
}

@@ -41,2 +44,3 @@

const libraryUserFolder = getPath("LIBRARY_USER_FOLDER");
let libraryCpxFolder = '';

@@ -55,3 +59,8 @@ function transpilerHandler() {

}).then(res => res);
}!res.initialized && createLibraryUserFileIfDoesNotExist(res);
}
if (!res.initialized && !res.oldName) {
createLibraryUserFileIfDoesNotExist(res);
} else if (res.oldName) {
moveComponentUserFile(res);
}
});

@@ -68,2 +77,3 @@ removePassiveComponentFiles();

initialized: comp.initialized,
oldName: comp.oldName,
changed: false

@@ -80,4 +90,4 @@ };

if (!tranp) {
tranp = {};
transpilers[comp.libraryType] = tranp;
tranp = {};
transpilers[comp.libraryType] = tranp;
}

@@ -111,3 +121,3 @@ tranp.active = true;

}
var filePath = prepareOutputFilePath(projectType, libraryUiFolder, opt.name);
var filePath = prepareOutputFilePath(projectType, libraryUiFolder, opt.name);
var islibFolderExists = util.mkdirpSync(path.dirname(filePath));

@@ -130,2 +140,51 @@ fs.writeFileSync(filePath, opt.content, "utf8");

async function moveComponentUserFile(compRes) {
const oldUserFilePath = prepareOutputFilePath(projectType, getPath("LIBRARY_USER_FOLDER"), util.capitalizeFirstLetter(compRes.oldName));
const newUserFilePath = prepareOutputFilePath(projectType, getPath("LIBRARY_USER_FOLDER"), util.capitalizeFirstLetter(compRes.name));
const existingResOld = await util.isExistsFileDir(oldUserFilePath);
const existingResNew = await util.isExistsFileDir(newUserFilePath);
console.log('|--- moveComponentUserFile \n|- ', oldUserFilePath, '\n|- ', newUserFilePath);
if ((existingResOld.existing && !existingResOld.dir) && (!existingResNew.existing || (existingResNew.existing && existingResNew.dir))) {
await fs.move(oldUserFilePath, newUserFilePath, { overwrite: true });
await fixImportStatement(newUserFilePath, compRes);
setWatcherEnabledStatus(false);
try {
await removeOldNameProp(compRes);
} catch (e) {
writeError({
file: newUserFilePath,
stack: e.stack,
}, 'ComponentSourceFile Writing Error');
}
setTimeout(() => setWatcherEnabledStatus(true), 300);
} else {
writeError({
file: newUserFilePath,
stack: `${oldUserFilePath}: ${JSON.stringify(existingResOld)}\n${newUserFilePath}: ${JSON.stringify(existingResNew)}`
}, 'ComponentUserfiles Existing Error');
}
}
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);
}
});
await fs.writeFile(newUserFilePath, lines.join('\n', 'utf-8'));
}
async function removeOldNameProp(compRes) {
const cpxFilePath = path.join(libraryCpxFolder, compRes.name + `.cpx`);
const content = await fs.readJSON(cpxFilePath);
content.components[0].oldName = undefined;
await fs.writeJSON(cpxFilePath, content, { spaces: '\t', overwrite: true });
}
function init() {

@@ -139,2 +198,3 @@ util.mkdirpSync(libraryUiFolder);

this.watchLibrary = (libraryFolder) => {
libraryCpxFolder = libraryFolder;
watchLibrary(libraryFolder, (err, libraryPageData) => {

@@ -147,3 +207,3 @@ if (err)

});
}
};
this.transpileComponents = transpilerHandler.bind(this);

@@ -150,0 +210,0 @@ this.init = init.bind(this);

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

const BRACKET_END = "$(B_R-A_C-K_E-T)";
const importExportRegex = /import|export/;

@@ -75,2 +76,3 @@ const isExistsFileDir = util.isExistsFileDir,

const pagesFolder = getPath("PAGES_FOLDER");
let watcherEnabledStatusFunc = () => { };
modulesComps.startMarketplaceClient();

@@ -100,3 +102,3 @@ libraryTranspiler.watchLibrary(path.join(pgxFolder, 'library'));

styleGeneration.initFolderPaths();
promiseArr.push(styleGeneration.generateStyles())
promiseArr.push(styleGeneration.generateStyles());
}

@@ -110,3 +112,3 @@ Promise.all(promiseArr).then(async res => {

console.error(err);
isStandalone && process.exit(1)
isStandalone && process.exit(1);
});

@@ -128,3 +130,3 @@ });

function transpilerHandler(filePath, classGeneration, trynum) {
return handlePgx(filePath).then(pgx => {
return handlePgx(filePath).then(async pgx => {
if (!pgx) {

@@ -141,3 +143,3 @@ if (!trynum || trynum < 5) {

else {
const dirtyPage = checkComponentsTestID(pgx)
const dirtyPage = checkComponentsTestID(pgx);
const parsedObjectData = transpiler.parse(pgx.components);

@@ -147,3 +149,3 @@ //classGeneration !== false && styleGeneration.generateClassesMapAllFiles(path.dirname(filePath));

parsedObjectData.coreLibPath = normalizePath(coreLibPath);
if (parsedObjectData.initialized === false) {
if (parsedObjectData.initialized === false && !parsedObjectData.oldName) {
createUserPageIfDoesNotExist({

@@ -154,2 +156,4 @@ pageName: parsedObjectData.name,

});
} else if (parsedObjectData.oldName) {
await movePageUserFile(parsedObjectData.name, parsedObjectData.oldName, pgx, filePath);
}

@@ -176,3 +180,3 @@ emitGeneratedEvent(transpiler.generate(parsedObjectData), resFilePath, true);

}
this.setWatcherEnabledStatusFunc = (_watcherEnabledStatusFunc) => watcherEnabledStatusFunc = _watcherEnabledStatusFunc;
this.deleteScriptFile = deleteScriptHandler;

@@ -191,2 +195,49 @@ this.changeHandler = transpilerHandler.bind(this);

async function movePageUserFile(pageName, oldPageName, pgx, pgxFilePath) {
const oldUserFilePath = path.join(pagesFolder, `${oldPageName}.${projectType}`);
const newUserFilePath = path.join(pagesFolder, `${pageName}.${projectType}`);
const existingResOld = await isExistsFileDir(oldUserFilePath);
const existingResNew = await isExistsFileDir(newUserFilePath);
console.log('|--- movePageUserFile \n|- ', oldUserFilePath, '\n|- ', newUserFilePath);
if ((existingResOld.existing && !existingResOld.dir) && (!existingResNew.existing || (existingResNew.existing && existingResNew.dir))) {
await fs.move(oldUserFilePath, newUserFilePath, { overwrite: true });
await fixImportStatement(newUserFilePath, { name: pageName, oldName: oldPageName });
watcherEnabledStatusFunc(false);
try {
await removeOldNameProp(pgx, pgxFilePath);
} catch (e) {
writeError({
file: newUserFilePath,
stack: e.stack,
}, 'PageSourceFile Writing Error');
}
setTimeout(() => watcherEnabledStatusFunc(true), 400);
} else {
writeError({
file: newUserFilePath,
stack: `${oldUserFilePath}: ${JSON.stringify(existingResOld)}\n${newUserFilePath}: ${JSON.stringify(existingResNew)}`
}, 'PageUserfiles Existing Error');
}
}
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);
}
});
await fs.writeFile(newUserFilePath, lines.join('\n', 'utf-8'));
}
async function removeOldNameProp(content, pgxFilePath) {
content.components[0].oldName = undefined;
await fs.writeJSON(pgxFilePath, content, { spaces: '\t', overwrite: true });
}
}

@@ -193,0 +244,0 @@

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