@apia/cli 4.0.14 → 4.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/{cli.js → cli.cjs} +27 -21
- package/cli/component_base.tsx +49 -30
- package/cli/{findFileInAncestors.js → findFileInAncestors.cjs} +1 -1
- package/cli/webpack.config.cjs +124 -27
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -13
- /package/cli/{askQuestion.js → askQuestion.cjs} +0 -0
package/cli/{cli.js → cli.cjs}
RENAMED
|
@@ -1,32 +1,37 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { program } = require('commander');
|
|
4
|
-
const {
|
|
4
|
+
const { spawn } = require('child_process');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const fs = require('fs');
|
|
7
|
-
const findFileInAncestors = require('./findFileInAncestors')
|
|
7
|
+
const findFileInAncestors = require('./findFileInAncestors.cjs')
|
|
8
|
+
const chalk = require('chalk')
|
|
8
9
|
|
|
9
10
|
const logger = {
|
|
10
11
|
log(...what) {
|
|
11
12
|
console.log(...what);
|
|
12
13
|
},
|
|
13
14
|
error(error) {
|
|
14
|
-
console.error('[ERROR] ', error)
|
|
15
|
+
console.error(chalk.red('[ERROR] '), error)
|
|
15
16
|
},
|
|
16
17
|
internalE(error) {
|
|
17
|
-
console.error('[INTERNAL ERROR] ', error)
|
|
18
|
+
console.error(chalk.red('[INTERNAL ERROR] '), error)
|
|
18
19
|
},
|
|
19
20
|
warn(warn) {
|
|
20
|
-
console.warn('[WARNING] ',
|
|
21
|
+
console.warn(chalk.yellow('[WARNING] '), warn)
|
|
21
22
|
},
|
|
22
23
|
info(info) {
|
|
23
|
-
console.
|
|
24
|
+
console.log(chalk.blue('[INFO] '), info)
|
|
24
25
|
},
|
|
25
26
|
success(success) {
|
|
26
|
-
console.log('[SUCCESS] ', success)
|
|
27
|
+
console.log(chalk.green('[SUCCESS] '), success)
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
function componentFolderResolver(componentName) {
|
|
32
|
+
return path.resolve(process.cwd(), 'components', componentName)
|
|
33
|
+
}
|
|
34
|
+
|
|
30
35
|
/**
|
|
31
36
|
* Starts webpack on the given component.
|
|
32
37
|
*
|
|
@@ -47,22 +52,23 @@ program
|
|
|
47
52
|
|
|
48
53
|
let envFile = findFileInAncestors('.env');
|
|
49
54
|
if (envFile !== undefined) {
|
|
50
|
-
const outDir = envFile.content.match(
|
|
51
|
-
if (outDir) {
|
|
52
|
-
const
|
|
53
|
-
|
|
55
|
+
const outDir = envFile.content.match(/APIA_4004 *= *([^\n]+)/);
|
|
56
|
+
if (outDir?.[1]) {
|
|
57
|
+
const actualOutput = path.resolve(outDir[1], 'react', 'customComponents', parsedName)
|
|
58
|
+
|
|
59
|
+
const targetComponentIndex = path.resolve(`${componentFolderResolver(parsedName)}/index.tsx`);
|
|
60
|
+
const webpackConfig = path.resolve(__dirname, 'webpack.config.cjs');
|
|
54
61
|
|
|
55
62
|
logger.info(`Building project with:
|
|
56
63
|
- Entry: ${targetComponentIndex}
|
|
57
|
-
- Output: ${
|
|
58
|
-
- Webpack config: ${
|
|
59
|
-
|
|
60
|
-
// Build with the specified inputs
|
|
61
|
-
execSync(`npx webpack --config "${webpackConfig}" --entry "${targetComponentIndex}" --output-filename "${outDir}.js" ${watch ? '--watch' : ''}`, { stdio: 'inherit' });
|
|
64
|
+
- Output: ${actualOutput}
|
|
65
|
+
- Webpack config: ${webpackConfig}`);
|
|
62
66
|
|
|
63
|
-
|
|
67
|
+
spawn('npx',
|
|
68
|
+
[`webpack --config "${webpackConfig}" --entry "${targetComponentIndex}" --output-path "${actualOutput}" --output-filename="index.js" ${watch ? '--mode=development' : ''} ${watch ? '--watch' : ''}`]
|
|
69
|
+
, { shell: true, stdio: ['inherit', 'inherit', 'inherit'] });
|
|
64
70
|
} else {
|
|
65
|
-
throw new Error("Cannot find
|
|
71
|
+
throw new Error("Cannot find APIA_4004 in " + envFile.fileName);
|
|
66
72
|
}
|
|
67
73
|
} else {
|
|
68
74
|
throw new Error("Cannot find .env file");
|
|
@@ -80,7 +86,7 @@ program
|
|
|
80
86
|
.description('Creates the boilerplate for the given component name.')
|
|
81
87
|
.action((componentName) => {
|
|
82
88
|
const parsedName = componentName.charAt(0).toUpperCase() + componentName.slice(1)
|
|
83
|
-
const destinationFile = path.resolve(
|
|
89
|
+
const destinationFile = path.resolve(componentFolderResolver(parsedName), 'index.tsx');
|
|
84
90
|
const sourcePath = path.resolve(__dirname, 'component_base.tsx');
|
|
85
91
|
|
|
86
92
|
if (fs.existsSync(destinationFile)) {
|
|
@@ -88,7 +94,7 @@ program
|
|
|
88
94
|
process.exit(1);
|
|
89
95
|
} else {
|
|
90
96
|
|
|
91
|
-
const destinationDir =
|
|
97
|
+
const destinationDir = componentFolderResolver(parsedName);
|
|
92
98
|
if (!fs.existsSync(destinationDir)) {
|
|
93
99
|
fs.mkdirSync(destinationDir, { recursive: true })
|
|
94
100
|
}
|
package/cli/component_base.tsx
CHANGED
|
@@ -1,40 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Plugin } from '
|
|
3
|
-
import {
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { AbstractCustomComponent, Plugin } from '@apia/execution-react';
|
|
3
|
+
import { makeObservable, observable } from 'mobx';
|
|
4
|
+
import { SimpleButton } from '@apia/components';
|
|
4
5
|
import { observer } from 'mobx-react-lite';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
/**
|
|
8
|
+
* README:
|
|
9
|
+
*
|
|
10
|
+
* In order to run the following component, the declarations in the Java AbstractCustomComponent must include
|
|
11
|
+
* an attribute named 'selectedPlan'.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
\@CustomComponentAttribute(name = "selectedPlan", title = "lblPlnSel", description = "lblPlnSel")
|
|
15
|
+
public Attribute selectedPlan;
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export default class __COMPONENT_NAME__ extends AbstractCustomComponent {
|
|
19
|
+
state = {
|
|
20
|
+
count: 0,
|
|
13
21
|
};
|
|
14
22
|
|
|
15
23
|
constructor() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get count() {
|
|
22
|
-
return this.state.counter;
|
|
24
|
+
super();
|
|
25
|
+
makeObservable(this, { state: observable });
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
protected Component: FC = observer(() => {
|
|
29
|
+
return (
|
|
30
|
+
<>
|
|
31
|
+
<Input
|
|
32
|
+
value={this.getIntermediateString('selectedPlan')}
|
|
33
|
+
onChange={(ev) =>
|
|
34
|
+
this.setIntermediateStringValue('selectedPlan', ev.target.value)
|
|
35
|
+
}
|
|
36
|
+
onBlur={(ev: any) => {
|
|
37
|
+
this.confirmIntermediateString('selectedPlan', ev.target.value);
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
<SimpleButton
|
|
41
|
+
onClick={() => {
|
|
42
|
+
this.state.count++;
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
Counter {this.state.count}
|
|
46
|
+
</SimpleButton>
|
|
47
|
+
<SimpleButton
|
|
48
|
+
onClick={() => {
|
|
49
|
+
this.state.count++;
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
Counter {this.state.count}
|
|
53
|
+
</SimpleButton>
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
});
|
|
28
57
|
}
|
|
29
58
|
|
|
30
|
-
const __COMPONENT_NAME__ = observer(() => {
|
|
31
|
-
const controller = useMemo(() => new __COMPONENT_NAME__Controller(), []);
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<button onClick={() => controller.sum()}>
|
|
35
|
-
Hello world {controller.count}
|
|
36
|
-
</button>
|
|
37
|
-
);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
59
|
new Plugin('__COMPONENT_NAME__', __COMPONENT_NAME__);
|
|
@@ -18,7 +18,7 @@ function findFileInAncestors(fileName) {
|
|
|
18
18
|
|
|
19
19
|
searchAgain = !fs.existsSync(currentEnv);
|
|
20
20
|
if (!searchAgain) {
|
|
21
|
-
return { fileName: currentEnv, content: fs.readFileSync(currentEnv) };
|
|
21
|
+
return { fileName: currentEnv, content: fs.readFileSync(currentEnv, { encoding: 'utf8' }) };
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const aux = currentDir;
|
package/cli/webpack.config.cjs
CHANGED
|
@@ -1,32 +1,129 @@
|
|
|
1
|
+
const TerserPlugin = require('terser-webpack-plugin');
|
|
1
2
|
const WrapperPlugin = require('wrapper-webpack-plugin');
|
|
2
3
|
const path = require('path')
|
|
4
|
+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
|
5
|
+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
3
6
|
|
|
4
|
-
module.exports = {
|
|
5
|
-
mode
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
module.exports = (_, argv) => {
|
|
8
|
+
const mode = process.env.buildmode || 'production';
|
|
9
|
+
const isDevelopment = mode === "development";
|
|
10
|
+
const analyzeBundle = false && !isDevelopment;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
cache: isDevelopment ? { type: 'memory' } : false,
|
|
14
|
+
mode: isDevelopment ? 'development' : 'production',
|
|
15
|
+
devtool: 'source-map',
|
|
16
|
+
module: {
|
|
17
|
+
rules: [
|
|
18
|
+
{
|
|
19
|
+
test: /\.(t|j)sx?$/,
|
|
20
|
+
enforce: "pre",
|
|
21
|
+
use: ["source-map-loader"],
|
|
22
|
+
exclude: /plotly.js/
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
test: /\.tsx?$/,
|
|
26
|
+
use: [
|
|
27
|
+
{
|
|
28
|
+
loader: 'ts-loader',
|
|
29
|
+
options: {
|
|
30
|
+
transpileOnly: true
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
test: /\.m?js$/,
|
|
37
|
+
resolve: {
|
|
38
|
+
fullySpecified: false,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
externals: { // See plugins.ts
|
|
44
|
+
react: 'react',
|
|
45
|
+
'@apia/components': 'apiaComponents',
|
|
46
|
+
'@apia/execution-react': 'execReact',
|
|
47
|
+
'@apia/theme': 'apiaTheme',
|
|
48
|
+
'@apia/util': 'apiaUtil',
|
|
49
|
+
mobx: 'mobx',
|
|
50
|
+
'mobx-react-lite': 'mobxReact'
|
|
51
|
+
},
|
|
52
|
+
resolve: {
|
|
53
|
+
extensions: ['.tsx', '.ts', '.js', '.css'],
|
|
54
|
+
},
|
|
55
|
+
plugins: [
|
|
56
|
+
new ForkTsCheckerWebpackPlugin(),
|
|
57
|
+
analyzeBundle && new BundleAnalyzerPlugin(),
|
|
58
|
+
new WrapperPlugin({
|
|
59
|
+
test: /\.(ts|js)x?$/, // only wrap output of bundle files with '.js' extension
|
|
60
|
+
header: 'function init() {\n',
|
|
61
|
+
footer: `\n}; if(window.react) { init(); } else {throw new Error("No react") }`,
|
|
62
|
+
afterOptimizations: true,
|
|
63
|
+
})
|
|
64
|
+
].filter(Boolean),
|
|
65
|
+
resolve: {
|
|
66
|
+
modules: ['node_modules'],
|
|
67
|
+
extensions: ['.ts', '.tsx', '.js', '.json'],
|
|
68
|
+
symlinks: true,
|
|
69
|
+
fallback: {
|
|
70
|
+
xml2js: path.resolve('./node_modules/xml2js'),
|
|
71
|
+
zlib: false,
|
|
72
|
+
http: false,
|
|
73
|
+
https: false,
|
|
74
|
+
emitter: false,
|
|
75
|
+
path: false,
|
|
76
|
+
fs: false,
|
|
77
|
+
tty: false,
|
|
78
|
+
os: false,
|
|
79
|
+
timers: false,
|
|
80
|
+
stream: false,
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
optimization: {
|
|
84
|
+
nodeEnv: 'production',
|
|
85
|
+
minimize: !isDevelopment,
|
|
86
|
+
minimizer: [!isDevelopment && new TerserPlugin({
|
|
87
|
+
extractComments: true,
|
|
88
|
+
parallel: true,
|
|
89
|
+
minify: TerserPlugin.terserMinify,
|
|
90
|
+
terserOptions: {
|
|
91
|
+
keep_classnames: true,
|
|
92
|
+
toplevel: true,
|
|
93
|
+
compress: {
|
|
94
|
+
warnings: true,
|
|
95
|
+
drop_debugger: true,
|
|
96
|
+
pure_funcs: ['console.log', 'console.table'],
|
|
97
|
+
dead_code: true,
|
|
98
|
+
},
|
|
99
|
+
output: {},
|
|
100
|
+
sourceMap: true,
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
103
|
+
].filter(Boolean),
|
|
104
|
+
removeAvailableModules: !isDevelopment,
|
|
105
|
+
},
|
|
106
|
+
resolve: {
|
|
107
|
+
alias: {
|
|
108
|
+
config: path.resolve(__dirname, './src/config/prod.ts'),
|
|
12
109
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
110
|
+
modules: ['node_modules'],
|
|
111
|
+
extensions: ['.ts', '.tsx', '.js', '.json'],
|
|
112
|
+
symlinks: true,
|
|
113
|
+
fallback: {
|
|
114
|
+
zlib: false,
|
|
115
|
+
http: false,
|
|
116
|
+
https: false,
|
|
117
|
+
emitter: false,
|
|
118
|
+
path: false,
|
|
119
|
+
fs: false,
|
|
120
|
+
tty: false,
|
|
121
|
+
os: false,
|
|
122
|
+
timers: false,
|
|
123
|
+
stream: false,
|
|
124
|
+
xml2js: path.resolve('./node_modules/xml2js'),
|
|
125
|
+
'react-focus-lock': path.resolve('./node_modules/react-focus-lock')
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
}
|
|
32
129
|
};
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/Plugin.ts"],"sourcesContent":["import { EventEmitter } from '@apia/util';\r\n\r\ndeclare global {\r\n interface Window {\r\n dispatchComponent: EventEmitter<{\r\n dispatch: any;\r\n ready: null;\r\n }>;\r\n }\r\n}\r\n\r\nexport class Plugin {\r\n constructor(name: string, fc: any) {\r\n window.dispatchComponent.
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/Plugin.ts"],"sourcesContent":["import { EventEmitter } from '@apia/util';\r\n\r\ndeclare global {\r\n interface Window {\r\n dispatchComponent: EventEmitter<{\r\n dispatch: any;\r\n ready: null;\r\n }>;\r\n }\r\n}\r\n\r\nexport class Plugin {\r\n constructor(name: string, fc: any) {\r\n window.dispatchComponent.once('ready', () => {\r\n window.dispatchComponent.emit('dispatch', { name, fc });\r\n });\r\n }\r\n}\r\n"],"names":[],"mappings":"AAWO,MAAM,MAAO,CAAA;AAAA,EAClB,WAAA,CAAY,MAAc,EAAS,EAAA;AACjC,IAAO,MAAA,CAAA,iBAAA,CAAkB,IAAK,CAAA,OAAA,EAAS,MAAM;AAC3C,MAAA,MAAA,CAAO,kBAAkB,IAAK,CAAA,UAAA,EAAY,EAAE,IAAA,EAAM,IAAI,CAAA;AAAA,KACvD,CAAA;AAAA;AAEL;;;;"}
|
package/package.json
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apia/cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.15",
|
|
4
4
|
"sideEffects": true,
|
|
5
5
|
"author": "Alexis Leite <alexisleite@live.com>",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"module": "dist/index.js",
|
|
8
|
-
"type": "module",
|
|
9
|
-
"typings": "dist/index.d.ts",
|
|
10
6
|
"bin": {
|
|
11
|
-
"apia": "./cli/cli.
|
|
12
|
-
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"libDev": "rollup --config ../../config/rollup.common.mjs --environment MODE:development,ENTRY:index.ts",
|
|
15
|
-
"libBuild": "rollup --config ../../config/rollup.common.mjs --environment MODE:production,ENTRY:index.ts",
|
|
16
|
-
"libWatch": "rollup --watch --config ../../config/rollup.common.mjs --environment MODE:development,ENTRY:index.ts,WATCH:true"
|
|
7
|
+
"apia": "./cli/cli.cjs"
|
|
17
8
|
},
|
|
18
9
|
"dependencies": {
|
|
19
|
-
"
|
|
10
|
+
"chalk": "^4.1.2",
|
|
20
11
|
"commander": "^12.0.0"
|
|
21
12
|
},
|
|
22
13
|
"publishConfig": {
|
|
23
14
|
"access": "public",
|
|
24
15
|
"registry": "https://registry.npmjs.org/"
|
|
25
16
|
},
|
|
26
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "893eb39744c85737b54df181b2919a51963fcc81",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"ts-loader": "^9.5.2"
|
|
20
|
+
}
|
|
27
21
|
}
|
|
File without changes
|