@pnpm/plugin-commands-init 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
4
+ Copyright (c) 2016-2022 Zoltan Kochan and other contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @pnpm/plugin-commands-init
2
+
3
+ > Create a package.json file
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@pnpm/plugin-commands-init.svg)](https://www.npmjs.com/package/@pnpm/plugin-commands-init)
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pnpm add @pnpm/plugin-commands-init
11
+ ```
12
+
13
+ ## License
14
+
15
+ MIT
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import * as init from './init';
2
+ export { init };
package/lib/index.js ADDED
@@ -0,0 +1,29 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.init = void 0;
27
+ const init = __importStar(require("./init"));
28
+ exports.init = init;
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA8B;AAErB,oBAAI"}
package/lib/init.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { UniversalOptions } from '@pnpm/config';
2
+ export declare const rcOptionsTypes: typeof cliOptionsTypes;
3
+ export declare function cliOptionsTypes(): {};
4
+ export declare const commandNames: string[];
5
+ export declare function help(): string;
6
+ export declare function handler(opts: Pick<UniversalOptions, 'dir' | 'rawConfig'>): Promise<string>;
package/lib/init.js ADDED
@@ -0,0 +1,56 @@
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.handler = exports.help = exports.commandNames = exports.cliOptionsTypes = exports.rcOptionsTypes = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const cli_utils_1 = require("@pnpm/cli-utils");
10
+ const error_1 = __importDefault(require("@pnpm/error"));
11
+ const write_project_manifest_1 = __importDefault(require("@pnpm/write-project-manifest"));
12
+ const render_help_1 = __importDefault(require("render-help"));
13
+ const utils_1 = require("./utils");
14
+ exports.rcOptionsTypes = cliOptionsTypes;
15
+ function cliOptionsTypes() {
16
+ return {};
17
+ }
18
+ exports.cliOptionsTypes = cliOptionsTypes;
19
+ exports.commandNames = ['init'];
20
+ function help() {
21
+ return (0, render_help_1.default)({
22
+ description: 'Create a package.json file',
23
+ descriptionLists: [],
24
+ url: (0, cli_utils_1.docsUrl)('init'),
25
+ usages: ['pnpm init'],
26
+ });
27
+ }
28
+ exports.help = help;
29
+ async function handler(opts) {
30
+ const manifestPath = path_1.default.join(opts.dir, 'package.json');
31
+ if (fs_1.default.existsSync(manifestPath)) {
32
+ throw new error_1.default('PACKAGE_JSON_EXISTS', 'package.json already exists');
33
+ }
34
+ const manifest = {
35
+ name: path_1.default.basename(opts.dir),
36
+ version: '1.0.0',
37
+ description: '',
38
+ main: 'index.js',
39
+ scripts: {
40
+ test: 'echo "Error: no test specified" && exit 1',
41
+ },
42
+ keywords: [],
43
+ author: '',
44
+ license: 'ISC',
45
+ };
46
+ const config = await (0, utils_1.parseRawConfig)(opts.rawConfig);
47
+ const packageJson = { ...manifest, ...config };
48
+ await (0, write_project_manifest_1.default)(manifestPath, packageJson, {
49
+ indent: 2,
50
+ });
51
+ return `Wrote to ${path_1.default.join(opts.dir, 'package.json')}
52
+
53
+ ${JSON.stringify(packageJson, null, 2)}`;
54
+ }
55
+ exports.handler = handler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;IACnD,MAAM,WAAW,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,EAAE,CAAA;IAC9C,MAAM,IAAA,gCAAoB,EAAC,YAAY,EAAE,WAAW,EAAE;QACpD,MAAM,EAAE,CAAC;KACV,CAAC,CAAA;IACF,OAAO,YAAY,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC;;EAEtD,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAA;AACxC,CAAC;AA3BD,0BA2BC"}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export interface Person {
2
+ name?: string;
3
+ email?: string;
4
+ url?: string;
5
+ web?: string;
6
+ mail?: string;
7
+ }
8
+ export declare function personToString(person: Person): string;
9
+ export declare function workWithInitModule(localConfig: Record<string, string>): {
10
+ [x: string]: string;
11
+ };
12
+ export declare function workWithInitConfig(localConfig: Record<string, string>): Record<string, string>;
13
+ export declare function parseRawConfig(rawConfig: Record<string, string>): Promise<Record<string, string>>;
package/lib/utils.js ADDED
@@ -0,0 +1,60 @@
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.parseRawConfig = exports.workWithInitConfig = exports.workWithInitModule = exports.personToString = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const child_process_1 = require("child_process");
9
+ const camelcase_keys_1 = __importDefault(require("camelcase-keys"));
10
+ const fs_1 = __importDefault(require("fs"));
11
+ function personToString(person) {
12
+ const name = person.name ?? '';
13
+ const u = person.url ?? person.web;
14
+ const url = u ? ` (${u})` : '';
15
+ const e = person.email ?? person.mail;
16
+ const email = e ? ` <${e}>` : '';
17
+ return name + email + url;
18
+ }
19
+ exports.personToString = personToString;
20
+ function workWithInitModule(localConfig) {
21
+ const { initModule, ...restConfig } = localConfig;
22
+ if (initModule) {
23
+ const filePath = path_1.default.resolve(localConfig.initModule);
24
+ const isFileExist = fs_1.default.existsSync(filePath);
25
+ if (['.js', '.cjs'].includes(path_1.default.extname(filePath)) && isFileExist) {
26
+ (0, child_process_1.spawnSync)('node', [filePath], {
27
+ stdio: 'inherit',
28
+ });
29
+ }
30
+ }
31
+ return restConfig;
32
+ }
33
+ exports.workWithInitModule = workWithInitModule;
34
+ function workWithInitConfig(localConfig) {
35
+ const packageJson = {};
36
+ const authorInfo = {};
37
+ for (const localConfigKey in localConfig) {
38
+ if (localConfigKey.startsWith('init')) {
39
+ const pureKey = localConfigKey.replace('init', '');
40
+ const value = localConfig[localConfigKey];
41
+ if (pureKey.startsWith('Author')) {
42
+ authorInfo[pureKey.replace('Author', '')] = value;
43
+ }
44
+ else {
45
+ packageJson[pureKey] = value;
46
+ }
47
+ }
48
+ }
49
+ const author = personToString((0, camelcase_keys_1.default)(authorInfo));
50
+ if (author) {
51
+ packageJson.author = author;
52
+ }
53
+ return (0, camelcase_keys_1.default)(packageJson);
54
+ }
55
+ exports.workWithInitConfig = workWithInitConfig;
56
+ async function parseRawConfig(rawConfig) {
57
+ return workWithInitConfig(workWithInitModule((0, camelcase_keys_1.default)(rawConfig)));
58
+ }
59
+ exports.parseRawConfig = parseRawConfig;
60
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,iDAAyC;AACzC,oEAA0C;AAC1C,4CAAmB;AAUnB,SAAgB,cAAc,CAAE,MAAc;IAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,EAAE,CAAA;IAC9B,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,CAAA;IAClC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EA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CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,CAAA;aAClD;iBAAM;gBACL,WAAW,CAAC,OAAO,CAAC,GAAG,KAAK,CAAA;aAC7B;SACF;KACF;IAED,MAAM,MAAM,GAAG,cAAc,CAAC,IAAA,wBAAa,EAAC,UAAU,CAAC,CAAC,CAAA;IACxD,IAAI,MAAM,EAAE;QACV,WAAW,CAAC,MAAM,GAAG,MAAM,CAAA;KAC5B;IACD,OAAO,IAAA,wBAAa,EAAC,WAAW,CAAC,CAAA;AACnC,CAAC;AApBD,gDAoBC;AAEM,KAAK,UAAU,cAAc,CAAE,SAAiC;IACrE,OAAO,kBAAkB,CACvB,kBAAkB,CAAC,IAAA,wBAAa,EAAC,SAAS,CAAC,CAAC,CAC7C,CAAA;AACH,CAAC;AAJD,wCAIC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@pnpm/plugin-commands-init",
3
+ "version": "0.0.0",
4
+ "description": "Create a package.json file",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "!*.map"
10
+ ],
11
+ "engines": {
12
+ "node": ">=14.19"
13
+ },
14
+ "repository": "https://github.com/pnpm/pnpm/blob/main/packages/plugin-commands-init",
15
+ "keywords": [
16
+ "pnpm7",
17
+ "pnpm",
18
+ "init"
19
+ ],
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/pnpm/pnpm/issues"
23
+ },
24
+ "homepage": "https://github.com/pnpm/pnpm/blob/main/packages/plugin-commands-init#readme",
25
+ "devDependencies": {
26
+ "@pnpm/plugin-commands-init": "0.0.0",
27
+ "@pnpm/prepare": "0.0.36",
28
+ "@pnpm/test-fixtures": "0.0.5",
29
+ "load-json-file": "^6.2.0"
30
+ },
31
+ "dependencies": {
32
+ "@pnpm/cli-utils": "0.6.50",
33
+ "@pnpm/config": "13.13.2",
34
+ "@pnpm/error": "2.1.0",
35
+ "@pnpm/write-project-manifest": "2.0.11",
36
+ "camelcase-keys": "^6.2.2",
37
+ "render-help": "^1.0.1"
38
+ },
39
+ "funding": "https://opencollective.com/pnpm",
40
+ "exports": {
41
+ ".": "./lib/index.js"
42
+ },
43
+ "scripts": {
44
+ "lint": "eslint src/**/*.ts test/**/*.ts",
45
+ "_test": "jest",
46
+ "test": "pnpm run compile && pnpm run _test",
47
+ "compile": "tsc --build && pnpm run lint --fix",
48
+ "update-responses": "ts-node test/utils/responses/update.ts"
49
+ }
50
+ }