@eggjs/scripts 3.1.0

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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/bin/dev.cmd +3 -0
  4. package/bin/dev.js +5 -0
  5. package/bin/run.cmd +3 -0
  6. package/bin/run.js +5 -0
  7. package/dist/commonjs/baseCommand.d.ts +25 -0
  8. package/dist/commonjs/baseCommand.js +62 -0
  9. package/dist/commonjs/commands/start.d.ts +34 -0
  10. package/dist/commonjs/commands/start.js +350 -0
  11. package/dist/commonjs/commands/stop.d.ts +16 -0
  12. package/dist/commonjs/commands/stop.js +90 -0
  13. package/dist/commonjs/helper.d.ts +10 -0
  14. package/dist/commonjs/helper.js +61 -0
  15. package/dist/commonjs/index.d.ts +3 -0
  16. package/dist/commonjs/index.js +26 -0
  17. package/dist/commonjs/package.json +3 -0
  18. package/dist/commonjs/types.d.ts +9 -0
  19. package/dist/commonjs/types.js +3 -0
  20. package/dist/esm/baseCommand.d.ts +25 -0
  21. package/dist/esm/baseCommand.js +55 -0
  22. package/dist/esm/commands/start.d.ts +34 -0
  23. package/dist/esm/commands/start.js +344 -0
  24. package/dist/esm/commands/stop.d.ts +16 -0
  25. package/dist/esm/commands/stop.js +87 -0
  26. package/dist/esm/helper.d.ts +10 -0
  27. package/dist/esm/helper.js +51 -0
  28. package/dist/esm/index.d.ts +3 -0
  29. package/dist/esm/index.js +5 -0
  30. package/dist/esm/package.json +3 -0
  31. package/dist/esm/types.d.ts +9 -0
  32. package/dist/esm/types.js +2 -0
  33. package/dist/package.json +4 -0
  34. package/package.json +103 -0
  35. package/scripts/start-cluster.cjs +15 -0
  36. package/scripts/start-cluster.mjs +14 -0
  37. package/src/baseCommand.ts +68 -0
  38. package/src/commands/start.ts +384 -0
  39. package/src/commands/stop.ts +100 -0
  40. package/src/helper.ts +62 -0
  41. package/src/index.ts +8 -0
  42. package/src/types.ts +9 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-present Alibaba Group Holding Limited and other contributors.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # @eggjs/scripts
2
+
3
+ [![NPM version][npm-image]][npm-url]
4
+ [![Node.js CI](https://github.com/eggjs/scripts/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/scripts/actions/workflows/nodejs.yml)
5
+ [![Test coverage][codecov-image]][codecov-url]
6
+ [![npm download][download-image]][download-url]
7
+ [![Node.js Version](https://img.shields.io/node/v/@eggjs/scripts.svg?style=flat)](https://nodejs.org/en/download/)
8
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
9
+
10
+ [npm-image]: https://img.shields.io/npm/v/@eggjs/scripts.svg?style=flat-square
11
+ [npm-url]: https://npmjs.org/package/@eggjs/scripts
12
+ [codecov-image]: https://codecov.io/github/eggjs/scripts/coverage.svg?branch=master
13
+ [codecov-url]: https://codecov.io/github/eggjs/scripts?branch=master
14
+ [download-image]: https://img.shields.io/npm/dm/@eggjs/scripts.svg?style=flat-square
15
+ [download-url]: https://npmjs.org/package/@eggjs/scripts
16
+
17
+ deploy tool for egg project.
18
+
19
+ **Note: Windows is partially supported, see [#22](https://github.com/eggjs/egg-scripts/pull/22)**
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ npm i @eggjs/scripts --save
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Add `eggctl` to `package.json` scripts:
30
+
31
+ ```json
32
+ {
33
+ "scripts": {
34
+ "start": "eggctl start --daemon",
35
+ "stop": "eggctl stop"
36
+ }
37
+ }
38
+ ```
39
+
40
+ Then run as:
41
+
42
+ - `npm start`
43
+ - `npm stop`
44
+
45
+ **Note:** `egg-scripts` is not recommended to install global, you should install and use it as npm scripts.
46
+
47
+ ## Command
48
+
49
+ ### start
50
+
51
+ Start egg at prod mode.
52
+
53
+ ```bash
54
+ $ eggctl start [options] [baseDir]
55
+
56
+ # Usage
57
+ # eggctl start --port=7001
58
+ # eggctl start ./server
59
+ ```
60
+
61
+ - **Arguments**
62
+ - `baseDir` - directory of application, default to `process.cwd()`.
63
+ - **Options**
64
+ - `port` - listening port, default to `process.env.PORT`, if unset, egg will use `7001` as default.
65
+ - `title` - process title description, use for kill grep, default to `egg-server-${APP_NAME}`.
66
+ - `workers` - numbers of app workers, default to `process.env.EGG_WORKERS`, if unset, egg will use `os.cpus().length` as default.
67
+ - `daemon` - whether run at background daemon mode, don't use it if in docker mode.
68
+ - `framework` - specify framework that can be absolute path or npm package, default to auto detect.
69
+ - `env` - server env, default to `process.env.EGG_SERVER_ENV`, recommended to keep empty then use framwork default env.
70
+ - `stdout` - customize stdout file, default to `$HOME/logs/master-stdout.log`.
71
+ - `stderr` - customize stderr file, default to `$HOME/logs/master-stderr.log`.
72
+ - `timeout` - the maximum timeout when app starts, default to 300s.
73
+ - `ignore-stderr` - whether ignore stderr when app starts.
74
+ - `sourcemap` / `typescript` / `ts` - provides source map support for stack traces.
75
+ - `node` - customize node command path, default will find node from $PATH
76
+
77
+ ### stop
78
+
79
+ Stop egg gracefull.
80
+
81
+ **Note:** if exec without `--title`, it will kill all egg process.
82
+
83
+ ```bash
84
+ $ eggctl stop [options]
85
+
86
+ # Usage
87
+ # eggctl stop --title=example
88
+ ```
89
+
90
+ - **Options**
91
+ - `title` - process title description, use for kill grep.
92
+ - `timeout` - the maximum timeout when app stop, default to 5s.
93
+
94
+ ## Options in `package.json`
95
+
96
+ In addition to the command line specification, options can also be specified in `package.json`. However, the command line designation takes precedence.
97
+
98
+ ```js
99
+ {
100
+ "eggScriptsConfig": {
101
+ "port": 1234,
102
+ "ignore-stderr": true,
103
+ // will pass as `node --max-http-header-size=20000`
104
+ "node-options--max-http-header-size": "20000",
105
+ // will pass as `node --allow-wasi`
106
+ "node-options--allow-wasi": true
107
+ }
108
+ }
109
+ ```
110
+
111
+ ## Questions & Suggestions
112
+
113
+ Please open an issue [here](https://github.com/eggjs/egg/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc).
114
+
115
+ ## License
116
+
117
+ [MIT](LICENSE)
118
+
119
+ ## Contributors
120
+
121
+ [![Contributors](https://contrib.rocks/image?repo=eggjs/scripts)](https://github.com/eggjs/scripts/graphs/contributors)
122
+
123
+ Made with [contributors-img](https://contrib.rocks).
package/bin/dev.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
package/bin/dev.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env -S node --loader ts-node/esm --disable-warning=ExperimentalWarning
2
+
3
+ import { execute } from '@oclif/core';
4
+
5
+ await execute({ development: true, dir: import.meta.url });
package/bin/run.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node "%~dp0\run" %*
package/bin/run.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execute } from '@oclif/core';
4
+
5
+ await execute({ dir: import.meta.url });
@@ -0,0 +1,25 @@
1
+ import { Command, Flags, Interfaces } from '@oclif/core';
2
+ import { PackageEgg } from './types.js';
3
+ type Flags<T extends typeof Command> = Interfaces.InferredFlags<typeof BaseCommand['baseFlags'] & T['flags']>;
4
+ type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
5
+ export declare abstract class BaseCommand<T extends typeof Command> extends Command {
6
+ static enableJsonFlag: boolean;
7
+ static baseFlags: {};
8
+ protected flags: Flags<T>;
9
+ protected args: Args<T>;
10
+ protected env: {
11
+ [x: string]: string | undefined;
12
+ TZ?: string;
13
+ };
14
+ protected pkg: Record<string, any>;
15
+ protected isESM: boolean;
16
+ protected pkgEgg: PackageEgg;
17
+ protected globalExecArgv: string[];
18
+ init(): Promise<void>;
19
+ protected initBaseInfo(baseDir: string): Promise<void>;
20
+ protected catch(err: Error & {
21
+ exitCode?: number;
22
+ }): Promise<any>;
23
+ protected finally(_: Error | undefined): Promise<any>;
24
+ }
25
+ export {};
@@ -0,0 +1,62 @@
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.BaseCommand = void 0;
7
+ const node_util_1 = require("node:util");
8
+ const core_1 = require("@oclif/core");
9
+ const utility_1 = require("utility");
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const debug = (0, node_util_1.debuglog)('@eggjs/scripts/baseCommand');
12
+ class BaseCommand extends core_1.Command {
13
+ // add the --json flag
14
+ static enableJsonFlag = false;
15
+ // define flags that can be inherited by any command that extends BaseCommand
16
+ static baseFlags = {
17
+ // 'log-level': Flags.option({
18
+ // default: 'info',
19
+ // helpGroup: 'GLOBAL',
20
+ // options: ['debug', 'warn', 'error', 'info', 'trace'] as const,
21
+ // summary: 'Specify level for logging.',
22
+ // })(),
23
+ };
24
+ flags;
25
+ args;
26
+ env = { ...process.env };
27
+ pkg;
28
+ isESM;
29
+ pkgEgg;
30
+ globalExecArgv = [];
31
+ async init() {
32
+ await super.init();
33
+ debug('[init] raw args: %o, NODE_ENV: %o', this.argv, this.env.NODE_ENV);
34
+ const { args, flags } = await this.parse({
35
+ flags: this.ctor.flags,
36
+ baseFlags: super.ctor.baseFlags,
37
+ enableJsonFlag: this.ctor.enableJsonFlag,
38
+ args: this.ctor.args,
39
+ strict: this.ctor.strict,
40
+ });
41
+ this.flags = flags;
42
+ this.args = args;
43
+ }
44
+ async initBaseInfo(baseDir) {
45
+ const pkg = await (0, utility_1.readJSON)(node_path_1.default.join(baseDir, 'package.json'));
46
+ this.pkg = pkg;
47
+ this.pkgEgg = pkg.egg ?? {};
48
+ this.isESM = pkg.type === 'module';
49
+ debug('[initBaseInfo] baseDir: %o, pkgEgg: %o, isESM: %o', baseDir, this.pkgEgg, this.isESM);
50
+ }
51
+ async catch(err) {
52
+ // add any custom logic to handle errors from the command
53
+ // or simply return the parent class error handling
54
+ return super.catch(err);
55
+ }
56
+ async finally(_) {
57
+ // called after run and catch regardless of whether or not the command errored
58
+ return super.finally(_);
59
+ }
60
+ }
61
+ exports.BaseCommand = BaseCommand;
62
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZUNvbW1hbmQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYmFzZUNvbW1hbmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEseUNBQXFDO0FBQ3JDLHNDQUF5RDtBQUV6RCxxQ0FBbUM7QUFDbkMsMERBQTZCO0FBRTdCLE1BQU0sS0FBSyxHQUFHLElBQUEsb0JBQVEsRUFBQyw0QkFBNEIsQ0FBQyxDQUFDO0FBS3JELE1BQ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BQUksQ0FBQyxLQUFLLEdBQUcsS0FBaUIsQ0FBQztRQUMvQixJQUFJLENBQUMsSUFBSSxHQUFHLElBQWUsQ0FBQztJQUM5QixDQUFDO0lBRVMsS0FBSyxDQUFDLFlBQVksQ0FBQyxPQUFlO1FBQzFDLE1BQU0sR0FBRyxHQUFHLE1BQU0sSUFBQSxrQkFBUSxFQUFDLG1CQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sRUFBRSxjQUFjLENBQUMsQ0FBQyxDQUFDO1FBQy9ELElBQUksQ0FBQyxHQUFHLEdBQUcsR0FBRyxDQUFDO1FBQ2YsSUFBSSxDQUFDLE1BQU0sR0FBRyxHQUFHLENBQUMsR0FBRyxJQUFJLEVBQUUsQ0FBQztRQUM1QixJQUFJLENBQUMsS0FBSyxHQUFHLEdBQUcsQ0FBQyxJQUFJLEtBQUssUUFBUSxDQUFDO1FBQ25DLEtBQUssQ0FBQyxtREFBbUQsRUFBRSxPQUFPLEVBQUUsSUFBSSxDQUFDLE1BQU0sRUFBRSxJQUFJLENBQUMsS0FBSyxDQUFDLENBQUM7SUFDL0YsQ0FBQztJQUVTLEtBQUssQ0FBQyxLQUFLLENBQUMsR0FBZ0M7UUFDcEQseURBQXlEO1FBQ3pELG1EQUFtRDtRQUNuRCxPQUFPLEtBQUssQ0FBQyxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUM7SUFDMUIsQ0FBQztJQUVTLEtBQUssQ0FBQyxPQUFPLENBQUMsQ0FBb0I7UUFDMUMsOEVBQThFO1FBQzlFLE9BQU8sS0FBSyxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUMxQixDQUFDOztBQXRESCxrQ0F1REMifQ==
@@ -0,0 +1,34 @@
1
+ import { BaseCommand } from '../baseCommand.js';
2
+ export interface FrameworkOptions {
3
+ baseDir: string;
4
+ framework?: string;
5
+ }
6
+ export default class Start<T extends typeof Start> extends BaseCommand<T> {
7
+ #private;
8
+ static description: string;
9
+ static examples: string[];
10
+ static args: {
11
+ baseDir: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
12
+ };
13
+ static flags: {
14
+ title: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ framework: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ port: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ workers: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ env: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
19
+ daemon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
20
+ stdout: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
+ stderr: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
22
+ timeout: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
23
+ 'ignore-stderr': import("@oclif/core/interfaces").BooleanFlag<boolean>;
24
+ node: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
25
+ require: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
26
+ sourcemap: import("@oclif/core/interfaces").BooleanFlag<boolean>;
27
+ };
28
+ isReady: boolean;
29
+ protected getFrameworkPath(options: FrameworkOptions): Promise<string>;
30
+ protected getFrameworkName(frameworkPath: string): Promise<string>;
31
+ protected getServerBin(): Promise<string>;
32
+ run(): Promise<void>;
33
+ protected checkStatus(): Promise<void>;
34
+ }