Ext.data.JsonP.command_package_authoring({"title":"Creating Sencha Cmd Packages","guide":"
Contents
\n\nSencha Cmd v3.1 includes the Sencha Package Manager. Packages have many uses even if you\ndo not intend to distribute the packages you create. This guide covers to process of\ncreating your own packages as well as distributing them. For information on using packages\nplease refer to Sencha Cmd Packages.
\n\nBefore we can generate a new package, we must first create a home for it: a\nWorkspace. For this example we will use Ext JS 4.2 for this\npackage, so we start with this command:
\n\nsencha -sdk /path/to/ext-4.2.0 generate workspace /path/to/workspace\n
\n\nNow we navigate to the new workspace and generate the package:
\n\ncd /path/to/workspace\nsencha -sdk ext generate package -type code foo\n
\n\nThe above steps will produce a starter package that contains many commonly used pieces.\nYou can delete many of these but it is important to keep the \".sencha\"
folder intact.
The structure of a package generated by sencha generate package
is as follows:
packages/\n foo/ # Top-level folder for the package\n .sencha/\n package/\n sencha.cfg # Sencha Cmd configuration for this package\n build-impl.xml # Generated build script for package\n plugin.xml # Sencha Cmd plugin for this package\n codegen.json # Data to support 3-way merge in code generator\n docs/ # Documentation for the package\n screenshots/ # Screen shots for Sencha Market\n licenses/ # License agreement\n overrides/ # Folder for automatically activated overrides\n resources/ # Static resources (typically has images folder)\n sass/ # Container for Sass code\n etc/ # General, non-component oriented Sass\n src/ # Sass rules and mixins named by component\n var/ # Sass variables named by component\n src/ # Folder for normal JavaScript code\n build.xml # Build script (called by `sencha package build`)\n package.json # Package descriptor\n Readme.md # High-level information about this package\n
\n\nWhile the above is quite extensive, the only parts that are required to be a package are\nthese: \"package.json\"
and \".sencha/package/sencha.cfg\"
.
The \"package.json\"
file contains a description of the package. An example of this from\nthe \"ext-theme-neptune\"
package:
{\n \"name\": \"ext-theme-neptune\",\n \"type\": \"theme\",\n \"creator\": \"Sencha\",\n \"summary\": \"Ext JS Neptune Theme\",\n \"detailedDescription\": \"The Neptune Theme provides a clean, modern style for Ext JS\",\n \"version\": \"4.2.1\",\n \"compatVersion\": \"4.2.0\",\n \"format\": \"1\",\n \"extend\": \"ext-theme-neutral\"\n}\n
\n\nThe creator
property is something you will need to set as a package author. There is no\nverification of this text, but it must match the name you assign to your local package\nrepository discussed later.
The \".sencha/package/sencha.cfg\"
file is primarily important to the developer of the\npackage as it is used by Sencha Cmd during sencha package build
. It is also used by\nby user applications during their sencha app build
process.
The purpose of most packages is to (eventually) become integrated in an application. To\naccomplish this, Sencha Cmd incorporates the various pieces of each required package in\nto an application during the sencha app build
process.
Precisely how this takes place depends on the type
of the package.
Different types of packages play different roles. Sencha Cmd understands the following\ntypes of packages:
\n\ncode
- An arbitrary package of code for use by applications or other packages.\nThese packages are general purpose and are included when there is a require
statement\nthat selects them.theme
- A package to be used as an application's theme. Themes are special in that\nonly one package of type theme
is allowed to be \"active\" in a build. This theme is\nselected by the app.theme
property and it causes all other theme packages that may\nbe in a require
to be filtered out. Themes can also use extend
to inherit Sass and\nresources from another theme package.locale
- A package containing localization strings or locale-specific code. These\npackages have a similar selection method to theme
packages. Packages of this type add\na property to their \"package.json\"
called \"locale\"
. This should be set to the name\nof the locale to which this package applies (e.g., \"he\"
for Hebrew). The app.locale
\nproperty, if set, causes any package of this type with a different value in its locale
\nto be filtered out. This means you can have many different locale packages with the\nsame locale
value and they will all be includedThe \"src\"
folder is the place for classes such as custom components or other useful\ncode. This code is automatically included in the classpath
for applications or other\npackages to require
and use.
This is where you would likely put most of your JavaScript code. Classes placed in this\nfolder should follow the Compiler-Friendly Code Guidelines.
\n\nThe \"sass\"
folder contains three sub-folders designed to handle different aspects of\nSass compilation.
\"sass/etc\"
- Code that does not relate directly to JavaScript classes\"sass/var\"
- Variable definitions (mirroring JavaScript class hierarchy)\"sass/src\"
- Mixins and rules (mirroring JavaScript class hierarchy)The folders and files in \"sass/var\"
and \"sass/ssrc\"
are organized such that they are\nmirror images of the JavaScript classes to which they apply. This correspondence allows\nSencha Cmd to include the files needed by the application. Files in these folders that\ndo not conform to this will never be included since the process proceeds by mapping the\nJavaScript class hierarchy to the file system and not be scanning these folders.
The package.sass.namespace
(in \".sencha/package/sencha.cfg\"
) determines the top-level\nnamespace to which your styling applies. This defaults to Ext
for packages. You will\nmost likely need to change this in order to associate your Sass with your classes inside\nyour package's namespace.
The \"resources\"
folder is where you place static resources needed by the package. When\napplications consume the package, they will copy these resources into a sub-folder of their\nown \"resources\"
folder named by the package name. In this case, \"resources/foo\"
. The\nrelative paths used by Sass will be automatically corrected if you use the provided\ntheme-background-image
method.
The \"overrides\"
folder is specifically intended for your package to provide mandatory\noverrides, hence its name. This mechanism should be used cautiously because all code you\nplace in this folder will be automatically required in to any application that uses this\npackage.
The Ext JS Neptune Theme uses this mechanism to change certain default config properties\non various components. Locale packages use this to inject their own text on to the\nprototypes of various components or to provide locale-specific logic for things such as\ndate formatting.
\n\nPackages have a version
property that describes its current version number. In\naddition the current version (in the version
property), packages can also indicate the\ndegree to which they are backward compatible using the compatVersion
property.
These versions are used when resolving package requirements. Each release of a package\nshould have an updated version number. The meaning assigned to version numbers by Sencha\nmay help you:
\n\nx.y.z.b\n\nx = Major release number (large, impacting changes and features)\ny = Minor release number (new functionality but few if any breaking changes)\nz = Patch release number (bug fix / maintenance release - goal of 100% compatible)\nb = Build number (assigned by build system)\n
\n\nThe version
property is typically the easiest to maintain. The compatVersion
, however,\nis an intentional statement about the degree to which users should be able to transparently\nupgrade and not require code changes.
Packages can require other packages in the same way that applications can require packages.\nTo do this, you add to the requires
array:
{\n \"name\": \"bar\",\n \"type\": \"code\",\n \"creator\": \"anonymous\",\n \"summary\": \"Short summary\",\n \"detailedDescription\": \"Long description of package\",\n \"version\": \"1.0.0\",\n \"compatVersion\": \"1.0.0\",\n \"format\": \"1\",\n \"local\": true,\n \"requires\": [\n 'ext-easy-button'\n ]\n}\n
\n\nNOTE: When using version restrictions as a package author, it is important to consider\nthat an application and all of the required packages will have to agree on a common version.\nIf you are too restrictive, this process can fail to find a mutually agreeable version for\nall of the required packages.
\n\nThe notion of inheritance for packages is intended exclusively for Themes. These are\nmost important ways in which the inherited package contents are rolled into the derived\npackage:
\n\n\"resources\"
folders of inherited packages is copied in to the \"resources\"
\nfolder in the \"build\"
output folder.overrides
of base packages are automatically included in the build output of\nthe derived package.To publish the package, you will need to build it using:
\n\nsencha package build\n
\n\nThis produces a \"build\"
folder inside the package. This is needed by applications when\nthey are running in \"dev mode\" (without being compiled). It also produces \"foo.pkg\"
file\nin your workspace's \"build\"
folder. This file is not placed in the package's \"build\"
\nfolder because:
The \"foo.pkg\"
file is used to add the package to your local repository. See below.
NOTE: In Cmd v3.1.0, sencha package build
may fail if you have Sass that depends\non the theme. To workaround this limitation, you can set the skip.sass
and skip.slice
\nproperties in \".sencha/package/sencha.cfg\"
. The package will be usable in an application\nbecause the theme will be included in sencha app build
.
The local repository was introduced in Sencha Cmd Packages,\nbut there is more to know about it when you want distribute the packages you have created.
\n\nThe local repository generated by Sencha Cmd looks like this:
\n\n.sencha/\n repo/\n sencha.cfg # Sencha Cmd configuration for the repo\n plugin.xml # Plugin for repository hooks\n private-key.json # Private key for repo\n\n remotes/ # Storage for remote repositories\n remoteName/ # Name given at `sencha repo add`\n catalog.json # Last catalog from this remote\n\n trust/ # Unused in this release\n <somename>.cert.json # Copy of `cert.json` (a public key)\n\npkgs/\n catalog.json # Catalog of all packages in this repo\n cert.json # Public key for this repo\n\n Foo/\n catalog.json # Catalog for all versions of Foo package\n cert.json # Public key for creator of Foo package\n\n 1.0/ # Folder containing version 1.0\n Foo.pkg # Zip file of package\n package.json # Extracted package descriptor\n 1.1/\n ...\n\n Bar/\n ...\n
\n\nWhen Sencha Cmd generates the default local repository, it does not require you to provide\nany kind of identity. This is fine for its role as a cache, but as a package author you\nneed to put your name on the packages you publish. Before you can publish packages you\nneed to initialize your local repository with an identity:
\n\nsencha package repo init -name \"My Company\" -email \"support@mycompany.com\"\n
\n\nAfter this step, your name and email address will be recorded in the local repository along\nwith a new public/private key pair.
\n\nNOTE: The name
argument must match the value of the creator
property you set in\nthe \"package.json\"
.
Your name, email and public key are stored in the \"pkgs/cert.json\"
file. This file will\nbe automatically added to the packages you create to identify you as the package author.
Obviously given its name, your private key is not intended to be shared with others. It\nis stored in your local repository in \".sencha/repo/private-key.json\"
.
You might want to back up these two files as they will serve more important roles in\nfuture releases.
\n\nThe \"pkgs\"
folder is where all the packages are stored. These may be packages you have\ncreated or packages that you have downloaded.
When you add package \".pkg\"
files, these will be copied in to the \"pkgs\"
folder tree.
The \".sencha/repo/plugin.xml\"
file is an Ant script that you\ncan use to provide \"hooks\" into repository actions such as sencha package add
. For more\ndetails on this, refer to the comments in the generated file.
Since: Sencha Cmd v3.1.1
\n\nOnce you have the \".pkg\"
file from the build, and assuming that the name
you have set\nas your identity on your local repository matches the creator
property defined in your\n\"package.json\"
, you can run this command:
sencha package add foo.pkg\n
\n\nSencha Cmd will produce a hash of the \".pkg\"
file using your private key and add it to\nthe \".pkg\"
file you specify and it will then copy that file to the local repository.
Now that the package reside in the repository, other developers can require
it if they\nhave added your repository as a remote.
The process to request that Sencha add your \".pkg\"
to the Sencha Package Repository is\nstill being finalized, but you can check Sencha Market for\nupdates on this.
The structure of the \"pkgs\"
folder is the structure expected for a remote repository. All\nthat is required for others to require
the packages you create is for them to add a\nremote repository:
sencha package repo add my-company http://my.company.com/packages\n
\n\nThat is, assuming you have hosted your \"pkgs\"
folder content at the above HTTP URL. There\nis nothing required of that hosting beyond HTTP GET access so a static file server or CDN\nwill work.