@bizhermit/npm-package-utils
Version:
npm package utils
1 lines • 2.02 kB
JavaScript
;var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const fs_1=require("fs"),path_1=__importDefault(require("path")),utils_1=require("./utils"),packNpmPackage=e=>{const s=path_1.default.join(e,"package"),t=JSON.parse((0,fs_1.readFileSync)(path_1.default.join(e,"package.json")).toString()),i=path_1.default.join(e,"src/package.json"),n=JSON.parse((0,fs_1.readFileSync)(i).toString());n.version=t.version||"0.0.0-alpha.0";let a=path_1.default.join(e,"src/index.d.ts");(0,fs_1.existsSync)(a)?((0,fs_1.copyFileSync)(a,path_1.default.join(s,"index.d.ts")),n.types="index.d.ts",(n.files??[]).length>0&&n.files.indexOf("index.d.ts")<0&&n.files.push("index.d.ts")):(a=path_1.default.join(e,"src/dist/index.d.ts"),(0,fs_1.existsSync)(a)?((0,fs_1.copyFileSync)(a,path_1.default.join(s,"dist/index.d.ts")),n.types="dist/index.d.ts",(n.files??[]).length>0&&n.files.indexOf("dist")<0&&n.files.push("dist")):(0,fs_1.existsSync)(path_1.default.join(e,"package/index.d.ts"))?(n.types="index.d.ts",(n.files??[]).length>0&&n.files.indexOf("index.d.ts")<0&&n.files.push("index.d.ts")):(0,fs_1.existsSync)(path_1.default.join(e,"package/dist/index.d.ts"))&&(n.types="dist/index.d.ts",(n.files??[]).length>0&&n.files.indexOf("dist")<0&&n.files.push("dist"))),(0,fs_1.existsSync)(s)||(0,fs_1.mkdirSync)(s,{recursive:!0}),(0,fs_1.writeFileSync)(i,JSON.stringify((0,utils_1.sortPackageJsonProps)(n),null,2)),(0,fs_1.writeFileSync)(path_1.default.join(s,"package.json"),JSON.stringify((0,utils_1.sortPackageJsonProps)(n),null,2));const d=path_1.default.join(e,"CREDIT");(0,fs_1.existsSync)(d)&&(0,fs_1.copyFileSync)(d,path_1.default.join(s,"CREDIT"));const f=path_1.default.join(e,"LICENSE");(0,fs_1.existsSync)(f)&&(0,fs_1.copyFileSync)(f,path_1.default.join(s,"LICENSE"));const l=path_1.default.join(e,"README.md");(0,fs_1.existsSync)(l)&&(0,fs_1.copyFileSync)(l,path_1.default.join(s,"README.md"))};exports.default=packNpmPackage;