-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.alias.js
159 lines (156 loc) · 7.03 KB
/
babel.config.alias.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const path = require("path");
const fs = require("fs");
const platforms = require("./src/platforms");
const getPlatform = (platform)=>{
platform = (typeof platform =='string'? platform : "web").toLowerCase();
for(let i in platforms){
let pl = platforms[i];
if(!pl || typeof pl !='string') continue;
if(pl.toLowerCase() == platform) return platform;
}
return "web";
}
/***
* @param {object}, les options du resolver, objet de la forme :
* {
* projectRoot : {string}, le chemin racine du projet
* platform : {web||expo},//La plateforme du client
* assets : {string}, le chemin assets de l'application,
* alias : {object}, les alias supplémentaires, pouvant être concaténés à ceux généré
* }
*
*/
module.exports = function(opts){
/***** faire une copie du fichier package.json, situé à la racine du projet */
const rootDir = path.resolve(__dirname);
const common = path.resolve(rootDir,"src");
let {projectRoot,withPouchdb,withPouchDB,assets,alias,platform} = opts && typeof opts =="object"? opts : {};
platform = getPlatform(platform);
withPouchDB = withPouchDB || withPouchdb;
projectRoot = projectRoot && typeof projectRoot =='string' && fs.existsSync(projectRoot) ? projectRoot : process.cwd();;
const src = path.resolve(projectRoot,"src");
const packagePath = path.resolve(projectRoot,"package.json");
const $packageJSON = getPackageJSON([opts.$packageJSON,opts.packageJSON,packagePath,path.resolve(common,"app","config.default.json")]);
const pouchdbIndex = path.resolve(common,"pouchdb",withPouchDB?"index.with-pouchdb":"index.with-no-pouchdb");
const cdataFileManager = path.resolve(common,"pouchdb","dataFileManager");
const r = {
"$cmedia" : path.resolve(common,"media"),
$packageJSON,
"$capp" : path.resolve(common,"app"),
"$capi" : path.resolve(common,"api"),
"$capiCustom" : path.resolve(common,"api","apiCustom"),
"$fetch" : path.resolve(common,"api","fetch"),
"$ci18n" : path.resolve(common,"i18n"),
"$clib" : path.resolve(common,"lib"),
"$cauth":path.resolve(common,"auth"),
"$cnavigation" : path.resolve(common,"navigation"),
"$cplatform" : path.resolve(common,"platform"),
"$cdimensions" : path.resolve(common,"platform/dimensions"),
"$cobservable" : path.resolve(common,"lib","observable"),
"$cvalidator" : path.resolve(common,"lib","validator"),
"$cdate" : path.resolve(common,"lib","date"),
"$crypto-js" : path.resolve(common,"lib","crypto-js"),
"$ccountries" : path.resolve(common,"countries"),
"$cdbMainDatabaseIndex" : pouchdbIndex,
"$pouchdb" : path.resolve(common,"pouchdb"),
"$pouchDB" : path.resolve(common,"pouchdb"),
"$ctheme" : path.resolve(common,"theme"),
"$cnotify" : path.resolve(common,"notify"),
"$cutils" : path.resolve(common,"utils"),
"$curi" : path.resolve(common,"utils","uri"),
"$ccurrency" : path.resolve(common,"lib","currency"),
"$csession" : path.resolve(common,"session"),
"$cbase64" : path.resolve(common,"lib","base-64"),
"$base64" : path.resolve(common,"lib","base-64"),
"$cactions" : path.resolve(common,"actions"),
"$media" : path.resolve(common,"media"),
"$capi" : path.resolve(common,"api"),
"$i18n" : path.resolve(common,"i18n"),
"$lib" : path.resolve(common,"lib"),
"$platform" : path.resolve(common,"platform"),
"$dimensions" : path.resolve(common,"platform/dimensions"),
"$observable" : path.resolve(common,"lib","observable"),
"$validator" : path.resolve(common,"lib","validator"),
"$crypto" : path.resolve(common,"lib","crypto-js"),
"$date" : path.resolve(common,"lib","date"),
"$cdate" : path.resolve(common,"lib","date"),
"$cfilters" : path.resolve(common,"utils","filters"),
"$cdatabaseUtils" : path.resolve(common,"utils","database"),
"$notify" : path.resolve(common,"notify"),
"$theme" : path.resolve(common,"theme"),
"$utils" : path.resolve(common,"utils"),
"$uri" : path.resolve(common,"utils","uri"),
"$cprint" : path.resolve(common,"print"),
"$currency" : path.resolve(common,"lib","currency"),
"$session" : path.resolve(common,"session"),
"$actions" : path.resolve(common,"actions"),
"$projectRoot" :projectRoot,
"$base" : projectRoot,
"$src" : src,
"$cdatafileManager": cdataFileManager,
"$datafileManager": cdataFileManager,
...(typeof alias =='object' && !Array.isArray(alias) && alias || {}),
"$ftc-common":rootDir,
"$ftc" : "@fto-consult",
"$ceventSource" : path.resolve(common,"utils","eventSource"),
$cappConfig : path.resolve(common,"app","config"),
$swr : path.resolve(common,"swr"),
$useSWR : path.resolve(common,"swr"),
}
r["$cpdf"] = path.resolve(common,"pdf");
r.$pdf = r.$pdf || r.$cpdf;
r.$eventSource = r.$eventSource || r.$ceventSource;
r.$currencies = r.$ccurrency;
if(!r.$api){
r.$api = r.$capi;
}
if(!r.$appConfig){
r.$appConfig = r.$cappConfig;
}
const cAssets = path.resolve(src,"assets");
assets = typeof assets =="string" && fs.existsSync(path.resolve(assets))? path.resolve(assets) : fs.existsSync(cAssets) ? cAssets : undefined;
if(assets){
r["$assets"] = assets;
r["$images"] = path.resolve(assets,"images");
r["$css"] = path.resolve(assets,"css");
}
if(!r["$app-events"]){
r["$app-events"] = path.resolve(common,"app","_events");
}
if(!r["$app"]){
r["$app"] = r["$capp"];
}
r.$cpreloader = path.resolve(common,"preloader");
if(!r.$preloader){
r.$preloader = r.$cpreloader;
}
/*** alias interne utile pour la compilation en fonction de la platform, soi next où expo */
r["$active-platform"] = path.resolve(common,"platforms",platform);
r["$clipboard"] = path.resolve(r["$active-platform"],"clipboard");
r["$makePhoneCall"] = path.resolve(r["$active-platform"],"makePhoneCall");
r["$common"] = common;
r["$react"] = path.resolve(common,"utils","react");
if(!r["$navigation"]){
r["$navigation"] = r["$cnavigation"];
}
/**** cet alias est utile pour la personnalisation du composant de connexion */
if(!r["$auth"]){
r["$auth"] = r["$cauth"];
}
r.$print = r.$print || r["$cprint"];
const neuLib = path.resolve(projectRoot,"node_modules","@neutralinojs/lib");
const $cneu = fs.existsSync(neuLib) && neuLib || path.resolve(common,"neu");
r.$cneu = r.$cneutralino = $cneu;
r.$neu = r.$neutralino = r.$neu || r.$neutralino || r.$cneu;
return r;
}
const getPackageJSON = (p)=>{
if(Array.isArray(p)){
for(let i in p){
const r = getPackageJSON(p[i]);
if(r) return r;
}
}
if(typeof p =='string' && p && fs.existsSync(p) && p.toLowerCase().trim().endsWith(".json")) return p;
return null;
}