Skip to content

Commit 98122fa

Browse files
author
Osama Mohammad Najjar
authored
Merge pull request #9 from mendix/fix-ASC20
Fix-ASC20
2 parents d76b371 + f9ff20c commit 98122fa

31 files changed

+9107
-13068
lines changed

.jshintrc

Lines changed: 0 additions & 23 deletions
This file was deleted.

Cropper/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules/
2+
build/
3+
dist/
4+
5+
test/*
6+
!test/widgets
7+
!test/TestCrop.mpr
8+
9+
.mxlocal.config.js

Cropper/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Cropper
2+
Image Cropping Widget
3+
4+
## Install dependencies
5+
6+
`npm install` or `yarn install`
7+
8+
9+
## Available Scripts
10+
11+
- `npm run dev` or `yarn dev`
12+
will watch for any changes you made and build unoptimized version of your widget with a source map for debugging.
13+
14+
- `npm run build` or `yarn build`
15+
will build an optimized (minified & uglified) version of your widget & no source maps will be genrated.

Cropper/conf/paths.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const path = require('path');
2+
let localConfFilePath = "../.mxlocal.config",
3+
localConf = false;
4+
if (moduleExists(localConfFilePath)) {
5+
localConf = require(localConfFilePath);
6+
}
7+
// if there is a local conf then use it otherwise use the default/general
8+
const mxProjectRootDir = localConf && localConf.mxProjectRootDir ? localConf.mxProjectRootDir : path.join(__dirname, "..", "test");
9+
10+
module.exports = {
11+
srcDir: path.join(__dirname, '..', 'src'),
12+
srcEntry: './src/index.js',
13+
confDir: __dirname,
14+
distDir: path.join(__dirname, '..', 'dist'),
15+
buildDir: path.join(__dirname, '..', 'build'),
16+
mxProjectRootDir,
17+
widgetPackageXML: path.join(__dirname, '..', 'src', 'package.ejs'),
18+
widgetConfigXML: path.join(__dirname, '..', 'src', 'widget.config.ejs')
19+
};
20+
21+
function moduleExists(modulePath) {
22+
try {
23+
return require.resolve(modulePath);
24+
} catch (e) {
25+
return false;
26+
}
27+
}

Cropper/conf/postcss.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
plugins: [
3+
require('autoprefixer'),
4+
require('postcss-clean'),
5+
require('cssnano')({
6+
preset: [
7+
'default',
8+
{
9+
discardComments: {
10+
removeAll: true
11+
}
12+
}
13+
]
14+
})
15+
]
16+
};

Cropper/conf/webpack.config.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
const paths = require('./paths');
2+
const widgetConf = require('./widget.config.json');
3+
const XMLPlugin = require('xml-webpack-plugin');
4+
const ArchivePlugin = require('webpack-archive-plugin');
5+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6+
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
7+
const fs = require('fs-extra');
8+
9+
const MODES = {
10+
DEV: 'development',
11+
PROD: 'production'
12+
};
13+
const isProd = process.env.MODE === MODES.PROD;
14+
const isDev = process.env.MODE === MODES.DEV;
15+
16+
const widgetDir = `${widgetConf.name}/widget`;
17+
const widgetUIDir = `${widgetDir}/ui`;
18+
19+
const widgetXMLFiles = [
20+
{
21+
template: paths.widgetPackageXML,
22+
filename: `package.xml`,
23+
data: {
24+
NAME: widgetConf.name
25+
}
26+
},
27+
{
28+
template: paths.widgetConfigXML,
29+
filename: `${widgetConf.name}/${widgetConf.name}.xml`,
30+
data: {
31+
NAME: widgetConf.name,
32+
FRIENDLY_NAME: widgetConf.friendlyName,
33+
WIDGET_DESC: widgetConf.description
34+
}
35+
}
36+
];
37+
38+
module.exports = {
39+
mode: isDev ? MODES.DEV : MODES.PROD,
40+
target: 'web',
41+
devtool: isDev ? 'eval-source-map' : false,
42+
watch: isDev,
43+
entry: paths.srcEntry,
44+
output: {
45+
path: isDev ? paths.buildDir : paths.distDir,
46+
filename: `${widgetDir}/${widgetConf.name}.js`,
47+
libraryTarget: 'amd'
48+
},
49+
optimization: {
50+
minimizer: [
51+
new UglifyJsPlugin({
52+
test: /\.js(\?.*)?$/i
53+
})
54+
]
55+
},
56+
module: {
57+
rules: [
58+
{
59+
test: /\.js$/,
60+
exclude: /node_modules/,
61+
use: {
62+
loader: 'babel-loader',
63+
options: {
64+
presets: [ '@babel/preset-env' ],
65+
plugins: [ 'add-module-exports' ]
66+
}
67+
}
68+
},
69+
{
70+
test: /\.(sa|sc|c)ss$/,
71+
use: [
72+
MiniCssExtractPlugin.loader,
73+
'css-loader',
74+
{ loader: 'postcss-loader', options: { config: { path: paths.confDir } } },
75+
'sass-loader'
76+
]
77+
},
78+
{
79+
test: /\.(gif|png|jpe?g|svg)$/i,
80+
use: [
81+
{
82+
loader: 'file-loader',
83+
options: {
84+
name: `[name].[ext]`,
85+
outputPath: `${widgetUIDir}/images`
86+
}
87+
}
88+
]
89+
}
90+
]
91+
},
92+
externals: [
93+
{ MxWidgetBase: 'mxui/widget/_WidgetBase' },
94+
{ dojoBaseDeclare: 'dojo/_base/declare' },
95+
/mx|mxui|mendix|dijit|dojo|require/
96+
],
97+
plugins: _getPlugins()
98+
};
99+
100+
function _getPlugins() {
101+
//ensure distDir fir Archive Plugin
102+
fs.ensureDirSync(paths.distDir);
103+
const plugins = [
104+
new MiniCssExtractPlugin({
105+
filename: `${widgetUIDir}/${widgetConf.name}.css`
106+
}),
107+
new XMLPlugin({
108+
files: widgetXMLFiles
109+
}),
110+
new ArchivePlugin({
111+
output: `${paths.distDir}/${widgetConf.name}`,
112+
format: 'zip',
113+
ext: 'mpk'
114+
})
115+
];
116+
if (paths.mxProjectRootDir) {
117+
plugins.push(
118+
new ArchivePlugin({
119+
output: `${paths.mxProjectRootDir}/widgets/${widgetConf.name}`,
120+
format: 'zip',
121+
ext: 'mpk'
122+
})
123+
);
124+
}
125+
return plugins;
126+
}

Cropper/conf/widget.config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "cropper",
3+
"friendlyName": "Image Cropper",
4+
"description": "Image cropper."
5+
}

0 commit comments

Comments
 (0)