Skip to content

Commit 25f82c6

Browse files
committed
Improve uninstalling components (supports rebuild CSS and JS).
1 parent 5004ad8 commit 25f82c6

1 file changed

Lines changed: 40 additions & 14 deletions

File tree

index.js

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,10 +3105,11 @@ Framework.prototype.install = function(type, name, declaration, options, callbac
31053105
if (!name && internal)
31063106
name = U.getName(internal).replace(/\.html/gi, '').trim();
31073107

3108+
var hash = '\n/*' + name.hash() + '*/\n';
31083109
var temporary = (F.id ? 'i-' + F.id + '_' : '') + 'components';
31093110
content = parseComponent(internal ? declaration : Fs.readFileSync(declaration).toString(ENCODING), name);
3110-
content.js && Fs.appendFileSync(F.path.temp(temporary + '.js'), (F.config.debug ? component_debug(name, content.js, 'js') : content.js) + '\n');
3111-
content.css && Fs.appendFileSync(F.path.temp(temporary + '.css'), (F.config.debug ? component_debug(name, content.css, 'css') : content.css) + '\n');
3111+
content.js && Fs.appendFileSync(F.path.temp(temporary + '.js'), hash + (F.config.debug ? component_debug(name, content.js, 'js') : content.js) + hash.substring(0, hash.length - 1));
3112+
content.css && Fs.appendFileSync(F.path.temp(temporary + '.css'), hash + (F.config.debug ? component_debug(name, content.css, 'css') : content.css) + hash.substring(0, hash.length - 1));
31123113

31133114
if (content.js)
31143115
F.components.js = true;
@@ -3923,21 +3924,46 @@ Framework.prototype.uninstall = function(type, name, options, skipEmit) {
39233924
} else if (type === 'component') {
39243925

39253926
obj = F.components.instances[name];
3926-
if (!obj)
3927-
return F;
3928-
3929-
F.routes.web = F.routes.web.remove('owner', id);
3930-
F.routes.files = F.routes.files.remove('owner', id);
3931-
F.routes.websockets = F.routes.websockets.remove('owner', id);
3932-
39333927
if (obj) {
3928+
F.routes.web = F.routes.web.remove('owner', id);
3929+
F.routes.files = F.routes.files.remove('owner', id);
3930+
F.routes.websockets = F.routes.websockets.remove('owner', id);
39343931
obj.uninstall && obj.uninstall(options, name);
3935-
delete F.components.instances[name];
3936-
delete F.components.views[name];
3932+
F._routesSort();
39373933
}
39383934

3939-
// @TODO: rebuild CSS and JS?
3940-
F._routesSort();
3935+
delete F.components.instances[name];
3936+
delete F.components.views[name];
3937+
3938+
var temporary = (F.id ? 'i-' + F.id + '_' : '') + 'components';
3939+
var data;
3940+
var index;
3941+
var beg = '\n/*' + name.hash() + '*/\n';
3942+
var end = beg.substring(0, beg.length - 1);
3943+
var is = false;
3944+
3945+
if (F.components.js) {
3946+
data = Fs.readFileSync(F.path.temp(temporary + '.js')).toString('utf-8');
3947+
index = data.indexOf(beg);
3948+
if (index !== -1) {
3949+
data = data.substring(0, index) + data.substring(data.indexOf(end, index + end.length) + end.length);
3950+
Fs.writeFileSync(F.path.temp(temporary + '.js'), data);
3951+
is = true;
3952+
}
3953+
}
3954+
3955+
if (F.components.css) {
3956+
data = Fs.readFileSync(F.path.temp(temporary + '.css')).toString('utf-8');
3957+
index = data.indexOf(beg);
3958+
if (index !== -1) {
3959+
data = data.substring(0, index) + data.substring(data.indexOf(end, index +end.length) + end.length);
3960+
Fs.writeFileSync(F.path.temp(temporary + '.css'), data);
3961+
is = true;
3962+
}
3963+
}
3964+
3965+
if (is)
3966+
F.components.version = U.GUID(5);
39413967
}
39423968

39433969
!skipEmit && F.emit('uninstall', type, name);
@@ -14657,4 +14683,4 @@ function controller_json_workflow(id) {
1465714683
// Because of controller prototypes
1465814684
// It's used in F.view() and F.viewCompile()
1465914685
const EMPTYCONTROLLER = new Controller('', null, null, null, '');
14660-
EMPTYCONTROLLER.isConnected = false;
14686+
EMPTYCONTROLLER.isConnected = false;

0 commit comments

Comments
 (0)