@codelet/cli-service 0.0.1
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/bin/codelet-cli-service.js +3 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +34 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.js +108 -0
- package/dist/defineConfig.d.ts +2 -0
- package/dist/defineConfig.js +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +69 -0
- package/package.json +54 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const argv = process.argv;
|
|
9
|
+
const options = (0, utils_1.parseArgv)(argv);
|
|
10
|
+
const config = (0, utils_1.getConfig)(options);
|
|
11
|
+
const callback = (err, stats) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
throw err;
|
|
14
|
+
}
|
|
15
|
+
if (stats) {
|
|
16
|
+
console.log(stats.toString({
|
|
17
|
+
chunks: false,
|
|
18
|
+
colors: true,
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
if (config.watch) {
|
|
23
|
+
(0, webpack_1.default)(config, callback);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
(0, webpack_1.default)(config).run(callback);
|
|
27
|
+
}
|
|
28
|
+
// 退出
|
|
29
|
+
process.on('SIGINT', () => {
|
|
30
|
+
process.exit();
|
|
31
|
+
});
|
|
32
|
+
process.on('SIGTERM', () => {
|
|
33
|
+
process.exit();
|
|
34
|
+
});
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Configuration } from 'webpack';
|
|
2
|
+
export interface Config extends Configuration {
|
|
3
|
+
/** 开发路径默认 src */
|
|
4
|
+
entryPath?: string;
|
|
5
|
+
source?: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function getDefaultConfig(): Configuration & {
|
|
8
|
+
entryPath: string;
|
|
9
|
+
source: string[];
|
|
10
|
+
};
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDefaultConfig = void 0;
|
|
7
|
+
const webpackbar_1 = __importDefault(require("webpackbar"));
|
|
8
|
+
const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
|
9
|
+
const inject_chunk_webpack_plugin_1 = __importDefault(require("@codelet/inject-chunk-webpack-plugin"));
|
|
10
|
+
const app_json_webpack_plugin_1 = __importDefault(require("@codelet/app-json-webpack-plugin"));
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
function getDefaultConfig() {
|
|
13
|
+
const entryPath = './src';
|
|
14
|
+
return {
|
|
15
|
+
entryPath,
|
|
16
|
+
source: ['app.(js|ts)', 'pages/**/*.(js|ts)', 'components/**/*.(js|ts)'],
|
|
17
|
+
mode: 'production',
|
|
18
|
+
devtool: false,
|
|
19
|
+
output: {
|
|
20
|
+
filename: '[name].js',
|
|
21
|
+
path: (0, utils_1.resolve)('dist'),
|
|
22
|
+
publicPath: '/',
|
|
23
|
+
clean: true,
|
|
24
|
+
},
|
|
25
|
+
resolve: {
|
|
26
|
+
alias: {
|
|
27
|
+
'@': (0, utils_1.resolve)('src'),
|
|
28
|
+
},
|
|
29
|
+
extensions: ['.js', '.ts'],
|
|
30
|
+
},
|
|
31
|
+
module: {
|
|
32
|
+
rules: [
|
|
33
|
+
{
|
|
34
|
+
oneOf: [
|
|
35
|
+
{
|
|
36
|
+
test: /\.(css|wxss)$/,
|
|
37
|
+
use: [mini_css_extract_plugin_1.default.loader, 'css-loader'],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
test: /\.s(a|c)ss$/,
|
|
41
|
+
use: [mini_css_extract_plugin_1.default.loader, 'css-loader', 'sass-loader'],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
test: /\.wxml$/,
|
|
45
|
+
loader: '@codelet/wxml-loader',
|
|
46
|
+
options: {
|
|
47
|
+
entryPath,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
test: /\.wxs$/,
|
|
52
|
+
loader: '@codelet/copy-loader',
|
|
53
|
+
options: {
|
|
54
|
+
entryPath,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
test: /\.json$/,
|
|
59
|
+
type: 'javascript/auto',
|
|
60
|
+
loader: '@codelet/copy-loader',
|
|
61
|
+
options: {
|
|
62
|
+
entryPath,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
test: /\.(png|jpe?g|gif|svg)$/,
|
|
67
|
+
type: 'asset/resource',
|
|
68
|
+
generator: {
|
|
69
|
+
filename: 'assets/images/[name][ext]',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
test: /\.(ts|js)$/,
|
|
74
|
+
loader: 'babel-loader',
|
|
75
|
+
options: {
|
|
76
|
+
cacheDirectory: true, // 开启 babel 缓存
|
|
77
|
+
cacheCompression: false, // 关闭缓存文件压缩
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
plugins: [
|
|
85
|
+
new mini_css_extract_plugin_1.default({
|
|
86
|
+
filename: '[name].wxss',
|
|
87
|
+
}),
|
|
88
|
+
new inject_chunk_webpack_plugin_1.default(),
|
|
89
|
+
new app_json_webpack_plugin_1.default(),
|
|
90
|
+
new webpackbar_1.default(),
|
|
91
|
+
],
|
|
92
|
+
optimization: {
|
|
93
|
+
splitChunks: {
|
|
94
|
+
chunks: 'all',
|
|
95
|
+
minChunks: 2,
|
|
96
|
+
minSize: 0,
|
|
97
|
+
cacheGroups: {
|
|
98
|
+
main: {
|
|
99
|
+
name: 'bundle',
|
|
100
|
+
minChunks: 2,
|
|
101
|
+
chunks: 'all',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
exports.getDefaultConfig = getDefaultConfig;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./defineConfig"), exports);
|
|
18
|
+
__exportStar(require("./config"), exports);
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Configuration } from 'webpack';
|
|
2
|
+
export declare const cmd: string;
|
|
3
|
+
export declare const resolve: (...args: string[]) => string;
|
|
4
|
+
export declare const parseDir: (entryPath: string, source: string[]) => {
|
|
5
|
+
entry: Record<string, {
|
|
6
|
+
import: string;
|
|
7
|
+
runtime: string;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
export declare function getOptionValue(argv: string[], option: string): string | undefined;
|
|
11
|
+
export declare function parseArgv(argv: string[]): {
|
|
12
|
+
configPath: string;
|
|
13
|
+
isWatch: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare function getConfig(options: {
|
|
16
|
+
configPath: string;
|
|
17
|
+
isWatch: boolean;
|
|
18
|
+
}): Configuration;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getConfig = exports.parseArgv = exports.getOptionValue = exports.parseDir = exports.resolve = exports.cmd = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
11
|
+
const config_1 = require("./config");
|
|
12
|
+
exports.cmd = process.cwd();
|
|
13
|
+
const resolve = (...args) => path_1.default.resolve(exports.cmd, ...args);
|
|
14
|
+
exports.resolve = resolve;
|
|
15
|
+
const parseDir = (entryPath, source) => {
|
|
16
|
+
entryPath = (0, exports.resolve)(entryPath);
|
|
17
|
+
const filepaths = fast_glob_1.default.sync(source.map((item) => (0, exports.resolve)(entryPath, item)));
|
|
18
|
+
const entry = filepaths.reduce((res, filepath) => {
|
|
19
|
+
const relPath = path_1.default.relative(entryPath, filepath);
|
|
20
|
+
const { dir, name } = path_1.default.parse(relPath);
|
|
21
|
+
res[path_1.default.join(dir, name)] = {
|
|
22
|
+
import: filepath,
|
|
23
|
+
runtime: 'bundle',
|
|
24
|
+
};
|
|
25
|
+
return res;
|
|
26
|
+
}, {});
|
|
27
|
+
return { entry };
|
|
28
|
+
};
|
|
29
|
+
exports.parseDir = parseDir;
|
|
30
|
+
function getOptionValue(argv, option) {
|
|
31
|
+
const index = argv.findIndex((item) => item === option);
|
|
32
|
+
if (index > -1) {
|
|
33
|
+
return argv[index + 1];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.getOptionValue = getOptionValue;
|
|
37
|
+
function parseArgv(argv) {
|
|
38
|
+
const isWatch = argv.includes('--watch');
|
|
39
|
+
const configRelativePath = getOptionValue(argv, '--config') || 'codelet.config.js';
|
|
40
|
+
const configPath = (0, exports.resolve)(configRelativePath);
|
|
41
|
+
return { configPath, isWatch };
|
|
42
|
+
}
|
|
43
|
+
exports.parseArgv = parseArgv;
|
|
44
|
+
function getConfig(options) {
|
|
45
|
+
const { configPath, isWatch } = options;
|
|
46
|
+
let config = (0, config_1.getDefaultConfig)();
|
|
47
|
+
if (fs_1.default.existsSync(configPath)) {
|
|
48
|
+
const options = require(configPath);
|
|
49
|
+
if (typeof options === 'function') {
|
|
50
|
+
config = options(config);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
if (options.source) {
|
|
54
|
+
delete config.source;
|
|
55
|
+
}
|
|
56
|
+
config = (0, webpack_merge_1.default)(config, options);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const { entryPath, source, ...rest } = config;
|
|
60
|
+
if (!rest.entry) {
|
|
61
|
+
const { entry } = (0, exports.parseDir)(entryPath, source);
|
|
62
|
+
rest.entry = entry;
|
|
63
|
+
}
|
|
64
|
+
if (isWatch) {
|
|
65
|
+
rest.watch = true;
|
|
66
|
+
}
|
|
67
|
+
return rest;
|
|
68
|
+
}
|
|
69
|
+
exports.getConfig = getConfig;
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codelet/cli-service",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "cli-service",
|
|
5
|
+
"bin": {
|
|
6
|
+
"codelet-cli-service": "./bin/codelet-cli-service.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"registry": "https://registry.npmjs.org/"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin",
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"daysnap",
|
|
20
|
+
"codelet",
|
|
21
|
+
"wechat",
|
|
22
|
+
"miniprogram",
|
|
23
|
+
"cli-service",
|
|
24
|
+
"mini"
|
|
25
|
+
],
|
|
26
|
+
"author": "woshiajuana",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@babel/core": "^7.23.7",
|
|
30
|
+
"@babel/preset-env": "^7.23.8",
|
|
31
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
32
|
+
"babel-loader": "^9.1.3",
|
|
33
|
+
"css-loader": "^6.9.0",
|
|
34
|
+
"fast-glob": "^3.3.2",
|
|
35
|
+
"mini-css-extract-plugin": "^2.7.7",
|
|
36
|
+
"sass": "^1.69.7",
|
|
37
|
+
"sass-loader": "^13.3.3",
|
|
38
|
+
"webpack": "^5.89.0",
|
|
39
|
+
"webpack-merge": "^5.10.0",
|
|
40
|
+
"webpackbar": "^6.0.0",
|
|
41
|
+
"@codelet/app-json-webpack-plugin": "^0.0.1",
|
|
42
|
+
"@codelet/inject-chunk-webpack-plugin": "^0.0.1",
|
|
43
|
+
"@codelet/wxml-loader": "^0.0.1",
|
|
44
|
+
"@codelet/copy-loader": "^0.0.1"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"rimraf": "^5.0.5"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "npm run clean && tsc -p ./tsconfig.lib.json",
|
|
51
|
+
"clean": "rimraf ./dist",
|
|
52
|
+
"release": "npm run build && dsc publish --pnpm"
|
|
53
|
+
}
|
|
54
|
+
}
|