Is there a way to minify an ExtJS application without Sencha CMD? - maven

I have an existing ExtJS app developed using ExtJS 4.2.1.
I am using Closure minifier through Maven plugin minify-maven-plugin.
The generated minified JS files (without merge) works fine.
However, generated merged minified file throws undefined errors because the definition comes later in the merged file.
My question is, is there a way I can figure out the order I have to provide the plugin? (I don't want to use Sencha Cmd)
The app folder follows the structure
app/common, app/controller, app/model, app/proxy, app/store, app/utils, app/view
At the moment this is how I have defined the build process in Maven POM file
<plugins>
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.4</version>
<executions>
<execution>
<id>default-minify</id>
<phase>prepare-package</phase>
<goals>
<goal>minify</goal>
</goals>
<inherited>false</inherited>
<configuration>
<charset>UTF-8</charset>
<!-- <skipMerge>true</skipMerge> -->
<webappSourceDir>${basedir}/src/main</webappSourceDir>
<jsSourceDir>js/app</jsSourceDir>
<jsTargetDir>js/app</jsTargetDir>
<jsEngine>CLOSURE</jsEngine>
<closureLanguage>ECMASCRIPT5</closureLanguage>
<closureAngularPass>true</closureAngularPass>
<nosuffix>true</nosuffix>
<webappTargetDir>${project.build.directory}</webappTargetDir>
<jsSourceIncludes>
<jsSourceInclude>**/*.js</jsSourceInclude>
</jsSourceIncludes>
</configuration>
</execution>
</executions>
</plugin>

Why dont use Sencha Cmd? It does exactly what you want!
Maybe it helps if you know that you can use Sencha Cmd without the Sencha application structure. If you want only merge the files use the concatenate cmd.
If you really dont want use Sencha Cmd, then you have to take care of all the extends, requires, mixins and so on... and I would not recommend this!
For example use Sencha Cmd with manual paths and exclude the extjs classes
sencha compile --classpath=myApp/src,extjs/src -debug=false exclude -all and include -namespace MyApp.* and concat bundle.js
the extjs/src path is the path where your extjs classes are

Since your question is about the order of of files for minification, providing that information below:
We had a similar requirement, where I could not use Sencha cmd as it is to minify files, so created jsb file on my own [I know this is not recommended :( ].
What I did was, created below jsb file [please note: sequence of files is very important]:
{
"projectName": "ProductName",
"builds": [
/** This file is for production purpose **/
{
"name": "ProductName - Production",
"target": "all-app.js",
"compress": true,
"files": [
/** utils **/
{
"path": "app/util/",
"name": "util.js"
}
/** models **/
{
"path": "app/model/",
"name": "MyModel.js"
},
/** stores **/
{
"path": "app/store/",
"name": "MyStore.js"
},
/** custom components **/
{
"path": "resources/ux/form/",
"name": "MySearchField.js"
},
/** views **/
{
"path": "app/view/admin/",
"name": "MyView.js"
},
/** controllers **/
{
"path": "app/controller/",
"name": "Window.js"
},
/** app.js **/
{
"path": "",
"name": "app.js"
}
]
},
/** This file is for debug purpose **/
{
"name": "ProductName - debug",
"target": "all-app-debug.js",
"compress": false,
"files": [
/** utils **/
{
"path": "app/util/",
"name": "util.js"
}
/** models **/
{
"path": "app/model/",
"name": "MyModel.js"
},
/** stores **/
{
"path": "app/store/",
"name": "MyStore.js"
},
/** custom components **/
{
"path": "resources/ux/form/",
"name": "MySearchField.js"
},
/** views **/
{
"path": "app/view/admin/",
"name": "MyView.js"
},
/** controllers **/
{
"path": "app/controller/",
"name": "Window.js"
},
/** app.js **/
{
"path": "",
"name": "app.js"
}
]
}
],
"resources" : []
}
If you create a minified file using above sequence, it will work in your case as well.
Hope this help.
Thanks!

Related

Using Composer autoload inside a ZIP package

I've been trying to get composer to generate classmaps for an API provided by a 3rd party company (OtherCompany in the example configuration) but have been unable to get it to work the way I think it should. However, I'm very new to composer so I may be completely wrong.
The situation is as follows. I have a project directory which contains the following composer.json (which does not generate classmaps for api.php):
{
"name": "company/company-library",
"description": "A useful library",
"type": "library",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "company",
"email": "hello#company.com"
}
],
"require": {
"othercompany/otherlibrary": "^1.0"
},
"config": {
"optimize-autoloader": true
},
"autoload": {
"psr-4": {
"Company\\CompanyLib\\": "src/"
}
},
"minimum-stability": "dev",
"repositories": [
{
"type": "package",
"package": {
"name": "othercompany/otherlibrary",
"type": "library",
"description": "Eases the integration of othercompany APIs into company's useful library",
"homepage": "https://otherlibraryportal.othercompany.com",
"version": "1.0",
"dist": {
"url": "../../../../repository/othercompany-otherlibrary-1.2.zip",
"type": "zip"
},
"require": {
"php": ">=5.6.1",
"phpseclib/phpseclib": "3.0.18"
},
"config": {
"optimize-autoloader": true
},
"autoload": {
"classmap": ["api.php"]
},
"minimum-stability": "dev"
}
}
]
}
The package "othercompany/otherlibrary" is contained in a ZIP file which only contains 2 files in a folder named othercompany-otherlibrary-1.2:
api.php
readme.txt
After a 'compose install', these files are stored in the directory:
vendor/othercompany/otherlibrary
The api.php file contains a number of classes which I would like to autoload. However, using the configuration above and various modifications of the classmap directive, have not been able to achieve the desired effect. Only if I move the classmap directive to the root level autoload directive in composer.json and update the path to vendor/othercompany/otherlibrary/api.php, classmaps are generated for the package my libary depends on. Snippet:
"autoload": {
"psr-4": {
"Company\\CompanyLib\\": "src/"
},
"classmap": ["vendor/othercompany/otherlibrary/api.php"]
}
Although this works and classmaps are now generated, I cannot help but think that this should not work this way as each package should independently be able to specify autoload options. If this is correct, what would be the right way to specify autoload options for the othercompany/otherlibrary package?
ADDITIONAL INFORMATION
api.php:
<?php
// Creates the API Request from the context
class APIRequest {
}
// API Response
class APIResponse {
}
// Api Method Type Constants
class APIMethodType {
}
// API Context that contain info for the API endpoint
class APIContext {
}
?>
companylibrary.php:
<?php
/**
* #package Company Library
* #author Company < hello#company.com >
* #version 1.0.0
*/
// Exit if accessed directly.
if (!defined('ABSPATH')) {
exit;
}
define('WC_CL_VERSION', '1.0.0');
require_once plugin_dir_path(__FILE__) . 'vendor/autoload.php';
/**
* Classes are correctly autoloaded if the autoload directive for the
* package the 'root' package depends on, is specified at the 'root'
* package level.
*
* If the autoload directive is specified at the package level of the
* 'sub' level of the package itself, no classmaps are generated.
*/
$public_key("othercompanypublickey");
$context = new APIContext();
$context->set_api_key('companyapikey');
$context->set_public_key($public_key);
$request = new APIRequest($context);
composer.json (which does generate classmaps for api.php):
{
"name": "company/company-library",
"description": "A useful library",
"type": "library",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "company",
"email": "hello#company.com"
}
],
"require": {
"othercompany/otherlibrary": "^1.0"
},
"config": {
"optimize-autoloader": true
},
"autoload": {
"psr-4": {
"Company\\CompanyLib\\": "src/"
},
"classmap": ["vendor/othercompany/otherlibrary/api.php"]
},
"minimum-stability": "dev",
"repositories": [
{
"type": "package",
"package": {
"name": "othercompany/otherlibrary",
"type": "library",
"description": "Eases the integration of othercompany APIs into company's useful library",
"homepage": "https://otherlibraryportal.othercompany.com",
"version": "1.0",
"dist": {
"url": "../../../../repository/othercompany-otherlibrary-1.2.zip",
"type": "zip"
},
"require": {
"php": ">=5.6.1",
"phpseclib/phpseclib": "3.0.18"
},
"minimum-stability": "dev"
}
}
]
}
Do not compress the folder containing the othercompany/otherlibrary files but instead, simply compress the files.
For a working project, please refer to GitHub:
github.com/ezoer/companylibrary

How to add some external package with nwidart/laravel-modules?

In Laravel 6/nwidart/laravel-modules 7 app I see file composer.json in root of my module
with lines :
{
"name": "nwidart/pages",
"description": "",
"authors": [
{
"name": "Nicolas Widart",
"email": "n.widart#gmail.com"
}
],
"extra": {
"laravel": {
"providers": [],
"aliases": {
}
}
},
"autoload": {
"psr-4": {
"Modules\\Pages\\": ""
}
}
}
I suppose that if I want to add some external package into my module(not the whole app)
I need to edit this file and run module commands?
How have I to edit it and which commands to use?
You can use regular composer commands in the module directory. Just cd into it then use composer require package-name.
After adding an entry to the compose file using e.g. in folder your module
composer require package-name
Use the command in the main application in folder global application
php artisan module:update name-your-module

Is there a good example how to add plugins into Bolt CMS CKEditor?

I see that there is no documentation how to add custom CKEditor plugins into Bolt CMS.
Can i add/modify files in public/bolt-public/ folder?
In public\bolt-public\view\js\ckeditor\config.js file i see the following:
// CKeditor config is done in /app/src/js/bolt.js.
but in my yet installed bolt cms i dont have any /app/src/js/bolt.js file to modify.
Can someone help me out to get for example this plugin working in my Bolt CMS?
https://www.michaeljanea.com/ckeditor/font-awesome
Here i found a solution to customize CKEditor and add plugins like FontAwesome.
First we need to create Bold Extension.
Create extension folder /extension/local/mycompany/customckeditor.
In this extension folder we need to create subfolders
/src
/web
/web/plugins
After we need to create Bolt extension file src/CustomCkeditorExtension.php
<?php
namespace Bolt\Extension\MyCompany\CustomCkeditor;
use Bolt\Asset\File\JavaScript;
use Bolt\Extension\SimpleExtension;
use Bolt\Controller\Zone;
/**
* Custom CKEditor extension class.
*/
class CustomCkeditorExtension extends SimpleExtension
{
/**
* {#inheritdoc}
*/
protected function registerAssets()
{
$asset = new JavaScript();
$asset->setFileName('/extensions/mycompany/customckeditor/ckeditor-extended.js')
->setLate(true)
->setPriority(99)
->setZone(Zone::BACKEND);
return [
$asset,
];
}
}
Create composer file /extension/local/mycompany/customckeditor/composer.json
{
"name": "mycompany/customckeditor",
"description": "An extension to allow for CKEditor customisations.",
"type": "bolt-extension",
"version": "1.0.0",
"keywords": [
"ckeditor"
],
"require": {
"bolt/bolt": "^3.4"
},
"require-dev": {
"phpunit/phpunit": "^4.7"
},
"license": "MIT",
"authors": [
{
"name": "Bogdan",
"email": "info#youremail.com"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Bolt\\Extension\\MyCompany\\CustomCkeditor\\": "src"
}
},
"extra": {
"bolt-assets": "web",
"bolt-class": "Bolt\\Extension\\MyCompany\\CustomCkeditor\\CustomCkeditorExtension"
}
}
Go to your console to /extensions folder and edit composer.json file.
Add this lines:
"repositories": {
...
"mycompany-ckeditor-git-repo": {
"type": "path",
"url": "local/mycompany/customckeditor",
"options": {
"symlink": false
}
},
...
},
"require": {
...
"mycompany/customckeditor": "^1.0",
...
}
After that run:
$ composer update
Create JS file /web/ckeditor-extended.js
if (typeof CKEDITOR !== 'undefined') {
CKEDITOR.dtd.$removeEmpty['span'] = false;
}
jQuery(document).ready(function ($) {
var CKEDITORPluginExtras = false;
if (typeof(CKEDITOR) != 'undefined') {
CKEDITOR.plugins.addExternal('fontawesome', '/extensions/mycompany/customckeditor/plugins/fontawesome/plugin.js', '');
CKEDITOR.on('instanceReady', function (event, instance) {
if (CKEDITORPluginExtras) {
return;
}
var config = event.editor.config,
name;
config.toolbar.push(
{ name: 'insert', items: [ 'FontAwesome' ] }
);
config.contentsCss.push(CKEDITOR.plugins.getPath('fontawesome') + 'font-awesome/css/font-awesome.min.css');
config.extraPlugins += (config.extraPlugins ? ',' : '') + 'widget,fontawesome';
for (name in CKEDITOR.instances) {
if (CKEDITOR.instances.hasOwnProperty(name)) {
CKEDITOR.instances[name].destroy();
CKEDITOR.replace(name, config);
}
}
CKEDITORPluginExtras = true;
});
}
});
Copy fontawesome.zip content to /web/plugins
And finally reload your admin panel.

Using HttpConfiguration in ASP.NET Core RC2

I created an empty asp.net web application project with rc2. My project file is:
{
"testRunner": "xunit",
"dependencies": {
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-build10025",
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.Cors": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Now I want to add HttpConfiguration config = new HttpConfiguration(); in my unit test.
But HtppConfiguration is from ASP.NET WEB API 2. How to change my project.json file? Or is there any replacement for it in ASP.NET CORE RC2?
ASP.Core provides an easy way for integration testing using TestServer class. The following may help to start using it:
an ASP.Net Core documentation about integration testing.
a post about using TestServer with example on github.
a TestServerTests.cs file from Hosting repo, that contains xunit tests for TestServer. May help to review, what TestServer can do.
good question on SO: "Why the TestServer (AspNetCore) gives 404 error on static files?"
and keep in mind that a lot of projects in https://github.com/aspnet use TestServer for testing (like Diagnostics ).

How to generate documentation for other projects within solution using DocFx

I am using DocFx to automatically generate documentation in Visual Studio 2015.
Per the Getting Started instructions, I added an empty ASP.NET 4 Web Application and used the Nuget Console to install the DocFx build package (e.g. Install-Package docfx.msbuild). I built the site and it it generated documentation for code within the project.
I was wondering how to configure docfx.json to get DocFx to document code in other projects within the solution.
In docfx.json, there is an array of metadata. The example metadata has a src object with files and exclude properties.
To point to another project in your solution, add a cwd property to metadata and change folders (i.e. "../Another.Project").
{
"metadata": [
{
"src": [
{
"files": [ "**/*.csproj" ],
"exclude": [ "**/bin/**", "**/obj/**", "_site/**" ],
"cwd": "../Another.Project"
}
],
"dest": "obj/api"
}
],
"build": ...
}
This worked for me.
directory structure
+---ClassLibrary
| \---ClassLibrary.csproj
\---DocFxProject
\---docfx.json
docfx.json contents
cwd and src are synonyms for the same property
{
"metadata":
[
{
"src":
[
{
"files": [ "**/ClassLibrary.csproj" ],
"src": "..",
"exclude": [ "**/obj/**", "**/bin/**" ]
}
],
"dest": "obj/api"
}
],
"build": { ... }
}

Resources