This package structure your project so you can have your client, server and modules in different places.
We make a separation bitween client, server and modules
┌── client
├── modules
└── server
Each module itself has a separation bitween client, server and common files
──┬ modules
└─┬ moduleXXX
├── client
├── common
└── server
For a module, common files and directories are symlinked to client and server
──┬ modules
└─┬ moduleXXX
├─┬ client
| ├── clientFILE.js
| ├── clientDIR
| ├── commonFILE.js <=symlink=> ./common/commonFILE.js
| └── commonDIR <=symlink=> ./common/commonDIR
├─┬ common
| ├── commonFILE.js
| └── commonDIR
└─┬ server
├── serverFILE.js
├── serverDIR
├── commonFILE.js <=symlink=> ./common/commonFILE.js
└── commonDIR <=symlink=> ./common/commonDIR
And finaly, client of the module is symlinked to the client source and server of the module is symlinked to the server source
┌─┬ client
| └─┬ src
| └── moduleXXX <=symlink=> modules/moduleXXX/client
├─┬ modules
| └─┬ moduleXXX
| ├── client
| ├── common
| └── server
└─┬ server
└─┬ src
└── moduleXXX <=symlink=> modules/moduleXXX/server
So, at the end, we have
┌─┬ client
| └─┬ src
| └─┬ moduleXXX
| ├── clientFILE.js
| ├── clientDIR
| ├── commonFILE.js
| └── commonDIR
├── modules...
└─┬ server
└─┬ src
└─┬ moduleXXX
├── serverFILE.js
├── serverDIR
├── commonFILE.js
└── commonDIR
You can create a modules-client-server.conf.json
file if you have other preferences. You have to execute a command in the same directory as the configuration file if it is defined.
Fist, install the package as global :
npm install -g modules-client-server
So as a sample :
mkdir sampleProj
cd sampleProj
modules-client-server --init --add moduleXXX
cd modules\moduleXXX
echo // > client\clientFILE.js
mkdir client\clientDIR
echo // > server\serverFILE.js
mkdir server\serverDIR
echo // > common\commonFILE.js
mkdir common\commonDIR
Each time you add or remove common files or directories you have to sync them with client and server side :
modules-client-server --sync
Or you can automate it :
modules-client-server --watch
While watching, you can use an other console to add or remove modules.
NOTA BENE: for Windows, to --sync
or --watch
, if you have files in the root of your common module directory, your console MUST be executed as Administrator. Directories are OK.
The commands are to be done where is the parameter file.
You can change where client, server or common directories are on your system.
The --conf
command show you the current configuration.
rootPath
: used ifclientRootPath
,serverRootPath
ormodulesRootPath
have relative pathsclientRootPath
: root path of the client (can be relative torootPath
)serverRootPath
: root path of the server (can be relative torootPath
)modulesRootPath
: root path of the modules (can be relative torootPath
)clientSrcPath
: src path of the client (can be relative toclientRootPath
)nodeModulesPath
:node_modules
path of the modules (can be relative toclientRootPath
)serverSrcPath
: src path of the server (can be relative toserverRootPath
)serverRootPathShouldExist
: the server must exist before--init
clientModulesName
: name of the directory where all modules have to be underclientSrcPath
if definedserverModulesName
: name of the directory where all modules have to be underserverSrcPath
if definedmoduleClientCommonName
: name of the directory where all common ressources of each modules have to be for the client side if definedmoduleServerCommonName
: name of the directory where all common ressources of each modules have to be for the server side if definedgitignore
: the symlinks are included in.gitignore
files of client, server and modules root directories (default to true)
If moduleClientCommonName
and moduleServerCommonName
are both used, you don't have to use --sync
.
┌─┬ client
| └─┬ src
| └─┬ modulesS
| └─┬ moduleXXX
| ├── clientFILE.js
| ├── clientDIR
| ├── commonFILE.js
| └── commonDIR
├── modules...
└─┬ server
└─┬ src
└─┬ modulesC
└─┬ moduleXXX
├── serverFILE.js
├── serverDIR
├── commonFILE.js
└── commonDIR
modules-client-server.conf.js
file :
{
"clientModulesName": "modulesS",
"serverModulesName": "modulesN"
}
┌─┬ client
| └─┬ src
| └─┬ £
| └─┬ moduleXXX
| ├── clientFILE.js
| ├── clientDIR
| └─┬ #
| ├── commonFILE.js
| └── commonDIR
├── modules...
└─┬ server
└─┬ src
└─┬ modulesC
└─┬ moduleXXX
├── serverFILE.js
├── serverDIR
└─┬ $
├── commonFILE.js
└── commonDIR
modules-client-server.conf.js
file :
{
"clientModulesName": "£",
"serverModulesName": "modulesC",
"moduleClientCommonName": "#",
"moduleServerCommonName": "$"
}