jiek 0.4.6 → 0.4.7-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -1
- package/bin/jiek.js +2 -1
- package/dist/cli.d.mts +97 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.d.ts +96 -1
- package/dist/cli.d.ts.map +1 -0
- package/dist/{cli.cjs → cli.js} +355 -231
- package/dist/cli.js.map +1 -0
- package/dist/cli.min.js +1 -0
- package/dist/cli.min.js.map +1 -0
- package/dist/cli.min.mjs +1 -0
- package/dist/cli.min.mjs.map +1 -0
- package/dist/cli.mjs +803 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.d.mts +58 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +47 -46
- package/dist/index.d.ts.map +1 -0
- package/dist/{index.cjs → index.js} +0 -1
- package/dist/index.js.map +1 -0
- package/dist/{index.min.cjs → index.min.js} +0 -1
- package/dist/index.min.js.map +1 -0
- package/dist/index.min.mjs +1 -0
- package/dist/index.min.mjs.map +1 -0
- package/dist/{index.esm.js → index.mjs} +0 -1
- package/dist/index.mjs.map +1 -0
- package/dist/rollup/index.d.mts +53 -0
- package/dist/rollup/index.d.mts.map +1 -0
- package/dist/rollup/index.d.ts +53 -0
- package/dist/rollup/index.d.ts.map +1 -0
- package/dist/rollup/index.js +553 -0
- package/dist/rollup/index.js.map +1 -0
- package/dist/rollup/index.min.js +1 -0
- package/dist/rollup/index.min.js.map +1 -0
- package/dist/rollup/index.min.mjs +1 -0
- package/dist/rollup/index.min.mjs.map +1 -0
- package/dist/rollup/index.mjs +551 -0
- package/dist/rollup/index.mjs.map +1 -0
- package/package.json +52 -35
- package/src/cli.ts +9 -0
- package/src/commands/base.ts +9 -0
- package/src/commands/build.ts +156 -0
- package/src/commands/init.ts +373 -0
- package/src/commands/publish.ts +156 -0
- package/src/index.ts +8 -0
- package/src/inner.ts +11 -0
- package/src/merge-package-json.ts +75 -0
- package/src/pkg.ts +1 -0
- package/src/rollup/base.ts +72 -0
- package/src/rollup/index.ts +420 -0
- package/src/rollup/plugins/globals.ts +34 -0
- package/src/rollup/plugins/progress.ts +26 -0
- package/src/rollup/plugins/skip.ts +23 -0
- package/src/rollup/utils/commonOptions.ts +9 -0
- package/src/rollup/utils/externalResolver.ts +21 -0
- package/src/rollup/utils/globalResolver.ts +13 -0
- package/src/rollup/utils/withMinify.ts +18 -0
- package/src/utils/filterSupport.ts +82 -0
- package/src/utils/getExports.ts +100 -0
- package/src/utils/getRoot.ts +16 -0
- package/src/utils/getWD.ts +31 -0
- package/src/utils/loadConfig.ts +93 -0
- package/src/utils/tsRegister.ts +22 -0
- package/dist/base.esm.d.ts +0 -55
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.esm.d.ts +0 -2
- package/dist/cli.esm.js +0 -9
- package/dist/cli.esm.js.map +0 -1
- package/dist/cli.esm.min.js +0 -2
- package/dist/cli.esm.min.js.map +0 -1
- package/dist/cli.min.cjs +0 -2
- package/dist/cli.min.cjs.map +0 -1
- package/dist/commands/base.esm.js +0 -5
- package/dist/commands/base.esm.js.map +0 -1
- package/dist/commands/base.esm.min.js +0 -2
- package/dist/commands/base.esm.min.js.map +0 -1
- package/dist/commands/build.esm.js +0 -58
- package/dist/commands/build.esm.js.map +0 -1
- package/dist/commands/build.esm.min.js +0 -2
- package/dist/commands/build.esm.min.js.map +0 -1
- package/dist/commands/init.esm.js +0 -271
- package/dist/commands/init.esm.js.map +0 -1
- package/dist/commands/init.esm.min.js +0 -2
- package/dist/commands/init.esm.min.js.map +0 -1
- package/dist/commands/publish.esm.js +0 -87
- package/dist/commands/publish.esm.js.map +0 -1
- package/dist/commands/publish.esm.min.js +0 -2
- package/dist/commands/publish.esm.min.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.esm.d.ts +0 -6
- package/dist/index.esm.js.map +0 -1
- package/dist/index.esm.min.js +0 -2
- package/dist/index.esm.min.js.map +0 -1
- package/dist/index.min.cjs.map +0 -1
- package/dist/inner.esm.js +0 -10
- package/dist/inner.esm.js.map +0 -1
- package/dist/inner.esm.min.js +0 -2
- package/dist/inner.esm.min.js.map +0 -1
- package/dist/merge-package-json.esm.js +0 -64
- package/dist/merge-package-json.esm.js.map +0 -1
- package/dist/merge-package-json.esm.min.js +0 -2
- package/dist/merge-package-json.esm.min.js.map +0 -1
- package/dist/pkg.esm.js +0 -4
- package/dist/pkg.esm.js.map +0 -1
- package/dist/pkg.esm.min.js +0 -2
- package/dist/pkg.esm.min.js.map +0 -1
- package/dist/rollup/plugins/globals.esm.js +0 -31
- package/dist/rollup/plugins/globals.esm.js.map +0 -1
- package/dist/rollup/plugins/globals.esm.min.js +0 -2
- package/dist/rollup/plugins/globals.esm.min.js.map +0 -1
- package/dist/rollup/plugins/skip.esm.js +0 -16
- package/dist/rollup/plugins/skip.esm.js.map +0 -1
- package/dist/rollup/plugins/skip.esm.min.js +0 -2
- package/dist/rollup/plugins/skip.esm.min.js.map +0 -1
- package/dist/rollup/utils/commonOptions.esm.js +0 -9
- package/dist/rollup/utils/commonOptions.esm.js.map +0 -1
- package/dist/rollup/utils/commonOptions.esm.min.js +0 -2
- package/dist/rollup/utils/commonOptions.esm.min.js.map +0 -1
- package/dist/rollup/utils/externalResolver.esm.js +0 -12
- package/dist/rollup/utils/externalResolver.esm.js.map +0 -1
- package/dist/rollup/utils/externalResolver.esm.min.js +0 -2
- package/dist/rollup/utils/externalResolver.esm.min.js.map +0 -1
- package/dist/rollup/utils/globalResolver.esm.js +0 -9
- package/dist/rollup/utils/globalResolver.esm.js.map +0 -1
- package/dist/rollup/utils/globalResolver.esm.min.js +0 -2
- package/dist/rollup/utils/globalResolver.esm.min.js.map +0 -1
- package/dist/rollup/utils/withMinify.esm.js +0 -15
- package/dist/rollup/utils/withMinify.esm.js.map +0 -1
- package/dist/rollup/utils/withMinify.esm.min.js +0 -2
- package/dist/rollup/utils/withMinify.esm.min.js.map +0 -1
- package/dist/rollup.cjs +0 -330
- package/dist/rollup.cjs.map +0 -1
- package/dist/rollup.d.ts +0 -23
- package/dist/rollup.esm.d.ts +0 -23
- package/dist/rollup.esm.js +0 -248
- package/dist/rollup.esm.js.map +0 -1
- package/dist/rollup.esm.min.js +0 -2
- package/dist/rollup.esm.min.js.map +0 -1
- package/dist/rollup.min.cjs +0 -2
- package/dist/rollup.min.cjs.map +0 -1
- package/dist/utils/commondir.esm.js +0 -25
- package/dist/utils/commondir.esm.js.map +0 -1
- package/dist/utils/commondir.esm.min.js +0 -2
- package/dist/utils/commondir.esm.min.js.map +0 -1
- package/dist/utils/filterSupport.esm.js +0 -67
- package/dist/utils/filterSupport.esm.js.map +0 -1
- package/dist/utils/filterSupport.esm.min.js +0 -2
- package/dist/utils/filterSupport.esm.min.js.map +0 -1
- package/dist/utils/getRoot.esm.js +0 -14
- package/dist/utils/getRoot.esm.js.map +0 -1
- package/dist/utils/getRoot.esm.min.js +0 -2
- package/dist/utils/getRoot.esm.min.js.map +0 -1
- package/dist/utils/getWD.esm.js +0 -31
- package/dist/utils/getWD.esm.js.map +0 -1
- package/dist/utils/getWD.esm.min.js +0 -2
- package/dist/utils/getWD.esm.min.js.map +0 -1
- package/dist/utils/loadConfig.esm.js +0 -75
- package/dist/utils/loadConfig.esm.js.map +0 -1
- package/dist/utils/loadConfig.esm.min.js +0 -2
- package/dist/utils/loadConfig.esm.min.js.map +0 -1
- package/dist/utils/tsRegister.esm.js +0 -24
- package/dist/utils/tsRegister.esm.js.map +0 -1
- package/dist/utils/tsRegister.esm.min.js +0 -2
- package/dist/utils/tsRegister.esm.min.js.map +0 -1
@@ -1,58 +0,0 @@
|
|
1
|
-
import * as childProcess from 'node:child_process';
|
2
|
-
import fs from 'node:fs';
|
3
|
-
import path from 'node:path';
|
4
|
-
import { program } from 'commander';
|
5
|
-
import { actionRestore, actionDone } from '../inner.esm.js';
|
6
|
-
import { mergePackageJson } from '../merge-package-json.esm.js';
|
7
|
-
import { getSelectedProjectsGraph } from '../utils/filterSupport.esm.js';
|
8
|
-
import { tsRegisterName } from '../utils/tsRegister.esm.js';
|
9
|
-
|
10
|
-
const FILE_TEMPLATE = (manifest) => `
|
11
|
-
const pkg = ${JSON.stringify(manifest, null, 2)}
|
12
|
-
const { jiek = {} } = pkg
|
13
|
-
const templateArg = jiek.templateArgFilePath
|
14
|
-
? require.resolve(jiek.templateArgFilePath)
|
15
|
-
: {
|
16
|
-
styled: jiek.styled
|
17
|
-
}
|
18
|
-
module.exports = require('jiek/rollup').template(templateArg, pkg)
|
19
|
-
`.trimStart();
|
20
|
-
program.command("build").option("-t, --target <type>", "target flow: esm|umd|dts, default esm,umd,dts").option("-s, --silent", "silent mode").action(async ({ target, silent }) => {
|
21
|
-
actionRestore();
|
22
|
-
const {
|
23
|
-
wd,
|
24
|
-
value = {}
|
25
|
-
} = await getSelectedProjectsGraph() ?? {};
|
26
|
-
if (Object.keys(value).length === 0) {
|
27
|
-
throw new Error("no package found");
|
28
|
-
}
|
29
|
-
const jiekTempDir = (...paths) => path.resolve(wd, "node_modules/.jiek", ...paths);
|
30
|
-
if (!fs.existsSync(jiekTempDir()))
|
31
|
-
fs.mkdirSync(jiekTempDir());
|
32
|
-
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
33
|
-
let i = 0;
|
34
|
-
for (const [dir, manifest] of Object.entries(value)) {
|
35
|
-
const newManifest = mergePackageJson(manifest, dir, { excludeDistInExports: true });
|
36
|
-
const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
|
37
|
-
const configFile = jiekTempDir(
|
38
|
-
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
39
|
-
);
|
40
|
-
fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest));
|
41
|
-
let prefix = "";
|
42
|
-
if (tsRegisterName) {
|
43
|
-
prefix = `node -r ${tsRegisterName} `;
|
44
|
-
}
|
45
|
-
const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
|
46
|
-
childProcess.execSync(command, {
|
47
|
-
cwd: dir,
|
48
|
-
stdio: "inherit",
|
49
|
-
env: {
|
50
|
-
JIEK_TARGET: target ?? process.env.JIEK_TARGET ?? "esm,umd,dts",
|
51
|
-
JIEK_SILENT: `${silent}` ?? process.env.JIEK_SILENT,
|
52
|
-
JIEK_ROOT: wd
|
53
|
-
}
|
54
|
-
});
|
55
|
-
}
|
56
|
-
actionDone();
|
57
|
-
});
|
58
|
-
//# sourceMappingURL=build.esm.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"build.esm.js","sources":["../../src/commands/build.ts"],"sourcesContent":["import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\nimport { tsRegisterName } from '../utils/tsRegister'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .option('-t, --target <type>', 'target flow: esm|umd|dts, default esm,umd,dts')\n .option('-s, --silent', 'silent mode')\n .action(async ({ target, silent }) => {\n actionRestore()\n const {\n wd, value = {}\n } = await getSelectedProjectsGraph() ?? {}\n\n if (Object.keys(value).length === 0) {\n throw new Error('no package found')\n }\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, manifest] of Object.entries(value)) {\n const newManifest = mergePackageJson(manifest, dir, { excludeDistInExports: true })\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (tsRegisterName) {\n prefix = `node -r ${tsRegisterName} `\n }\n // TODO replace with `spawn` to support watch mode\n const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`\n childProcess.execSync(command, {\n cwd: dir, stdio: 'inherit',\n env: {\n JIEK_TARGET: target ?? process.env.JIEK_TARGET ?? 'esm,umd,dts',\n JIEK_SILENT: `${silent}` ?? process.env.JIEK_SILENT,\n JIEK_ROOT: wd\n }\n })\n }\n\n actionDone()\n })\n"],"names":[],"mappings":";;;;;;;;;AAWA,MAAM,aAAA,GAAgB,CAAC,QAAsB,KAAA,CAAA;AAAA,YAAA,EAC/B,IAAK,CAAA,SAAA,CAAU,QAAU,EAAA,IAAA,EAAM,CAAC,CAAC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA,CAQ7C,SAAU,EAAA,CAAA;AAEZ,OAAA,CACG,QAAQ,OAAO,CAAA,CACf,MAAO,CAAA,qBAAA,EAAuB,+CAA+C,CAC7E,CAAA,MAAA,CAAO,cAAgB,EAAA,aAAa,EACpC,MAAO,CAAA,OAAO,EAAE,MAAA,EAAQ,QAAa,KAAA;AACpC,EAAc,aAAA,EAAA,CAAA;AACd,EAAM,MAAA;AAAA,IACJ,EAAA;AAAA,IAAI,QAAQ,EAAC;AAAA,GACX,GAAA,MAAM,wBAAyB,EAAA,IAAK,EAAC,CAAA;AAEzC,EAAA,IAAI,MAAO,CAAA,IAAA,CAAK,KAAK,CAAA,CAAE,WAAW,CAAG,EAAA;AACnC,IAAM,MAAA,IAAI,MAAM,kBAAkB,CAAA,CAAA;AAAA,GACpC;AACA,EAAM,MAAA,WAAA,GAAc,IAAI,KAAoB,KAAA,IAAA,CAAK,QAA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A,SAAA;AAAA,MACjB,GAAK,EAAA;AAAA,QACH,WAAa,EAAA,MAAA,IAAU,OAAQ,CAAA,GAAA,CAAI,WAAe,IAAA,aAAA;AAAA,QAClD,WAAa,EAAA,CAAA,EAAG,MAAM,CAAA,CAAA,IAAM,QAAQ,GAAI,CAAA,WAAA;AAAA,QACxC,SAAW,EAAA,EAAA;AAAA,OACb;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AAEA,EAAW,UAAA,EAAA,CAAA;AACb,CAAC,CAAA"}
|
@@ -1,2 +0,0 @@
|
|
1
|
-
import*as e from"node:child_process";import t from"node:fs";import o from"node:path";import{program as r}from"commander";import{actionRestore as s,actionDone as n}from"../inner.esm.min.js";import{mergePackageJson as i}from"../merge-package-json.esm.min.js";import{getSelectedProjectsGraph as m}from"../utils/filterSupport.esm.min.js";import{tsRegisterName as l}from"../utils/tsRegister.esm.min.js";const p=e=>`\nconst pkg = ${JSON.stringify(e,null,2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart();r.command("build").option("-t, --target <type>","target flow: esm|umd|dts, default esm,umd,dts").option("-s, --silent","silent mode").action((async({target:r,silent:c})=>{s();const{wd:a,value:d={}}=await m()??{};if(0===Object.keys(d).length)throw new Error("no package found");const u=(...e)=>o.resolve(a,"node_modules/.jiek",...e);t.existsSync(u())||t.mkdirSync(u());const g=require.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup");let f=0;for(const[o,s]of Object.entries(d)){const n=i(s,o,{excludeDistInExports:!0}),m=s.name?.replace(/^@/g,"").replace(/\//g,"+"),d=u(`${m??"anonymous-"+f++}.rollup.config.js`);t.writeFileSync(d,p(n));let j="";l&&(j=`node -r ${l} `);const k=`${j}${g} --silent -c ${d}`;e.execSync(k,{cwd:o,stdio:"inherit",env:{JIEK_TARGET:r??process.env.JIEK_TARGET??"esm,umd,dts",JIEK_SILENT:`${c}`??process.env.JIEK_SILENT,JIEK_ROOT:a}})}n()}));
|
2
|
-
//# sourceMappingURL=build.esm.min.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"build.esm.min.js","sources":["../../src/commands/build.ts"],"sourcesContent":["import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\nimport { tsRegisterName } from '../utils/tsRegister'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .option('-t, --target <type>', 'target flow: esm|umd|dts, default esm,umd,dts')\n .option('-s, --silent', 'silent mode')\n .action(async ({ target, silent }) => {\n actionRestore()\n const {\n wd, value = {}\n } = await getSelectedProjectsGraph() ?? {}\n\n if (Object.keys(value).length === 0) {\n throw new Error('no package found')\n }\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, manifest] of Object.entries(value)) {\n const newManifest = mergePackageJson(manifest, dir, { excludeDistInExports: true })\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (tsRegisterName) {\n prefix = `node -r ${tsRegisterName} `\n }\n // TODO replace with `spawn` to support watch mode\n const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`\n childProcess.execSync(command, {\n cwd: dir, stdio: 'inherit',\n env: {\n JIEK_TARGET: target ?? process.env.JIEK_TARGET ?? 'esm,umd,dts',\n JIEK_SILENT: `${silent}` ?? process.env.JIEK_SILENT,\n JIEK_ROOT: wd\n }\n })\n }\n\n actionDone()\n })\n"],"names":["FILE_TEMPLATE","manifest","JSON","stringify","trimStart","program","command","option","action","async","target","silent","actionRestore","wd","value","getSelectedProjectsGraph","Object","keys","length","Error","jiekTempDir","paths","path","resolve","fs","existsSync","mkdirSync","rollupBinaryPath","require","replace","i","dir","entries","newManifest","mergePackageJson","excludeDistInExports","escapeManifestName","name","configFile","writeFileSync","prefix","tsRegisterName","childProcess","execSync","cwd","stdio","env","JIEK_TARGET","process","JIEK_SILENT","JIEK_ROOT","actionDone"],"mappings":"8YAWA,MAAMA,EAAiBC,GAAsB,iBAC/BC,KAAKC,UAAUF,EAAU,KAAM,wOAQ3CG,YAEFC,EACGC,QAAQ,SACRC,OAAO,sBAAuB,iDAC9BA,OAAO,eAAgB,eACvBC,QAAOC,OAASC,SAAQC,aACTC,IACR,MAAAC,GACJA,EAAAC,MAAIA,EAAQ,CAAC,SACLC,KAA8B,GAExC,GAAkC,IAA9BC,OAAOC,KAAKH,GAAOI,OACf,MAAA,IAAIC,MAAM,oBAEZ,MAAAC,EAAc,IAAIC,IAAoBC,EAAKC,QAAQV,EAAI,wBAAyBQ,GACjFG,EAAGC,WAAWL,MAAmBI,EAAAE,UAAUN,KAEhD,MAAMO,EAAmBC,QAAQL,QAAQ,UACtCM,QAAQ,mBAAoB,mBAC/B,IAAIC,EAAI,EACR,IAAA,MAAYC,EAAK9B,KAAae,OAAOgB,QAAQlB,GAAQ,CACnD,MAAMmB,EAAcC,EAAiBjC,EAAU8B,EAAK,CAAEI,sBAAsB,IAEtEC,EAAqBnC,EAASoC,MAAMR,QAAQ,MAAO,IAAIA,QAAQ,MAAO,KACtES,EAAalB,EACjB,GAAGgB,GAAsB,aAAaN,wBAExCN,EAAGe,cAAcD,EAAYtC,EAAciC,IAC3C,IAAIO,EAAS,GACTC,IACFD,EAAS,WAAWC,MAGtB,MAAMnC,EAAU,GAAGkC,IAASb,iBAAgCW,IAC5DI,EAAaC,SAASrC,EAAS,CAC7BsC,IAAKb,EAAKc,MAAO,UACjBC,IAAK,CACHC,YAAarC,GAAUsC,QAAQF,IAAIC,aAAe,cAClDE,YAAa,GAAGtC,KAAYqC,QAAQF,IAAIG,YACxCC,UAAWrC,IAGjB,CAEWsC,GAAA"}
|
@@ -1,271 +0,0 @@
|
|
1
|
-
import fs from 'node:fs';
|
2
|
-
import path from 'node:path';
|
3
|
-
import { program } from 'commander';
|
4
|
-
import detectIndent from 'detect-indent';
|
5
|
-
import inquirer from 'inquirer';
|
6
|
-
import { applyEdits, modify } from 'jsonc-parser';
|
7
|
-
import { isMatch } from 'micromatch';
|
8
|
-
import { getWD } from '../utils/getWD.esm.js';
|
9
|
-
import { loadConfig } from '../utils/loadConfig.esm.js';
|
10
|
-
|
11
|
-
const PACKAGE_JSON_TEMPLATE = `{
|
12
|
-
"name": "",
|
13
|
-
"version": "0.0.1",
|
14
|
-
"description": "",
|
15
|
-
"license": "",
|
16
|
-
"author": "",
|
17
|
-
"files": ["dist"],
|
18
|
-
"exports": {
|
19
|
-
".": "./src/index.ts"
|
20
|
-
},
|
21
|
-
"scripts": {
|
22
|
-
},
|
23
|
-
"homepage": "",
|
24
|
-
"repository": "",
|
25
|
-
"bugs": ""
|
26
|
-
}`.trimStart();
|
27
|
-
const README_TEMPLATE = `# $name
|
28
|
-
|
29
|
-
## Installation
|
30
|
-
|
31
|
-
\`\`\`bash
|
32
|
-
npm install $name
|
33
|
-
# or
|
34
|
-
pnpm install $name
|
35
|
-
# or
|
36
|
-
yarn add $name
|
37
|
-
\`\`\`
|
38
|
-
|
39
|
-
## Usage
|
40
|
-
|
41
|
-
|
42
|
-
## License
|
43
|
-
|
44
|
-
$license
|
45
|
-
`.trimStart();
|
46
|
-
function getTemplateStr(wd, template) {
|
47
|
-
let templateString = template ?? PACKAGE_JSON_TEMPLATE;
|
48
|
-
let isTemplateFile = false;
|
49
|
-
try {
|
50
|
-
if (template)
|
51
|
-
JSON.parse(template);
|
52
|
-
} catch (e) {
|
53
|
-
isTemplateFile = true;
|
54
|
-
}
|
55
|
-
if (isTemplateFile) {
|
56
|
-
const templatePath = path.resolve(wd, template);
|
57
|
-
templateString = fs.readFileSync(templatePath, "utf-8");
|
58
|
-
}
|
59
|
-
return templateString;
|
60
|
-
}
|
61
|
-
const wdCache = /* @__PURE__ */ new Map();
|
62
|
-
function getWDPackageJSONFiled(wd, field) {
|
63
|
-
if (wdCache.has(wd)) {
|
64
|
-
return wdCache.get(wd)[field];
|
65
|
-
}
|
66
|
-
const packageJSONPath = path.resolve(wd, "package.json");
|
67
|
-
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, "utf-8"));
|
68
|
-
wdCache.set(wd, packageJSON);
|
69
|
-
return packageJSON[field];
|
70
|
-
}
|
71
|
-
async function getName(named, name, {
|
72
|
-
wd,
|
73
|
-
cwd,
|
74
|
-
workspaceName
|
75
|
-
}) {
|
76
|
-
const relativePath = cwd.replace(`${wd}/`, "");
|
77
|
-
let basename = path.basename(cwd);
|
78
|
-
if (typeof named === "function") {
|
79
|
-
return named(name, {
|
80
|
-
full: wd,
|
81
|
-
relative: cwd
|
82
|
-
});
|
83
|
-
}
|
84
|
-
let isParentMatched = false;
|
85
|
-
let matchedKey;
|
86
|
-
let matchedRule;
|
87
|
-
if (typeof named === "object") {
|
88
|
-
const isWD = cwd === wd;
|
89
|
-
if (isWD) {
|
90
|
-
const { rule } = await inquirer.prompt({
|
91
|
-
type: "list",
|
92
|
-
name: "rule",
|
93
|
-
message: "choose a rule",
|
94
|
-
default: "default",
|
95
|
-
choices: ["default"].concat(Object.keys(named))
|
96
|
-
});
|
97
|
-
if (rule !== "default") {
|
98
|
-
matchedKey = rule;
|
99
|
-
matchedRule = named[rule];
|
100
|
-
}
|
101
|
-
} else
|
102
|
-
for (const [key, value] of Object.entries(named)) {
|
103
|
-
if (isMatch(relativePath, key)) {
|
104
|
-
matchedKey = key;
|
105
|
-
matchedRule = value;
|
106
|
-
break;
|
107
|
-
}
|
108
|
-
if (isMatch(`${relativePath}/jiek_ignore_dont_use_same_file_name`, key)) {
|
109
|
-
isParentMatched = true;
|
110
|
-
matchedKey = key;
|
111
|
-
matchedRule = value;
|
112
|
-
break;
|
113
|
-
}
|
114
|
-
}
|
115
|
-
}
|
116
|
-
if (!matchedRule) {
|
117
|
-
matchedKey = "packages/*";
|
118
|
-
matchedRule = `@${workspaceName}/$basename`;
|
119
|
-
}
|
120
|
-
if (!matchedRule)
|
121
|
-
throw new Error("no matched rule");
|
122
|
-
if (!name && isParentMatched) {
|
123
|
-
basename = await inquirer.prompt({
|
124
|
-
type: "input",
|
125
|
-
name: "name",
|
126
|
-
message: `the matched rule is \`${String(matchedRule)}\`, please input the basename
|
127
|
-
`
|
128
|
-
}).then(({ name: name2 }) => name2);
|
129
|
-
}
|
130
|
-
if (typeof matchedRule === "function") {
|
131
|
-
return matchedRule(name, {
|
132
|
-
full: wd,
|
133
|
-
relative: cwd,
|
134
|
-
basename
|
135
|
-
});
|
136
|
-
}
|
137
|
-
if (typeof matchedRule === "string") {
|
138
|
-
const dirName = name ?? basename;
|
139
|
-
return [
|
140
|
-
matchedRule.replace(/\$basename/g, dirName),
|
141
|
-
matchedKey?.replace(/\/\*$/g, `/${dirName}`)
|
142
|
-
];
|
143
|
-
}
|
144
|
-
throw new Error("no matched rule");
|
145
|
-
}
|
146
|
-
program.command("init [name]").option("-t, --template <template>", "the package.json template file path or file content").action(async () => {
|
147
|
-
const [, name] = program.args;
|
148
|
-
const cwd = process.cwd();
|
149
|
-
const { init = {} } = loadConfig() ?? {};
|
150
|
-
const { wd } = getWD();
|
151
|
-
const workspaceName = path.basename(wd);
|
152
|
-
const {
|
153
|
-
named,
|
154
|
-
template,
|
155
|
-
bug = {},
|
156
|
-
readme: _readme = README_TEMPLATE,
|
157
|
-
readmeTemplate
|
158
|
-
} = init;
|
159
|
-
const resolvedBug = {
|
160
|
-
template: "bug_report.yml",
|
161
|
-
labels: ["bug"],
|
162
|
-
...bug
|
163
|
-
};
|
164
|
-
let readme = _readme;
|
165
|
-
if (readmeTemplate) {
|
166
|
-
const readmeTemplatePath = path.resolve(wd, readmeTemplate);
|
167
|
-
readme = fs.readFileSync(readmeTemplatePath, "utf-8");
|
168
|
-
}
|
169
|
-
const templateString = getTemplateStr(wd, template);
|
170
|
-
const { indent = " " } = detectIndent(templateString);
|
171
|
-
const formattingOptions = {
|
172
|
-
tabSize: indent.length,
|
173
|
-
insertSpaces: true
|
174
|
-
};
|
175
|
-
const passFields = [
|
176
|
-
"license",
|
177
|
-
"author"
|
178
|
-
];
|
179
|
-
let newJSONString = templateString;
|
180
|
-
for (const field of passFields) {
|
181
|
-
newJSONString = applyEdits(newJSONString, modify(
|
182
|
-
newJSONString,
|
183
|
-
[field],
|
184
|
-
getWDPackageJSONFiled(wd, field),
|
185
|
-
{ formattingOptions }
|
186
|
-
));
|
187
|
-
}
|
188
|
-
let [pkgName, pkgDir] = await getName(named, name, {
|
189
|
-
wd,
|
190
|
-
cwd,
|
191
|
-
workspaceName
|
192
|
-
});
|
193
|
-
if (!pkgDir) {
|
194
|
-
const { dir } = await inquirer.prompt({
|
195
|
-
type: "input",
|
196
|
-
name: "dir",
|
197
|
-
message: "package directory",
|
198
|
-
default: name
|
199
|
-
});
|
200
|
-
pkgDir = dir;
|
201
|
-
}
|
202
|
-
if (!pkgName) {
|
203
|
-
const { name: inputName } = await inquirer.prompt({
|
204
|
-
type: "input",
|
205
|
-
name: "name",
|
206
|
-
message: "package name",
|
207
|
-
default: name
|
208
|
-
});
|
209
|
-
pkgName = inputName;
|
210
|
-
}
|
211
|
-
newJSONString = applyEdits(newJSONString, modify(newJSONString, ["name"], pkgName, { formattingOptions }));
|
212
|
-
let pkgRepo = getWDPackageJSONFiled(wd, "repository");
|
213
|
-
if (typeof pkgRepo === "string") {
|
214
|
-
pkgRepo = {
|
215
|
-
type: "git",
|
216
|
-
url: pkgRepo,
|
217
|
-
directory: pkgDir
|
218
|
-
};
|
219
|
-
}
|
220
|
-
newJSONString = applyEdits(newJSONString, modify(
|
221
|
-
newJSONString,
|
222
|
-
["repository"],
|
223
|
-
pkgRepo,
|
224
|
-
{ formattingOptions }
|
225
|
-
));
|
226
|
-
const homepage = `${pkgRepo?.url}/blob/master/${pkgDir}/README.md`;
|
227
|
-
newJSONString = applyEdits(newJSONString, modify(
|
228
|
-
newJSONString,
|
229
|
-
["homepage"],
|
230
|
-
homepage,
|
231
|
-
{ formattingOptions }
|
232
|
-
));
|
233
|
-
let labels = resolvedBug.labels;
|
234
|
-
if (typeof labels === "function")
|
235
|
-
labels = labels({
|
236
|
-
name: pkgName,
|
237
|
-
dir: pkgDir
|
238
|
-
});
|
239
|
-
labels.push(`scope:${pkgName}`);
|
240
|
-
const bugs = `${pkgRepo?.url}/issues/new?template=${resolvedBug.template}&labels=${labels.join(",")}`;
|
241
|
-
newJSONString = applyEdits(newJSONString, modify(
|
242
|
-
newJSONString,
|
243
|
-
["bugs"],
|
244
|
-
bugs,
|
245
|
-
{ formattingOptions }
|
246
|
-
));
|
247
|
-
function pkgDirTo(to) {
|
248
|
-
if (!pkgDir)
|
249
|
-
throw new Error("pkgDir is not defined");
|
250
|
-
return path.resolve(pkgDir, to);
|
251
|
-
}
|
252
|
-
if (!fs.existsSync(pkgDir))
|
253
|
-
fs.mkdirSync(pkgDir);
|
254
|
-
const pkgJSONFilePath = pkgDirTo("package.json");
|
255
|
-
if (fs.existsSync(pkgJSONFilePath)) {
|
256
|
-
throw new Error("package.json already exists");
|
257
|
-
}
|
258
|
-
fs.writeFileSync(pkgJSONFilePath, newJSONString);
|
259
|
-
console.log(newJSONString, "written to", pkgJSONFilePath);
|
260
|
-
const license = getWDPackageJSONFiled(wd, "license");
|
261
|
-
const readmeFilePath = pkgDirTo("README.md");
|
262
|
-
if (typeof readme === "function") {
|
263
|
-
readme = readme({
|
264
|
-
dir: pkgDir,
|
265
|
-
packageJson: JSON.parse(newJSONString)
|
266
|
-
});
|
267
|
-
}
|
268
|
-
const readmeContent = readme.replace(/\$name/g, pkgName).replace(/\$license/g, license);
|
269
|
-
fs.writeFileSync(readmeFilePath, readmeContent);
|
270
|
-
});
|
271
|
-
//# sourceMappingURL=init.esm.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"init.esm.js","sources":["../../src/commands/init.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\nimport detectIndent from 'detect-indent'\nimport inquirer from 'inquirer'\nimport { applyEdits, modify } from 'jsonc-parser'\nimport { isMatch } from 'micromatch'\n\nimport type { Config, InitNamed } from '../base'\nimport { getWD } from '../utils/getWD'\nimport { loadConfig } from '../utils/loadConfig'\n\nconst PACKAGE_JSON_TEMPLATE = `{\n \"name\": \"\",\n \"version\": \"0.0.1\",\n \"description\": \"\",\n \"license\": \"\",\n \"author\": \"\",\n \"files\": [\"dist\"],\n \"exports\": {\n \".\": \"./src/index.ts\"\n },\n \"scripts\": {\n },\n \"homepage\": \"\",\n \"repository\": \"\",\n \"bugs\": \"\"\n}`.trimStart()\nconst README_TEMPLATE = `# $name\n\n## Installation\n\n\\`\\`\\`bash\nnpm install $name\n# or\npnpm install $name\n# or\nyarn add $name\n\\`\\`\\`\n\n## Usage\n\n\n## License\n\n$license\n`.trimStart()\n\nfunction getTemplateStr(wd: string, template: string | undefined) {\n let templateString = template ?? PACKAGE_JSON_TEMPLATE\n let isTemplateFile = false\n try {\n if (template) JSON.parse(template)\n } catch (e) {\n isTemplateFile = true\n }\n if (isTemplateFile) {\n const templatePath = path.resolve(wd, template!)\n templateString = fs.readFileSync(templatePath, 'utf-8')\n }\n return templateString\n}\nconst wdCache = new Map<string, Record<string, any>>()\nfunction getWDPackageJSONFiled(wd: string, field: string) {\n if (wdCache.has(wd)) {\n return wdCache.get(wd)![field]\n }\n const packageJSONPath = path.resolve(wd, 'package.json')\n const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8'))\n wdCache.set(wd, packageJSON)\n return packageJSON[field]\n}\nasync function getName(\n named: InitNamed | undefined,\n name: string,\n {\n wd, cwd,\n workspaceName\n }: {\n wd: string\n cwd: string\n workspaceName: string\n }\n): Promise<[name?: string, path?: string]> {\n const relativePath = cwd.replace(`${wd}/`, '')\n let basename = path.basename(cwd)\n\n if (typeof named === 'function') {\n return named(name, {\n full: wd,\n relative: cwd\n })\n }\n\n let isParentMatched = false\n let matchedKey: string | undefined\n let matchedRule: NonNullable<typeof named>[string] | undefined\n if (typeof named === 'object') {\n const isWD = cwd === wd\n if (isWD) {\n const { rule } = await inquirer.prompt<{ rule: string }>({\n type: 'list',\n name: 'rule',\n message: 'choose a rule',\n default: 'default',\n choices: ['default'].concat(Object.keys(named))\n })\n if (rule !== 'default') {\n matchedKey = rule\n matchedRule = named[rule]\n }\n } else for (const [key, value] of Object.entries(named)) {\n if (isMatch(relativePath, key)) {\n matchedKey = key\n matchedRule = value\n break\n }\n if (isMatch(`${relativePath}/jiek_ignore_dont_use_same_file_name`, key)) {\n isParentMatched = true\n matchedKey = key\n matchedRule = value\n break\n }\n }\n }\n if (!matchedRule) {\n matchedKey = 'packages/*'\n matchedRule = `@${workspaceName}/$basename`\n }\n if (!matchedRule)\n throw new Error('no matched rule')\n if (!name && isParentMatched) {\n basename = await inquirer.prompt<{ name: string }>({\n type: 'input',\n name: 'name',\n message: `the matched rule is \\`${String(matchedRule)}\\`, please input the basename\\n`\n }).then(({ name }) => name)\n }\n\n if (typeof matchedRule === 'function') {\n return matchedRule(name, {\n full: wd,\n relative: cwd,\n basename: basename\n })\n }\n if (typeof matchedRule === 'string') {\n const dirName = name ?? basename\n return [\n matchedRule.replace(/\\$basename/g, dirName),\n matchedKey?.replace(/\\/\\*$/g, `/${dirName}`)\n ]\n }\n throw new Error('no matched rule')\n}\n\nprogram\n .command('init [name]')\n .option('-t, --template <template>', 'the package.json template file path or file content')\n .action(async () => {\n const [, name] = program.args\n const cwd = process.cwd()\n const { init = {} }: Config = loadConfig() ?? {}\n const { wd } = getWD()\n const workspaceName = path.basename(wd)\n\n const {\n named,\n template,\n bug = {},\n readme: _readme = README_TEMPLATE,\n readmeTemplate\n } = init\n const resolvedBug = {\n template: 'bug_report.yml',\n labels: ['bug'],\n ...bug\n }\n let readme = _readme\n if (readmeTemplate) {\n const readmeTemplatePath = path.resolve(wd, readmeTemplate)\n readme = fs.readFileSync(readmeTemplatePath, 'utf-8')\n }\n\n const templateString = getTemplateStr(wd, template)\n // TODO detectIndent by editorconfig\n const { indent = ' ' } = detectIndent(templateString)\n const formattingOptions = {\n tabSize: indent.length,\n insertSpaces: true\n }\n const passFields = [\n 'license', 'author'\n ]\n let newJSONString = templateString\n for (const field of passFields) {\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, [field], getWDPackageJSONFiled(wd, field), { formattingOptions }\n ))\n }\n let [pkgName, pkgDir] = await getName(named, name, {\n wd, cwd,\n workspaceName\n })\n if (!pkgDir) {\n const { dir } = await inquirer.prompt<{ dir: string }>({\n type: 'input',\n name: 'dir',\n message: 'package directory',\n default: name\n })\n pkgDir = dir\n }\n if (!pkgName) {\n const { name: inputName } = await inquirer.prompt<{\n name: string\n }>({\n type: 'input',\n name: 'name',\n message: 'package name',\n default: name\n })\n pkgName = inputName\n }\n newJSONString = applyEdits(newJSONString, modify(newJSONString, ['name'], pkgName, { formattingOptions }))\n\n let pkgRepo = getWDPackageJSONFiled(wd, 'repository')\n if (typeof pkgRepo === 'string') {\n pkgRepo = {\n type: 'git',\n url: pkgRepo,\n directory: pkgDir\n }\n }\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['repository'], pkgRepo, { formattingOptions }\n ))\n const homepage = `${pkgRepo?.url}/blob/master/${pkgDir}/README.md`\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['homepage'], homepage, { formattingOptions }\n ))\n let labels = resolvedBug.labels\n if (typeof labels === 'function') labels = labels({\n name: pkgName, dir: pkgDir\n })\n labels.push(`scope:${pkgName}`)\n const bugs = `${pkgRepo?.url}/issues/new?template=${\n resolvedBug.template\n }&labels=${\n labels.join(',')\n }`\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['bugs'], bugs, { formattingOptions }\n ))\n\n function pkgDirTo(to: string) {\n if (!pkgDir) throw new Error('pkgDir is not defined')\n\n return path.resolve(pkgDir, to)\n }\n if (!fs.existsSync(pkgDir)) fs.mkdirSync(pkgDir)\n const pkgJSONFilePath = pkgDirTo('package.json')\n if (fs.existsSync(pkgJSONFilePath)) {\n throw new Error('package.json already exists')\n }\n fs.writeFileSync(pkgJSONFilePath, newJSONString)\n console.log(newJSONString, 'written to', pkgJSONFilePath)\n\n const license = getWDPackageJSONFiled(wd, 'license')\n const readmeFilePath = pkgDirTo('README.md')\n if (typeof readme === 'function') {\n readme = readme({\n dir: pkgDir,\n packageJson: JSON.parse(newJSONString)\n })\n }\n const readmeContent = readme\n .replace(/\\$name/g, pkgName)\n .replace(/\\$license/g, license)\n fs.writeFileSync(readmeFilePath, readmeContent)\n })\n"],"names":["name"],"mappings":";;;;;;;;;;AAaA,MAAM,qBAAwB,GAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA,CAAA,CAe3B,SAAU,EAAA,CAAA;AACb,MAAM,eAAkB,GAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA,CAkBtB,SAAU,EAAA,CAAA;AAEZ,SAAS,cAAA,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CAAA,CAAA;AAAA,GACH;AACA,EAAM,MAAA,aAAA,GAAgB,OACnB,OAAQ,CAAA,SAAA,EAAW,OAAO,CAC1B,CAAA,OAAA,CAAQ,cAAc,OAAO,CAAA,CAAA;AAChC,EAAG,EAAA,CAAA,aAAA,CAAc,gBAAgB,aAAa,CAAA,CAAA;AAChD,CAAC,CAAA"}
|
@@ -1,2 +0,0 @@
|
|
1
|
-
import e from"node:fs";import t from"node:path";import{program as n}from"commander";import a from"detect-indent";import r from"inquirer";import{applyEdits as o,modify as i}from"jsonc-parser";import{isMatch as s}from"micromatch";import{getWD as m}from"../utils/getWD.esm.min.js";import{loadConfig as c}from"../utils/loadConfig.esm.min.js";const p='{\n "name": "",\n "version": "0.0.1",\n "description": "",\n "license": "",\n "author": "",\n "files": ["dist"],\n "exports": {\n ".": "./src/index.ts"\n },\n "scripts": {\n },\n "homepage": "",\n "repository": "",\n "bugs": ""\n}'.trimStart(),l="# $name\n\n## Installation\n\n```bash\nnpm install $name\n# or\npnpm install $name\n# or\nyarn add $name\n```\n\n## Usage\n\n\n## License\n\n$license\n".trimStart();const f=new Map;function u(n,a){if(f.has(n))return f.get(n)[a];const r=t.resolve(n,"package.json"),o=JSON.parse(e.readFileSync(r,"utf-8"));return f.set(n,o),o[a]}n.command("init [name]").option("-t, --template <template>","the package.json template file path or file content").action((async()=>{const[,f]=n.args,d=process.cwd(),{init:g={}}=c()??{},{wd:y}=m(),w=t.basename(y),{named:h,template:b,bug:$={},readme:k=l,readmeTemplate:S}=g,j={template:"bug_report.yml",labels:["bug"],...$};let O=k;if(S){const n=t.resolve(y,S);O=e.readFileSync(n,"utf-8")}const E=function(n,a){let r=a??p,o=!1;try{a&&JSON.parse(a)}catch(e){o=!0}if(o){const o=t.resolve(n,a);r=e.readFileSync(o,"utf-8")}return r}(y,b),{indent:v=" "}=a(E),_={tabSize:v.length,insertSpaces:!0},x=["license","author"];let F=E;for(const e of x)F=o(F,i(F,[e],u(y,e),{formattingOptions:_}));let[N,D]=await async function(e,n,{wd:a,cwd:o,workspaceName:i}){const m=o.replace(`${a}/`,"");let c=t.basename(o);if("function"==typeof e)return e(n,{full:a,relative:o});let p,l,f=!1;if("object"==typeof e)if(o===a){const{rule:t}=await r.prompt({type:"list",name:"rule",message:"choose a rule",default:"default",choices:["default"].concat(Object.keys(e))});"default"!==t&&(p=t,l=e[t])}else for(const[t,n]of Object.entries(e)){if(s(m,t)){p=t,l=n;break}if(s(`${m}/jiek_ignore_dont_use_same_file_name`,t)){f=!0,p=t,l=n;break}}if(l||(p="packages/*",l=`@${i}/$basename`),!l)throw new Error("no matched rule");if(!n&&f&&(c=await r.prompt({type:"input",name:"name",message:`the matched rule is \`${String(l)}\`, please input the basename\n`}).then((({name:e})=>e))),"function"==typeof l)return l(n,{full:a,relative:o,basename:c});if("string"==typeof l){const e=n??c;return[l.replace(/\$basename/g,e),p?.replace(/\/\*$/g,`/${e}`)]}throw new Error("no matched rule")}(h,f,{wd:y,cwd:d,workspaceName:w});if(!D){const{dir:e}=await r.prompt({type:"input",name:"dir",message:"package directory",default:f});D=e}if(!N){const{name:e}=await r.prompt({type:"input",name:"name",message:"package name",default:f});N=e}F=o(F,i(F,["name"],N,{formattingOptions:_}));let J=u(y,"repository");"string"==typeof J&&(J={type:"git",url:J,directory:D}),F=o(F,i(F,["repository"],J,{formattingOptions:_}));F=o(F,i(F,["homepage"],`${J?.url}/blob/master/${D}/README.md`,{formattingOptions:_}));let M=j.labels;"function"==typeof M&&(M=M({name:N,dir:D})),M.push(`scope:${N}`);const A=`${J?.url}/issues/new?template=${j.template}&labels=${M.join(",")}`;function R(e){if(!D)throw new Error("pkgDir is not defined");return t.resolve(D,e)}F=o(F,i(F,["bugs"],A,{formattingOptions:_})),e.existsSync(D)||e.mkdirSync(D);const q=R("package.json");if(e.existsSync(q))throw new Error("package.json already exists");e.writeFileSync(q,F),console.log(F,"written to",q);const z=u(y,"license"),C=R("README.md");"function"==typeof O&&(O=O({dir:D,packageJson:JSON.parse(F)}));const I=O.replace(/\$name/g,N).replace(/\$license/g,z);e.writeFileSync(C,I)}));
|
2
|
-
//# sourceMappingURL=init.esm.min.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"init.esm.min.js","sources":["../../src/commands/init.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\nimport detectIndent from 'detect-indent'\nimport inquirer from 'inquirer'\nimport { applyEdits, modify } from 'jsonc-parser'\nimport { isMatch } from 'micromatch'\n\nimport type { Config, InitNamed } from '../base'\nimport { getWD } from '../utils/getWD'\nimport { loadConfig } from '../utils/loadConfig'\n\nconst PACKAGE_JSON_TEMPLATE = `{\n \"name\": \"\",\n \"version\": \"0.0.1\",\n \"description\": \"\",\n \"license\": \"\",\n \"author\": \"\",\n \"files\": [\"dist\"],\n \"exports\": {\n \".\": \"./src/index.ts\"\n },\n \"scripts\": {\n },\n \"homepage\": \"\",\n \"repository\": \"\",\n \"bugs\": \"\"\n}`.trimStart()\nconst README_TEMPLATE = `# $name\n\n## Installation\n\n\\`\\`\\`bash\nnpm install $name\n# or\npnpm install $name\n# or\nyarn add $name\n\\`\\`\\`\n\n## Usage\n\n\n## License\n\n$license\n`.trimStart()\n\nfunction getTemplateStr(wd: string, template: string | undefined) {\n let templateString = template ?? PACKAGE_JSON_TEMPLATE\n let isTemplateFile = false\n try {\n if (template) JSON.parse(template)\n } catch (e) {\n isTemplateFile = true\n }\n if (isTemplateFile) {\n const templatePath = path.resolve(wd, template!)\n templateString = fs.readFileSync(templatePath, 'utf-8')\n }\n return templateString\n}\nconst wdCache = new Map<string, Record<string, any>>()\nfunction getWDPackageJSONFiled(wd: string, field: string) {\n if (wdCache.has(wd)) {\n return wdCache.get(wd)![field]\n }\n const packageJSONPath = path.resolve(wd, 'package.json')\n const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8'))\n wdCache.set(wd, packageJSON)\n return packageJSON[field]\n}\nasync function getName(\n named: InitNamed | undefined,\n name: string,\n {\n wd, cwd,\n workspaceName\n }: {\n wd: string\n cwd: string\n workspaceName: string\n }\n): Promise<[name?: string, path?: string]> {\n const relativePath = cwd.replace(`${wd}/`, '')\n let basename = path.basename(cwd)\n\n if (typeof named === 'function') {\n return named(name, {\n full: wd,\n relative: cwd\n })\n }\n\n let isParentMatched = false\n let matchedKey: string | undefined\n let matchedRule: NonNullable<typeof named>[string] | undefined\n if (typeof named === 'object') {\n const isWD = cwd === wd\n if (isWD) {\n const { rule } = await inquirer.prompt<{ rule: string }>({\n type: 'list',\n name: 'rule',\n message: 'choose a rule',\n default: 'default',\n choices: ['default'].concat(Object.keys(named))\n })\n if (rule !== 'default') {\n matchedKey = rule\n matchedRule = named[rule]\n }\n } else for (const [key, value] of Object.entries(named)) {\n if (isMatch(relativePath, key)) {\n matchedKey = key\n matchedRule = value\n break\n }\n if (isMatch(`${relativePath}/jiek_ignore_dont_use_same_file_name`, key)) {\n isParentMatched = true\n matchedKey = key\n matchedRule = value\n break\n }\n }\n }\n if (!matchedRule) {\n matchedKey = 'packages/*'\n matchedRule = `@${workspaceName}/$basename`\n }\n if (!matchedRule)\n throw new Error('no matched rule')\n if (!name && isParentMatched) {\n basename = await inquirer.prompt<{ name: string }>({\n type: 'input',\n name: 'name',\n message: `the matched rule is \\`${String(matchedRule)}\\`, please input the basename\\n`\n }).then(({ name }) => name)\n }\n\n if (typeof matchedRule === 'function') {\n return matchedRule(name, {\n full: wd,\n relative: cwd,\n basename: basename\n })\n }\n if (typeof matchedRule === 'string') {\n const dirName = name ?? basename\n return [\n matchedRule.replace(/\\$basename/g, dirName),\n matchedKey?.replace(/\\/\\*$/g, `/${dirName}`)\n ]\n }\n throw new Error('no matched rule')\n}\n\nprogram\n .command('init [name]')\n .option('-t, --template <template>', 'the package.json template file path or file content')\n .action(async () => {\n const [, name] = program.args\n const cwd = process.cwd()\n const { init = {} }: Config = loadConfig() ?? {}\n const { wd } = getWD()\n const workspaceName = path.basename(wd)\n\n const {\n named,\n template,\n bug = {},\n readme: _readme = README_TEMPLATE,\n readmeTemplate\n } = init\n const resolvedBug = {\n template: 'bug_report.yml',\n labels: ['bug'],\n ...bug\n }\n let readme = _readme\n if (readmeTemplate) {\n const readmeTemplatePath = path.resolve(wd, readmeTemplate)\n readme = fs.readFileSync(readmeTemplatePath, 'utf-8')\n }\n\n const templateString = getTemplateStr(wd, template)\n // TODO detectIndent by editorconfig\n const { indent = ' ' } = detectIndent(templateString)\n const formattingOptions = {\n tabSize: indent.length,\n insertSpaces: true\n }\n const passFields = [\n 'license', 'author'\n ]\n let newJSONString = templateString\n for (const field of passFields) {\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, [field], getWDPackageJSONFiled(wd, field), { formattingOptions }\n ))\n }\n let [pkgName, pkgDir] = await getName(named, name, {\n wd, cwd,\n workspaceName\n })\n if (!pkgDir) {\n const { dir } = await inquirer.prompt<{ dir: string }>({\n type: 'input',\n name: 'dir',\n message: 'package directory',\n default: name\n })\n pkgDir = dir\n }\n if (!pkgName) {\n const { name: inputName } = await inquirer.prompt<{\n name: string\n }>({\n type: 'input',\n name: 'name',\n message: 'package name',\n default: name\n })\n pkgName = inputName\n }\n newJSONString = applyEdits(newJSONString, modify(newJSONString, ['name'], pkgName, { formattingOptions }))\n\n let pkgRepo = getWDPackageJSONFiled(wd, 'repository')\n if (typeof pkgRepo === 'string') {\n pkgRepo = {\n type: 'git',\n url: pkgRepo,\n directory: pkgDir\n }\n }\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['repository'], pkgRepo, { formattingOptions }\n ))\n const homepage = `${pkgRepo?.url}/blob/master/${pkgDir}/README.md`\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['homepage'], homepage, { formattingOptions }\n ))\n let labels = resolvedBug.labels\n if (typeof labels === 'function') labels = labels({\n name: pkgName, dir: pkgDir\n })\n labels.push(`scope:${pkgName}`)\n const bugs = `${pkgRepo?.url}/issues/new?template=${\n resolvedBug.template\n }&labels=${\n labels.join(',')\n }`\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['bugs'], bugs, { formattingOptions }\n ))\n\n function pkgDirTo(to: string) {\n if (!pkgDir) throw new Error('pkgDir is not defined')\n\n return path.resolve(pkgDir, to)\n }\n if (!fs.existsSync(pkgDir)) fs.mkdirSync(pkgDir)\n const pkgJSONFilePath = pkgDirTo('package.json')\n if (fs.existsSync(pkgJSONFilePath)) {\n throw new Error('package.json already exists')\n }\n fs.writeFileSync(pkgJSONFilePath, newJSONString)\n console.log(newJSONString, 'written to', pkgJSONFilePath)\n\n const license = getWDPackageJSONFiled(wd, 'license')\n const readmeFilePath = pkgDirTo('README.md')\n if (typeof readme === 'function') {\n readme = readme({\n dir: pkgDir,\n packageJson: JSON.parse(newJSONString)\n })\n }\n const readmeContent = readme\n .replace(/\\$name/g, pkgName)\n .replace(/\\$license/g, license)\n fs.writeFileSync(readmeFilePath, readmeContent)\n })\n"],"names":["PACKAGE_JSON_TEMPLATE","trimStart","README_TEMPLATE","wdCache","Map","getWDPackageJSONFiled","wd","field","has","get","packageJSONPath","path","resolve","packageJSON","JSON","parse","fs","readFileSync","set","program","command","option","action","async","name","args","cwd","process","init","loadConfig","getWD","workspaceName","basename","named","template","bug","readme","_readme","readmeTemplate","resolvedBug","labels","readmeTemplatePath","templateString","isTemplateFile","e","templatePath","getTemplateStr","indent","detectIndent","formattingOptions","tabSize","length","insertSpaces","passFields","newJSONString","applyEdits","modify","pkgName","pkgDir","relativePath","replace","full","relative","matchedKey","matchedRule","isParentMatched","rule","inquirer","prompt","type","message","default","choices","concat","Object","keys","key","value","entries","isMatch","Error","String","then","dirName","getName","dir","inputName","pkgRepo","url","directory","push","bugs","join","pkgDirTo","to","existsSync","mkdirSync","pkgJSONFilePath","writeFileSync","console","log","license","readmeFilePath","packageJson","readmeContent"],"mappings":"kVAaA,MAAMA,EAAwB,yPAe3BC,YACGC,EAAkB,0JAkBtBD,YAgBF,MAAME,MAAcC,IACpB,SAASC,EAAsB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IAAIjB,MAAM,+BAEfhE,EAAAkF,cAAcD,EAAiB3C,GAC1B6C,QAAAC,IAAI9C,EAAe,aAAc2C,GAEnC,MAAAI,EAAUhG,EAAsBC,EAAI,WACpCgG,EAAiBT,EAAS,aACV,mBAAXzD,IACTA,EAASA,EAAO,CACdiD,IAAK3B,EACL6C,YAAazF,KAAKC,MAAMuC,MAGtB,MAAAkD,EAAgBpE,EACnBwB,QAAQ,UAAWH,GACnBG,QAAQ,aAAcyC,GACtBrF,EAAAkF,cAAcI,EAAgBE,EAAa"}
|
@@ -1,87 +0,0 @@
|
|
1
|
-
import * as childProcess from 'node:child_process';
|
2
|
-
import fs from 'node:fs';
|
3
|
-
import path from 'node:path';
|
4
|
-
import { bump } from '@jiek/utils/bumper';
|
5
|
-
import { program } from 'commander';
|
6
|
-
import detectIndent from 'detect-indent';
|
7
|
-
import { applyEdits, modify } from 'jsonc-parser';
|
8
|
-
import { actionRestore, actionDone } from '../inner.esm.js';
|
9
|
-
import { mergePackageJson } from '../merge-package-json.esm.js';
|
10
|
-
import { getSelectedProjectsGraph } from '../utils/filterSupport.esm.js';
|
11
|
-
|
12
|
-
program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-p, --preview", "preview publish").action(async ({ preview, bumper, ...options }) => {
|
13
|
-
actionRestore();
|
14
|
-
const { value = {} } = await getSelectedProjectsGraph() ?? {};
|
15
|
-
const selectedProjectsGraphEntries = Object.entries(value);
|
16
|
-
if (selectedProjectsGraphEntries.length === 0) {
|
17
|
-
throw new Error("no packages selected");
|
18
|
-
}
|
19
|
-
const mainfests = selectedProjectsGraphEntries.map(([dir, manifest]) => [
|
20
|
-
dir,
|
21
|
-
mergePackageJson(manifest, dir)
|
22
|
-
]);
|
23
|
-
const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
|
24
|
-
if (value2) {
|
25
|
-
acc.push(`--${key}`, value2);
|
26
|
-
}
|
27
|
-
return acc;
|
28
|
-
}, []);
|
29
|
-
for (const [dir, manifest] of mainfests) {
|
30
|
-
const oldJSONString = fs.readFileSync(path.join(dir, "package.json"), "utf-8");
|
31
|
-
const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
|
32
|
-
const newVersion = bump(oldJSON.version, bumper);
|
33
|
-
const { indent = " " } = detectIndent(oldJSONString);
|
34
|
-
const formattingOptions = {
|
35
|
-
tabSize: indent.length,
|
36
|
-
insertSpaces: true
|
37
|
-
};
|
38
|
-
let newJSONString = oldJSONString;
|
39
|
-
newJSONString = applyEdits(newJSONString, modify(
|
40
|
-
newJSONString,
|
41
|
-
["version"],
|
42
|
-
newVersion,
|
43
|
-
{ formattingOptions }
|
44
|
-
));
|
45
|
-
for (const [key, value2] of Object.entries(manifest)) {
|
46
|
-
if (JSON.stringify(value2) === JSON.stringify(oldJSON[key]))
|
47
|
-
continue;
|
48
|
-
if (key !== "exports") {
|
49
|
-
newJSONString = applyEdits(newJSONString, modify(
|
50
|
-
newJSONString,
|
51
|
-
["publishConfig", key],
|
52
|
-
value2,
|
53
|
-
{ formattingOptions }
|
54
|
-
));
|
55
|
-
} else {
|
56
|
-
for (const [k, v] of Object.entries(value2)) {
|
57
|
-
newJSONString = applyEdits(newJSONString, modify(
|
58
|
-
newJSONString,
|
59
|
-
["publishConfig", "exports", k],
|
60
|
-
v,
|
61
|
-
{ formattingOptions }
|
62
|
-
));
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
try {
|
67
|
-
fs.renameSync(path.join(dir, "package.json"), path.join(dir, "package.json.bak"));
|
68
|
-
fs.writeFileSync(path.join(dir, "package.json"), newJSONString);
|
69
|
-
console.log(newJSONString);
|
70
|
-
if (preview) {
|
71
|
-
console.warn("preview mode");
|
72
|
-
continue;
|
73
|
-
}
|
74
|
-
childProcess.execSync(["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs].join(" "), {
|
75
|
-
cwd: dir,
|
76
|
-
stdio: "inherit"
|
77
|
-
});
|
78
|
-
const modifyVersionPackageJSON = applyEdits(oldJSONString, modify(oldJSONString, ["version"], newVersion, {}));
|
79
|
-
fs.writeFileSync(path.join(dir, "package.json.bak"), modifyVersionPackageJSON);
|
80
|
-
} finally {
|
81
|
-
fs.unlinkSync(path.join(dir, "package.json"));
|
82
|
-
fs.renameSync(path.join(dir, "package.json.bak"), path.join(dir, "package.json"));
|
83
|
-
}
|
84
|
-
}
|
85
|
-
actionDone();
|
86
|
-
});
|
87
|
-
//# sourceMappingURL=publish.esm.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"publish.esm.js","sources":["../../src/commands/publish.ts"],"sourcesContent":["import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { bump, type BumperType } from '@jiek/utils/bumper'\nimport { program } from 'commander'\nimport detectIndent from 'detect-indent'\nimport { applyEdits, modify } from 'jsonc-parser'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\n\nprogram\n .command('publish')\n .aliases(['pub', 'p'])\n .option('-b, --bumper <bumper>', 'bump version', 'patch')\n .option('-p, --preview', 'preview publish')\n .action(async ({ preview, bumper, ...options }: {\n preview?: boolean\n bumper: BumperType\n }) => {\n actionRestore()\n\n const { value = {} } = await getSelectedProjectsGraph() ?? {}\n const selectedProjectsGraphEntries = Object.entries(value)\n if (selectedProjectsGraphEntries.length === 0) {\n throw new Error('no packages selected')\n }\n const mainfests = selectedProjectsGraphEntries\n .map(([dir, manifest]) => [\n dir, mergePackageJson(manifest, dir)\n ] as const)\n const passArgs = Object\n .entries(options)\n .reduce((acc, [key, value]) => {\n if (value) {\n acc.push(`--${key}`, value as string)\n }\n return acc\n }, [] as string[])\n for (const [dir, manifest] of mainfests) {\n const oldJSONString = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8')\n const oldJSON = JSON.parse(oldJSONString) ?? '0.0.0'\n const newVersion = bump(oldJSON.version, bumper)\n // TODO detectIndent by editorconfig\n const { indent = ' ' } = detectIndent(oldJSONString)\n const formattingOptions = {\n tabSize: indent.length,\n insertSpaces: true\n }\n let newJSONString = oldJSONString\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['version'], newVersion, { formattingOptions }\n ))\n for (const [key, value] of Object.entries(manifest)) {\n if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue\n\n if (key !== 'exports') {\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['publishConfig', key], value, { formattingOptions }\n ))\n } else {\n for (const [k, v] of Object.entries(value)) {\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['publishConfig', 'exports', k], v, { formattingOptions }\n ))\n }\n }\n }\n try {\n fs.renameSync(path.join(dir, 'package.json'), path.join(dir, 'package.json.bak'))\n fs.writeFileSync(path.join(dir, 'package.json'), newJSONString)\n console.log(newJSONString)\n if (preview) {\n console.warn('preview mode')\n continue\n }\n childProcess.execSync(['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs].join(' '), {\n cwd: dir,\n stdio: 'inherit'\n })\n const modifyVersionPackageJSON = applyEdits(oldJSONString, modify(oldJSONString, ['version'], newVersion, {}))\n fs.writeFileSync(path.join(dir, 'package.json.bak'), modifyVersionPackageJSON)\n } finally {\n fs.unlinkSync(path.join(dir, 'package.json'))\n fs.renameSync(path.join(dir, 'package.json.bak'), path.join(dir, 'package.json'))\n }\n }\n actionDone()\n })\n"],"names":["value"],"mappings":";;;;;;;;;;;AAaA,OACG,CAAA,OAAA,CAAQ,SAAS,CAAA,CACjB,OAAQ,CAAA,CAAC,OAAO,GAAG,CAAC,CACpB,CAAA,MAAA,CAAO,uBAAyB,EAAA,cAAA,EAAgB,OAAO,CACvD,CAAA,MAAA,CAAO,eAAiB,EAAA,iBAAiB,CACzC,CAAA,MAAA,CAAO,OAAO,EAAE,OAAS,EAAA,MAAA,EAAQ,GAAG,OAAA,EAG/B,KAAA;AACJ,EAAc,aAAA,EAAA,CAAA;AA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,GAAK,EAAA,kBAAkB,CAAC,CAAA,CAAA;AAChF,MAAA,EAAA,CAAG,cAAc,IAAK,CAAA,IAAA,CAAK,GAAK,EAAA,cAAc,GAAG,aAAa,CAAA,CAAA;AAC9D,MAAA,OAAA,CAAQ,IAAI,aAAa,CAAA,CAAA;AACzB,MAAA,IAAI,OAAS,EAAA;AACX,QAAA,OAAA,CAAQ,KAAK,cAAc,CAAA,CAAA;AAC3B,QAAA,SAAA;AAAA,OACF;AACA,MAAA,YAAA,CAAa,QAAS,CAAA,CAAC,MAAQ,EAAA,SAAA,EAAW,UAAY,EAAA,QAAA,EAAU,iBAAmB,EAAA,GAAG,QAAQ,CAAA,CAAE,IAAK,CAAA,GAAG,CAAG,EAAA;AAAA,QACzG,GAAK,EAAA,GAAA;AAAA,QACL,KAAO,EAAA,SAAA;AAAA,OACR,CAAA,CAAA;AACD,MAAM,MAAA,wBAAA,GAA2B,UAAW,CAAA,aAAA,EAAe,MAAO,CAAA,aAAA,EAAe,CAAC,SAAS,CAAG,EAAA,UAAA,EAAY,EAAE,CAAC,CAAA,CAAA;AAC7G,MAAA,EAAA,CAAG,cAAc,IAAK,CAAA,IAAA,CAAK,GAAK,EAAA,kBAAkB,GAAG,wBAAwB,CAAA,CAAA;AAAA,KAC7E,SAAA;AACA,MAAA,EAAA,CAAG,UAAW,CAAA,IAAA,CAAK,IAAK,CAAA,GAAA,EAAK,cAAc,CAAC,CAAA,CAAA;AAC5C,MAAG,EAAA,CAAA,UAAA,CAAW,IAAK,CAAA,IAAA,CAAK,GAAK,EAAA,kBAAkB,GAAG,IAAK,CAAA,IAAA,CAAK,GAAK,EAAA,cAAc,CAAC,CAAA,CAAA;AAAA,KAClF;AAAA,GACF;AACA,EAAW,UAAA,EAAA,CAAA;AACb,CAAC,CAAA"}
|
@@ -1,2 +0,0 @@
|
|
1
|
-
import*as e from"node:child_process";import o from"node:fs";import n from"node:path";import{bump as i}from"@jiek/utils/bumper";import{program as r}from"commander";import t from"detect-indent";import{applyEdits as s,modify as p}from"jsonc-parser";import{actionRestore as c,actionDone as a}from"../inner.esm.min.js";import{mergePackageJson as m}from"../merge-package-json.esm.min.js";import{getSelectedProjectsGraph as f}from"../utils/filterSupport.esm.min.js";r.command("publish").aliases(["pub","p"]).option("-b, --bumper <bumper>","bump version","patch").option("-p, --preview","preview publish").action((async({preview:r,bumper:j,...l})=>{c();const{value:g={}}=await f()??{},b=Object.entries(g);if(0===b.length)throw new Error("no packages selected");const u=b.map((([e,o])=>[e,m(o,e)])),k=Object.entries(l).reduce(((e,[o,n])=>(n&&e.push(`--${o}`,n),e)),[]);for(const[c,a]of u){const m=o.readFileSync(n.join(c,"package.json"),"utf-8"),f=JSON.parse(m)??"0.0.0",l=i(f.version,j),{indent:g=" "}=t(m),b={tabSize:g.length,insertSpaces:!0};let u=m;u=s(u,p(u,["version"],l,{formattingOptions:b}));for(const[e,o]of Object.entries(a))if(JSON.stringify(o)!==JSON.stringify(f[e]))if("exports"!==e)u=s(u,p(u,["publishConfig",e],o,{formattingOptions:b}));else for(const[e,n]of Object.entries(o))u=s(u,p(u,["publishConfig","exports",e],n,{formattingOptions:b}));try{if(o.renameSync(n.join(c,"package.json"),n.join(c,"package.json.bak")),o.writeFileSync(n.join(c,"package.json"),u),console.log(u),r){console.warn("preview mode");continue}e.execSync(["pnpm","publish","--access","public","--no-git-checks",...k].join(" "),{cwd:c,stdio:"inherit"});const i=s(m,p(m,["version"],l,{}));o.writeFileSync(n.join(c,"package.json.bak"),i)}finally{o.unlinkSync(n.join(c,"package.json")),o.renameSync(n.join(c,"package.json.bak"),n.join(c,"package.json"))}}a()}));
|
2
|
-
//# sourceMappingURL=publish.esm.min.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"publish.esm.min.js","sources":["../../src/commands/publish.ts"],"sourcesContent":["import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { bump, type BumperType } from '@jiek/utils/bumper'\nimport { program } from 'commander'\nimport detectIndent from 'detect-indent'\nimport { applyEdits, modify } from 'jsonc-parser'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\n\nprogram\n .command('publish')\n .aliases(['pub', 'p'])\n .option('-b, --bumper <bumper>', 'bump version', 'patch')\n .option('-p, --preview', 'preview publish')\n .action(async ({ preview, bumper, ...options }: {\n preview?: boolean\n bumper: BumperType\n }) => {\n actionRestore()\n\n const { value = {} } = await getSelectedProjectsGraph() ?? {}\n const selectedProjectsGraphEntries = Object.entries(value)\n if (selectedProjectsGraphEntries.length === 0) {\n throw new Error('no packages selected')\n }\n const mainfests = selectedProjectsGraphEntries\n .map(([dir, manifest]) => [\n dir, mergePackageJson(manifest, dir)\n ] as const)\n const passArgs = Object\n .entries(options)\n .reduce((acc, [key, value]) => {\n if (value) {\n acc.push(`--${key}`, value as string)\n }\n return acc\n }, [] as string[])\n for (const [dir, manifest] of mainfests) {\n const oldJSONString = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8')\n const oldJSON = JSON.parse(oldJSONString) ?? '0.0.0'\n const newVersion = bump(oldJSON.version, bumper)\n // TODO detectIndent by editorconfig\n const { indent = ' ' } = detectIndent(oldJSONString)\n const formattingOptions = {\n tabSize: indent.length,\n insertSpaces: true\n }\n let newJSONString = oldJSONString\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['version'], newVersion, { formattingOptions }\n ))\n for (const [key, value] of Object.entries(manifest)) {\n if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue\n\n if (key !== 'exports') {\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['publishConfig', key], value, { formattingOptions }\n ))\n } else {\n for (const [k, v] of Object.entries(value)) {\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['publishConfig', 'exports', k], v, { formattingOptions }\n ))\n }\n }\n }\n try {\n fs.renameSync(path.join(dir, 'package.json'), path.join(dir, 'package.json.bak'))\n fs.writeFileSync(path.join(dir, 'package.json'), newJSONString)\n console.log(newJSONString)\n if (preview) {\n console.warn('preview mode')\n continue\n }\n childProcess.execSync(['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs].join(' '), {\n cwd: dir,\n stdio: 'inherit'\n })\n const modifyVersionPackageJSON = applyEdits(oldJSONString, modify(oldJSONString, ['version'], newVersion, {}))\n fs.writeFileSync(path.join(dir, 'package.json.bak'), modifyVersionPackageJSON)\n } finally {\n fs.unlinkSync(path.join(dir, 'package.json'))\n fs.renameSync(path.join(dir, 'package.json.bak'), path.join(dir, 'package.json'))\n }\n }\n actionDone()\n })\n"],"names":["program","command","aliases","option","action","async","preview","bumper","options","actionRestore","value","getSelectedProjectsGraph","selectedProjectsGraphEntries","Object","entries","length","Error","mainfests","map","dir","manifest","mergePackageJson","passArgs","reduce","acc","key","push","oldJSONString","fs","readFileSync","path","join","oldJSON","JSON","parse","newVersion","bump","version","indent","detectIndent","formattingOptions","tabSize","insertSpaces","newJSONString","applyEdits","modify","stringify","k","v","renameSync","writeFileSync","console","log","warn","childProcess","execSync","cwd","stdio","modifyVersionPackageJSON","unlinkSync","actionDone"],"mappings":"2cAaAA,EACGC,QAAQ,WACRC,QAAQ,CAAC,MAAO,MAChBC,OAAO,wBAAyB,eAAgB,SAChDA,OAAO,gBAAiB,mBACxBC,QAAOC,OAASC,UAASC,YAAWC,MAIrBC,IAER,MAAAC,MAAEA,EAAQ,CAAC,SAAYC,KAA8B,CAAA,EACrDC,EAA+BC,OAAOC,QAAQJ,GAChD,GAAwC,IAAxCE,EAA6BG,OACzB,MAAA,IAAIC,MAAM,wBAElB,MAAMC,EAAYL,EACfM,KAAI,EAAEC,EAAKC,KAAc,CACxBD,EAAKE,EAAiBD,EAAUD,MAE9BG,EAAWT,OACdC,QAAQN,GACRe,QAAO,CAACC,GAAMC,EAAKf,MACdA,GACFc,EAAIE,KAAK,KAAKD,IAAOf,GAEhBc,IACN,IACL,IAAA,MAAYL,EAA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qB,WAAWnB,EAAKC,KAAKZ,EAAK,oBAAqBW,EAAKC,KAAKZ,EAAK,gBACnE,CACF,CACWyC,GAAA"}
|
package/dist/index.cjs.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import type { Config } from './base'\n\nexport const defineConfig = (config: Config) => config\n\nexport * from './base'\n"],"names":[],"mappings":";;AAEa,MAAA,YAAA,GAAe,CAAC,MAAmB,KAAA;;;;"}
|
package/dist/index.esm.d.ts
DELETED
package/dist/index.esm.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["import type { Config } from './base'\n\nexport const defineConfig = (config: Config) => config\n\nexport * from './base'\n"],"names":[],"mappings":"AAEa,MAAA,YAAA,GAAe,CAAC,MAAmB,KAAA;;;;"}
|
package/dist/index.esm.min.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.esm.min.js","sources":["../src/index.ts"],"sourcesContent":["import type { Config } from './base'\n\nexport const defineConfig = (config: Config) => config\n\nexport * from './base'\n"],"names":["defineConfig","config"],"mappings":"AAEa,MAAAA,EAAgBC,GAAmBA"}
|
package/dist/index.min.cjs.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.min.cjs","sources":["../src/index.ts"],"sourcesContent":["import type { Config } from './base'\n\nexport const defineConfig = (config: Config) => config\n\nexport * from './base'\n"],"names":["config"],"mappings":"kCAE6BA,GAAmBA"}
|
package/dist/inner.esm.js
DELETED
package/dist/inner.esm.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"inner.esm.js","sources":["../src/inner.ts"],"sourcesContent":["let resolve: () => void\n\nexport let actionFuture: Promise<void>\n\nexport function actionDone() {\n resolve()\n}\n\nexport function actionRestore() {\n actionFuture = new Promise<void>(r => resolve = r)\n}\n"],"names":[],"mappings":"AAAA,IAAI,OAAA,CAAA;AAIG,SAAS,UAAa,GAAA;AAC3B,EAAQ,OAAA,EAAA,CAAA;AACV,CAAA;AAEO,SAAS,aAAgB,GAAA;AAC9B,EAAe,IAAI,OAAA,CAAc,CAAK,CAAA,KAAA,OAAA,GAAU,CAAC,CAAA,CAAA;AACnD;;;;"}
|
package/dist/inner.esm.min.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"inner.esm.min.js","sources":["../src/inner.ts"],"sourcesContent":["let resolve: () => void\n\nexport let actionFuture: Promise<void>\n\nexport function actionDone() {\n resolve()\n}\n\nexport function actionRestore() {\n actionFuture = new Promise<void>(r => resolve = r)\n}\n"],"names":["resolve","actionDone","actionRestore","Promise","r"],"mappings":"AAAA,IAAIA,EAIG,SAASC,IACND,GACV,CAEO,SAASE,IACC,IAAIC,SAAmBC,GAAAJ,EAAUI,GAClD"}
|