@vltpkg/init 0.0.0-10
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 +15 -0
- package/README.md +21 -0
- package/dist/esm/get-author-from-git-user.d.ts +3 -0
- package/dist/esm/get-author-from-git-user.d.ts.map +1 -0
- package/dist/esm/get-author-from-git-user.js +15 -0
- package/dist/esm/get-author-from-git-user.js.map +1 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +40 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Copyright (c) vlt technology, Inc.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
7
|
+
Subject to the terms and conditions of this license, each copyright holder and contributor hereby grants to those receiving rights under this license a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except for failure to satisfy the conditions of this license) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer this software, where such license applies only to those patent claims, already acquired or hereafter acquired, licensable by such copyright holder or contributor that are necessarily infringed by:
|
|
8
|
+
|
|
9
|
+
(a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable additions of contributors, in source or binary form) alone; or
|
|
10
|
+
(b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) was added by such copyright holder or contributor, if, at the time the Contribution is added, such addition causes such combination to be necessarily infringed. The patent license shall not apply to any other combinations which include the Contribution.
|
|
11
|
+
Except as expressly stated above, no rights or licenses from any copyright holder or contributor is granted under this license, whether expressly, by implication, estoppel or otherwise.
|
|
12
|
+
|
|
13
|
+
DISCLAIMER
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @vltpkg/init
|
|
2
|
+
|
|
3
|
+
Project initialization logic for `vlt`.
|
|
4
|
+
|
|
5
|
+
**[Usage](#usage)**
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This is a tool that provides the project initialization logic used by
|
|
10
|
+
the vlt cli and gui.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
import { init } from '@vltpkg/init'
|
|
16
|
+
|
|
17
|
+
// initalize a project
|
|
18
|
+
const results = await init({ cwd: '/some/path' })
|
|
19
|
+
|
|
20
|
+
// now results contains { manifest: { path, data }}
|
|
21
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-author-from-git-user.d.ts","sourceRoot":"","sources":["../../src/get-author-from-git-user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,eAAO,MAAM,oBAAoB,UAAW,OAAO,KAAG,MAUrD,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const getAuthorFromGitUser = (user) => {
|
|
2
|
+
if (!user)
|
|
3
|
+
return '';
|
|
4
|
+
const { name, email } = user;
|
|
5
|
+
let res = '';
|
|
6
|
+
if (name)
|
|
7
|
+
res += name;
|
|
8
|
+
if (email) {
|
|
9
|
+
if (name)
|
|
10
|
+
res += ' ';
|
|
11
|
+
res += `<${email}>`;
|
|
12
|
+
}
|
|
13
|
+
return res;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=get-author-from-git-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-author-from-git-user.js","sourceRoot":"","sources":["../../src/get-author-from-git-user.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAc,EAAU,EAAE;IAC7D,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IACpB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAA;IAC5B,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,IAAI,IAAI;QAAE,GAAG,IAAI,IAAI,CAAA;IACrB,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,IAAI;YAAE,GAAG,IAAI,GAAG,CAAA;QACpB,GAAG,IAAI,IAAI,KAAK,GAAG,CAAA;IACrB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import type { GitUser } from '@vltpkg/git'\n\nexport const getAuthorFromGitUser = (user?: GitUser): string => {\n if (!user) return ''\n const { name, email } = user\n let res = ''\n if (name) res += name\n if (email) {\n if (name) res += ' '\n res += `<${email}>`\n }\n return res\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { JSONObj } from '@vltpkg/registry-client';
|
|
2
|
+
import type { Manifest } from '@vltpkg/types';
|
|
3
|
+
import { getAuthorFromGitUser } from './get-author-from-git-user.ts';
|
|
4
|
+
export { getAuthorFromGitUser };
|
|
5
|
+
export type InitOptions = {
|
|
6
|
+
cwd?: string;
|
|
7
|
+
author?: string;
|
|
8
|
+
logger?: (...a: unknown[]) => void;
|
|
9
|
+
};
|
|
10
|
+
export type CustomizableInitOptions = {
|
|
11
|
+
name: string;
|
|
12
|
+
author: string;
|
|
13
|
+
};
|
|
14
|
+
export type JSONFileInfo<T extends JSONObj = JSONObj> = {
|
|
15
|
+
path: string;
|
|
16
|
+
data: T;
|
|
17
|
+
};
|
|
18
|
+
export type InitFileResults = {
|
|
19
|
+
manifest?: JSONFileInfo<Manifest>;
|
|
20
|
+
};
|
|
21
|
+
export declare const init: ({ cwd, author, logger, }?: InitOptions) => Promise<InitFileResults>;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AAEpE,OAAO,EAAE,oBAAoB,EAAE,CAAA;AAK/B,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;CACnC,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAaD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI;IACtD,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,CAAC,CAAA;CACR,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAA;CAKlC,CAAA;AAED,eAAO,MAAM,IAAI,8BAId,WAAW,KAAQ,OAAO,CAAC,eAAe,CAwB5C,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getUser } from '@vltpkg/git';
|
|
2
|
+
import { PackageJson } from '@vltpkg/package-json';
|
|
3
|
+
import { basename, resolve } from 'node:path';
|
|
4
|
+
import { getAuthorFromGitUser } from "./get-author-from-git-user.js";
|
|
5
|
+
import { asError } from '@vltpkg/error-cause';
|
|
6
|
+
export { getAuthorFromGitUser };
|
|
7
|
+
// eslint-disable-next-line no-console
|
|
8
|
+
const stderr = console.error;
|
|
9
|
+
const template = ({ name, author, }) => ({
|
|
10
|
+
name,
|
|
11
|
+
version: '1.0.0',
|
|
12
|
+
description: '',
|
|
13
|
+
main: 'index.js',
|
|
14
|
+
...(author ? { author } : undefined),
|
|
15
|
+
});
|
|
16
|
+
export const init = async ({ cwd = process.cwd(), author, logger = stderr, } = {}) => {
|
|
17
|
+
const packageJson = new PackageJson();
|
|
18
|
+
const path = resolve(cwd, 'package.json');
|
|
19
|
+
try {
|
|
20
|
+
packageJson.read(cwd);
|
|
21
|
+
// will only return here in case the package.json file does not exist
|
|
22
|
+
logger('package.json already exists');
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
if (asError(err).message !== 'Could not read package.json file') {
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
const name = basename(cwd);
|
|
30
|
+
const data = template({
|
|
31
|
+
name,
|
|
32
|
+
author: author ??
|
|
33
|
+
getAuthorFromGitUser(await getUser().catch(() => undefined)),
|
|
34
|
+
});
|
|
35
|
+
const indent = 2;
|
|
36
|
+
packageJson.write(cwd, data, indent);
|
|
37
|
+
return { manifest: { path, data } };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAGlD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,CAAA;AAE/B,sCAAsC;AACtC,MAAM,MAAM,GAA8B,OAAO,CAAC,KAAK,CAAA;AAavD,MAAM,QAAQ,GAAG,CAAC,EAChB,IAAI,EACJ,MAAM,GACkB,EAAY,EAAE,CAAC,CAAC;IACxC,IAAI;IACJ,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,EAAE;IACf,IAAI,EAAE,UAAU;IAChB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;CACrC,CAAC,CAAA;AAeF,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAE,EACzB,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EACnB,MAAM,EACN,MAAM,GAAG,MAAM,MACA,EAAE,EAA4B,EAAE;IAC/C,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAA;IACrC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;IACzC,IAAI,CAAC;QACH,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACrB,qEAAqE;QACrE,MAAM,CAAC,6BAA6B,CAAC,CAAA;QACrC,OAAO,EAAE,CAAA;IACX,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,KAAK,kCAAkC,EAAE,CAAC;YAChE,MAAM,GAAG,CAAA;QACX,CAAC;QAED,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;QAC1B,MAAM,IAAI,GAAG,QAAQ,CAAC;YACpB,IAAI;YACJ,MAAM,EACJ,MAAM;gBACN,oBAAoB,CAAC,MAAM,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;SAC/D,CAAC,CAAA;QACF,MAAM,MAAM,GAAG,CAAC,CAAA;QAChB,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;QACpC,OAAO,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAA;IACrC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { getUser } from '@vltpkg/git'\nimport { PackageJson } from '@vltpkg/package-json'\nimport type { JSONObj } from '@vltpkg/registry-client'\nimport type { Manifest } from '@vltpkg/types'\nimport { basename, resolve } from 'node:path'\nimport { getAuthorFromGitUser } from './get-author-from-git-user.ts'\nimport { asError } from '@vltpkg/error-cause'\nexport { getAuthorFromGitUser }\n\n// eslint-disable-next-line no-console\nconst stderr: (...a: unknown[]) => void = console.error\n\nexport type InitOptions = {\n cwd?: string\n author?: string\n logger?: (...a: unknown[]) => void\n}\n\nexport type CustomizableInitOptions = {\n name: string\n author: string\n}\n\nconst template = ({\n name,\n author,\n}: CustomizableInitOptions): Manifest => ({\n name,\n version: '1.0.0',\n description: '',\n main: 'index.js',\n ...(author ? { author } : undefined),\n})\n\nexport type JSONFileInfo<T extends JSONObj = JSONObj> = {\n path: string\n data: T\n}\n\nexport type InitFileResults = {\n manifest?: JSONFileInfo<Manifest>\n // TODO: enable these if/when we do more than just the manifest\n // Eg:\n // workspaces?: JSONFileInfo\n // config?: JSONFileInfo\n}\n\nexport const init = async ({\n cwd = process.cwd(),\n author,\n logger = stderr,\n}: InitOptions = {}): Promise<InitFileResults> => {\n const packageJson = new PackageJson()\n const path = resolve(cwd, 'package.json')\n try {\n packageJson.read(cwd)\n // will only return here in case the package.json file does not exist\n logger('package.json already exists')\n return {}\n } catch (err) {\n if (asError(err).message !== 'Could not read package.json file') {\n throw err\n }\n\n const name = basename(cwd)\n const data = template({\n name,\n author:\n author ??\n getAuthorFromGitUser(await getUser().catch(() => undefined)),\n })\n const indent = 2\n packageJson.write(cwd, data, indent)\n return { manifest: { path, data } }\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vltpkg/init",
|
|
3
|
+
"description": "vlt project intialization logic",
|
|
4
|
+
"version": "0.0.0-10",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
8
|
+
"directory": "src/init"
|
|
9
|
+
},
|
|
10
|
+
"tshy": {
|
|
11
|
+
"selfLink": false,
|
|
12
|
+
"liveDev": true,
|
|
13
|
+
"dialects": [
|
|
14
|
+
"esm"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
".": "./src/index.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@vltpkg/error-cause": "0.0.0-10",
|
|
23
|
+
"@vltpkg/package-json": "0.0.0-10",
|
|
24
|
+
"@vltpkg/git": "0.0.0-10",
|
|
25
|
+
"@vltpkg/registry-client": "0.0.0-10",
|
|
26
|
+
"@vltpkg/types": "0.0.0-10"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@eslint/js": "^9.25.0",
|
|
30
|
+
"@types/node": "^22.14.1",
|
|
31
|
+
"eslint": "^9.25.0",
|
|
32
|
+
"prettier": "^3.5.3",
|
|
33
|
+
"tap": "^21.1.0",
|
|
34
|
+
"tshy": "^3.0.2",
|
|
35
|
+
"typedoc": "~0.27.6",
|
|
36
|
+
"typescript": "5.7.3",
|
|
37
|
+
"typescript-eslint": "^8.30.1"
|
|
38
|
+
},
|
|
39
|
+
"license": "BSD-2-Clause-Patent",
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=22"
|
|
42
|
+
},
|
|
43
|
+
"tap": {
|
|
44
|
+
"extends": "../../tap-config.yaml"
|
|
45
|
+
},
|
|
46
|
+
"prettier": "../../.prettierrc.js",
|
|
47
|
+
"module": "./dist/esm/index.js",
|
|
48
|
+
"type": "module",
|
|
49
|
+
"exports": {
|
|
50
|
+
"./package.json": "./package.json",
|
|
51
|
+
".": {
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./dist/esm/index.d.ts",
|
|
54
|
+
"default": "./dist/esm/index.js"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"files": [
|
|
59
|
+
"dist"
|
|
60
|
+
],
|
|
61
|
+
"scripts": {
|
|
62
|
+
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
63
|
+
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
64
|
+
"lint": "eslint . --fix",
|
|
65
|
+
"lint:check": "eslint .",
|
|
66
|
+
"snap": "tap",
|
|
67
|
+
"test": "tap",
|
|
68
|
+
"posttest": "tsc --noEmit",
|
|
69
|
+
"typecheck": "tsc --noEmit"
|
|
70
|
+
}
|
|
71
|
+
}
|