From 03910ea06d21cc9d72ee573ae59bb8adbf56aae4 Mon Sep 17 00:00:00 2001 From: to1source-me Date: Wed, 19 May 2021 23:31:39 +0800 Subject: [PATCH 1/9] Add copyProps method --- package.json | 3 ++- src/main.ts | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2049ebf..8dda850 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "files": [ "index.js", - "dist" + "dist", + "tsconfig.json" ], "scripts": { "test": "ava", diff --git a/src/main.ts b/src/main.ts index 290c60f..639f43c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -49,6 +49,26 @@ export function changeAndGetPkg(where: string): any { return fsx.readJsonSync(pkgFile) } } - // just for f**king around with Typescript + // just for f**king around with Typescript throw new CustomError(new TypeError(`${where} does not exist`)) } + +/** + * copy over the properties + * @param {object} pkg + * @return {object} + */ +export function copyProps(pkg: any): any { + const myPkg = fsx.readJsonSync(join(__dirname, PKG_FILE)) + // first merge the devDependencies + pkg.devDependencies = Object.assign(pkg.devDependencies, myPkg.devDependencies) + // next add the ava options + pkg.ava = myPkg.ava + // finally add some of the scripts + const keys = ["tests", "lint", "build", "clean", "ts-node", "docs"] + pkg.scripts = keys.reduce((obj: any, key: string) => ( + Object.assign(obj, {[key]: myPkg.scripts[key]}) + ), pkg.scripts) + + return pkg +} -- Gitee From 91aeba1463929aa81b87aed46896be88425bfe70 Mon Sep 17 00:00:00 2001 From: to1source-me Date: Thu, 20 May 2021 09:00:51 +0800 Subject: [PATCH 2/9] add package-tpl.json for final test fixtures --- tests/fixtures/package-tpl.json | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/fixtures/package-tpl.json diff --git a/tests/fixtures/package-tpl.json b/tests/fixtures/package-tpl.json new file mode 100644 index 0000000..5eef989 --- /dev/null +++ b/tests/fixtures/package-tpl.json @@ -0,0 +1,32 @@ +{ + "name": "create-tsdev", + "version": "0.0.1", + "description": "Using npx to generate a TS dev env", + "main": "index.js", + "files": [ + "index.js", + "dist", + "tsconfig.json" + ], + "scripts": { + "hello": "echo \"hello\"" + }, + "repository": { + "type": "git", + "url": "git@gitee.com:NEWBRAN/create-tsdev.git" + }, + "keywords": [ + "Node", + "TS", + "Typescript", + "ava.js" + ], + "author": "Joel Chu ", + "license": "MIT", + "bin": { + "create-tsdev": "./index.js" + }, + "dependencies": { + "fs-extra": "^10.0.0" + } +} -- Gitee From 9596b32109f74b0884b27a1d569546731a2c1451 Mon Sep 17 00:00:00 2001 From: to1source-me Date: Thu, 20 May 2021 09:17:52 +0800 Subject: [PATCH 3/9] add clean.js some weird problem that can not call forEach on an Array --- clean.js | 9 +++++++++ dist/main.d.ts | 10 ---------- dist/main.js | 29 ----------------------------- dist/main.js.map | 1 - package.json | 2 +- tests/main.test.ts | 29 ++++++++++++++++++++++++++--- 6 files changed, 36 insertions(+), 44 deletions(-) create mode 100644 clean.js delete mode 100644 dist/main.d.ts delete mode 100644 dist/main.js delete mode 100644 dist/main.js.map diff --git a/clean.js b/clean.js new file mode 100644 index 0000000..07e21db --- /dev/null +++ b/clean.js @@ -0,0 +1,9 @@ +// use fs-extra to clean folder instead of command line makes it cross platform + +const fsx = require('fs-extra') +const { join } = require('path') +const dirs = ['dist', 'build'] + +dirs.forEach(dir => { + fsx.removeSync(join(__dirname, dir)) +}) diff --git a/dist/main.d.ts b/dist/main.d.ts deleted file mode 100644 index 35eb8ed..0000000 --- a/dist/main.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -declare type configObj = { - to?: String; - skipInstall?: Boolean; -}; -/** - * @param {array} arg -- process.argv - * @return {promise} resolve nothing - */ -export declare function processArg(argv: Array): Promise; -export {}; diff --git a/dist/main.js b/dist/main.js deleted file mode 100644 index 38ba8c5..0000000 --- a/dist/main.js +++ /dev/null @@ -1,29 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.processArg = void 0; -const tslib_1 = require("tslib"); -/** - * @param {array} arg -- process.argv - * @return {promise} resolve nothing - */ -function processArg(argv) { - return tslib_1.__awaiter(this, void 0, void 0, function* () { - return Promise.resolve(argv.slice(2)) - .then(args => { - return args.reduce((a, arg) => { - if (a.to !== undefined) { - a.to = arg; - } - else if (arg.toLowerCase() === '--to') { - a.to = ''; // placeholder - } - else if (arg === '--skipInstall') { - a.skipInstall = true; - } - return a; - }, {}); - }); - }); -} -exports.processArg = processArg; -//# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/dist/main.js.map b/dist/main.js.map deleted file mode 100644 index ddca386..0000000 --- a/dist/main.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;AAOA;;;GAGG;AACH,SAAsB,UAAU,CAAC,IAAmB;;QAClD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aAClC,IAAI,CAAC,IAAI,CAAC,EAAE;YACX,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAY,EAAE,GAAW,EAAE,EAAE;gBAC/C,IAAI,CAAC,CAAC,EAAE,KAAK,SAAS,EAAE;oBACtB,CAAC,CAAC,EAAE,GAAG,GAAG,CAAA;iBACX;qBACI,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM,EAAE;oBACrC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAA,CAAC,cAAc;iBACzB;qBACI,IAAI,GAAG,KAAK,eAAe,EAAE;oBAChC,CAAC,CAAC,WAAW,GAAG,IAAI,CAAA;iBACrB;gBACD,OAAO,CAAC,CAAA;YACV,CAAC,EAAE,EAAE,CAAC,CAAA;QACR,CAAC,CAAC,CAAA;IACN,CAAC;CAAA;AAhBD,gCAgBC"} \ No newline at end of file diff --git a/package.json b/package.json index 8dda850..2909a9e 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "cli": "node ./index.js", "lint": "eslint src/ --ext .js,.jsx,.ts,.tsx", "build": "tsc -p tsconfig.json", - "clean": "rm -rf dist build", + "clean": "node ./clean.js", "ts-node": "ts-node", "docs": "typedoc --entryPoints src/main.ts", "build-all": "npm run clean && npm run build && npm run esbuild-node", diff --git a/tests/main.test.ts b/tests/main.test.ts index ab0d0fa..3746ee6 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -1,6 +1,27 @@ // main test file import test from 'ava' -import { processArg, changeAndGetPkg, CustomError } from '../src/main' +import fsx from 'fs-extra' +import { join } from 'path' +import { + processArg, + changeAndGetPkg, + CustomError, + copyProps +} from '../src/main' + + +const fixtures: string = join(__dirname, 'fixtures') +const pkgTpl: string = join(fixtures, 'package-tpl.json') +const dest: string = join(fixtures, 'package.json' ) + +test.before(() => { + fsx.copySync(pkgTpl, dest) +}) + +test.after(() => { + fsx.remove(dest) +}) + test(`Expect to able to get the right properties`, async t => { const p = '/home/joel/Projects/create-t1sts' @@ -12,9 +33,11 @@ test(`Expect to able to get the right properties`, async t => { test(`Expect to fail if there is no package.json`, t => { const myTestFunc = () => changeAndGetPkg("/path/to/no/where") - + const err = t.throws(myTestFunc) t.is(err.parent.name, 'TypeError') }) -test.todo(`Expect to copy over the necessary properties to the package.json`) +test(`Expect to copy over the necessary properties to the package.json` t => { + +}) -- Gitee From f98a7ddc82ed27838430532245d4700d6375bccf Mon Sep 17 00:00:00 2001 From: to1source-me Date: Thu, 20 May 2021 09:36:22 +0800 Subject: [PATCH 4/9] All test passed --- dist/custom-error.d.ts | 4 ++ dist/custom-error.js | 11 +++++ dist/custom-error.js.map | 1 + dist/main.d.ts | 23 +++++++++++ dist/main.js | 72 +++++++++++++++++++++++++++++++++ dist/main.js.map | 1 + src/main.ts | 14 ++++--- tests/fixtures/package-tpl.json | 15 +------ tests/main.test.ts | 16 +++++--- 9 files changed, 132 insertions(+), 25 deletions(-) create mode 100644 dist/custom-error.d.ts create mode 100644 dist/custom-error.js create mode 100644 dist/custom-error.js.map create mode 100644 dist/main.d.ts create mode 100644 dist/main.js create mode 100644 dist/main.js.map diff --git a/dist/custom-error.d.ts b/dist/custom-error.d.ts new file mode 100644 index 0000000..92cba5d --- /dev/null +++ b/dist/custom-error.d.ts @@ -0,0 +1,4 @@ +export declare class CustomError extends Error { + parent: Error; + constructor(parent: any); +} diff --git a/dist/custom-error.js b/dist/custom-error.js new file mode 100644 index 0000000..82e8c62 --- /dev/null +++ b/dist/custom-error.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CustomError = void 0; +class CustomError extends Error { + constructor(parent) { + super(parent.message); + this.parent = parent; + } +} +exports.CustomError = CustomError; +//# sourceMappingURL=custom-error.js.map \ No newline at end of file diff --git a/dist/custom-error.js.map b/dist/custom-error.js.map new file mode 100644 index 0000000..6489aaf --- /dev/null +++ b/dist/custom-error.js.map @@ -0,0 +1 @@ +{"version":3,"file":"custom-error.js","sourceRoot":"","sources":["../src/custom-error.ts"],"names":[],"mappings":";;;AACA,MAAa,WAAY,SAAQ,KAAK;IAGrC,YAAY,MAAW;QACtB,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACrB,CAAC;CACD;AAPD,kCAOC"} \ No newline at end of file diff --git a/dist/main.d.ts b/dist/main.d.ts new file mode 100644 index 0000000..57466d4 --- /dev/null +++ b/dist/main.d.ts @@ -0,0 +1,23 @@ +import { CustomError } from './custom-error'; +declare type configObj = { + to?: String; + skipInstall?: Boolean; +}; +export { CustomError }; +/** + * @param {array} arg -- process.argv + * @return {promise} resolve nothing + */ +export declare function processArg(argv: Array): Promise; +/** + * pass the `to` prop and switch over to that directory + * @param {string} where to + * @return {*} + */ +export declare function changeAndGetPkg(where: string): any; +/** + * copy over the properties + * @param {object} pkg + * @return {object} + */ +export declare function copyProps(pkg: any): any; diff --git a/dist/main.js b/dist/main.js new file mode 100644 index 0000000..5bf653b --- /dev/null +++ b/dist/main.js @@ -0,0 +1,72 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.copyProps = exports.changeAndGetPkg = exports.processArg = exports.CustomError = void 0; +const tslib_1 = require("tslib"); +// main.ts +const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); +const path_1 = require("path"); +const custom_error_1 = require("./custom-error"); +Object.defineProperty(exports, "CustomError", { enumerable: true, get: function () { return custom_error_1.CustomError; } }); +const PKG_FILE = 'package.json'; +/** + * @param {array} arg -- process.argv + * @return {promise} resolve nothing + */ +function processArg(argv) { + return tslib_1.__awaiter(this, void 0, void 0, function* () { + return Promise.resolve(argv.slice(2)) + .then(args => { + return args.reduce((a, arg) => { + if (a.to !== undefined) { + a.to = arg; + } + else if (arg.toLowerCase() === '--to') { + a.to = ''; // placeholder + } + else if (arg === '--skipInstall') { + a.skipInstall = true; + } + return a; + }, {}); + }); + }); +} +exports.processArg = processArg; +/** + * pass the `to` prop and switch over to that directory + * @param {string} where to + * @return {*} + */ +function changeAndGetPkg(where) { + if (fs_extra_1.default.existsSync(where)) { + process.chdir(where); + const dir = process.cwd(); + const pkgFile = path_1.join(dir, PKG_FILE); + if (fs_extra_1.default.existsSync(pkgFile)) { + return fs_extra_1.default.readJsonSync(pkgFile); + } + } + // just for f**king around with Typescript + throw new custom_error_1.CustomError(new TypeError(`${where} does not exist`)); +} +exports.changeAndGetPkg = changeAndGetPkg; +/** + * copy over the properties + * @param {object} pkg + * @return {object} + */ +function copyProps(pkg) { + const pathToPkg = path_1.resolve(__dirname, '..', PKG_FILE); + const myPkg = fs_extra_1.default.readJsonSync(pathToPkg); + // first merge the devDependencies + pkg.devDependencies = Object.assign(pkg.devDependencies || {}, myPkg.devDependencies); + // next add the ava options + pkg.ava = myPkg.ava; + // finally add some of the scripts + const keys = ["test", "lint", "build", "clean", "ts-node", "docs"]; + pkg.scripts = keys.reduce((obj, key) => (Object.assign(obj, { [key]: myPkg.scripts[key] })), pkg.scripts || {}); + pkg.dependencies = Object.assign(pkg.dependencies || {}, myPkg.dependencies); + return pkg; +} +exports.copyProps = copyProps; +//# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/dist/main.js.map b/dist/main.js.map new file mode 100644 index 0000000..46591dc --- /dev/null +++ b/dist/main.js.map @@ -0,0 +1 @@ +{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;AAAA,UAAU;AACV,gEAA0B;AAC1B,+BAAoC;AACpC,iDAA4C;AAUnC,4FAVA,0BAAW,OAUA;AAHpB,MAAM,QAAQ,GAAW,cAAc,CAAA;AAKvC;;;GAGG;AACH,SAAsB,UAAU,CAAC,IAAmB;;QAClD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aAClC,IAAI,CAAC,IAAI,CAAC,EAAE;YACX,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAY,EAAE,GAAW,EAAE,EAAE;gBAC/C,IAAI,CAAC,CAAC,EAAE,KAAK,SAAS,EAAE;oBACtB,CAAC,CAAC,EAAE,GAAG,GAAG,CAAA;iBACX;qBACI,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM,EAAE;oBACrC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAA,CAAC,cAAc;iBACzB;qBACI,IAAI,GAAG,KAAK,eAAe,EAAE;oBAChC,CAAC,CAAC,WAAW,GAAG,IAAI,CAAA;iBACrB;gBACD,OAAO,CAAC,CAAA;YACV,CAAC,EAAE,EAAE,CAAC,CAAA;QACR,CAAC,CAAC,CAAA;IACN,CAAC;CAAA;AAhBD,gCAgBC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,KAAa;IAC3C,IAAI,kBAAG,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QACzB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACpB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;QACzB,MAAM,OAAO,GAAG,WAAI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CAAC;AAfD,8BAeC"} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 639f43c..c04f39e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ // main.ts import fsx from 'fs-extra' -import { join } from 'path' +import { join, resolve } from 'path' import { CustomError } from './custom-error' // the main method @@ -56,19 +56,21 @@ export function changeAndGetPkg(where: string): any { /** * copy over the properties * @param {object} pkg - * @return {object} + * @return {object} */ export function copyProps(pkg: any): any { - const myPkg = fsx.readJsonSync(join(__dirname, PKG_FILE)) + const pathToPkg = resolve(__dirname, '..', PKG_FILE) + const myPkg = fsx.readJsonSync(pathToPkg) // first merge the devDependencies - pkg.devDependencies = Object.assign(pkg.devDependencies, myPkg.devDependencies) + pkg.devDependencies = Object.assign(pkg.devDependencies || {}, myPkg.devDependencies) // next add the ava options pkg.ava = myPkg.ava // finally add some of the scripts - const keys = ["tests", "lint", "build", "clean", "ts-node", "docs"] + const keys = ["test", "lint", "build", "clean", "ts-node", "docs"] pkg.scripts = keys.reduce((obj: any, key: string) => ( Object.assign(obj, {[key]: myPkg.scripts[key]}) - ), pkg.scripts) + ), pkg.scripts || {}) + pkg.dependencies = Object.assign(pkg.dependencies || {}, myPkg.dependencies) return pkg } diff --git a/tests/fixtures/package-tpl.json b/tests/fixtures/package-tpl.json index 5eef989..53350f7 100644 --- a/tests/fixtures/package-tpl.json +++ b/tests/fixtures/package-tpl.json @@ -3,11 +3,6 @@ "version": "0.0.1", "description": "Using npx to generate a TS dev env", "main": "index.js", - "files": [ - "index.js", - "dist", - "tsconfig.json" - ], "scripts": { "hello": "echo \"hello\"" }, @@ -21,12 +16,6 @@ "Typescript", "ava.js" ], - "author": "Joel Chu ", - "license": "MIT", - "bin": { - "create-tsdev": "./index.js" - }, - "dependencies": { - "fs-extra": "^10.0.0" - } + "author": "NOBODY", + "license": "MIT" } diff --git a/tests/main.test.ts b/tests/main.test.ts index 3746ee6..34fa629 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -1,6 +1,6 @@ // main test file import test from 'ava' -import fsx from 'fs-extra' +import { copySync, removeSync, readJsonSync } from 'fs-extra' import { join } from 'path' import { processArg, @@ -15,11 +15,11 @@ const pkgTpl: string = join(fixtures, 'package-tpl.json') const dest: string = join(fixtures, 'package.json' ) test.before(() => { - fsx.copySync(pkgTpl, dest) + copySync(pkgTpl, dest) }) test.after(() => { - fsx.remove(dest) + removeSync(dest) }) @@ -30,7 +30,6 @@ test(`Expect to able to get the right properties`, async t => { t.is(result.to, p) }) - test(`Expect to fail if there is no package.json`, t => { const myTestFunc = () => changeAndGetPkg("/path/to/no/where") @@ -38,6 +37,11 @@ test(`Expect to fail if there is no package.json`, t => { t.is(err.parent.name, 'TypeError') }) -test(`Expect to copy over the necessary properties to the package.json` t => { - +test(`Expect to copy over the necessary properties to the package.json`, t => { + const myPkg = readJsonSync(dest) + const result = copyProps(myPkg) + + t.true(result.dependencies !== undefined) + t.true(result.scripts !== undefined) + t.is(result.scripts.test, "ava") }) -- Gitee From 7e66b194fbc20d63bcd3af7aca3ff131eff6ebb5 Mon Sep 17 00:00:00 2001 From: to1source-me Date: Thu, 20 May 2021 16:17:05 +0800 Subject: [PATCH 5/9] rename the main.ts to lib.ts and create new main.ts as entry point --- src/lib.ts | 76 +++++++++++++++++++++++++++ src/main.ts | 79 +++-------------------------- tests/{main.test.ts => lib.test.ts} | 2 +- 3 files changed, 84 insertions(+), 73 deletions(-) create mode 100644 src/lib.ts rename tests/{main.test.ts => lib.test.ts} (98%) diff --git a/src/lib.ts b/src/lib.ts new file mode 100644 index 0000000..9996e80 --- /dev/null +++ b/src/lib.ts @@ -0,0 +1,76 @@ +// lib.ts libraries of functions +import fsx from 'fs-extra' +import { join, resolve } from 'path' +import { CustomError } from './custom-error' + +// the main method +type configObj = { + to?: String, + skipInstall? : Boolean +} +const PKG_FILE: string = 'package.json' + +// re-export +export { CustomError } + +/** + * @param {array} arg -- process.argv + * @return {promise} resolve nothing + */ +export async function processArg(argv: Array): Promise { + return Promise.resolve(argv.slice(2)) + .then(args => { + return args.reduce((a: configObj, arg: String) => { + if (a.to !== undefined) { + a.to = arg + } + else if (arg.toLowerCase() === '--to') { + a.to = '' // placeholder + } + else if (arg === '--skipInstall') { + a.skipInstall = true + } + return a + }, {}) + }) +} + +/** + * pass the `to` prop and switch over to that directory + * @param {string} where to + * @return {*} + */ +export function changeAndGetPkg(where: string): any { + if (fsx.existsSync(where)) { + process.chdir(where) + const dir = process.cwd() + const pkgFile = join(dir, PKG_FILE) + if (fsx.existsSync(pkgFile)) { + return fsx.readJsonSync(pkgFile) + } + } + // just for f**king around with Typescript + throw new CustomError(new TypeError(`${where} does not exist`)) +} + +/** + * copy over the properties + * @param {object} pkg + * @return {object} + */ +export function copyProps(pkg: any): any { + const pathToPkg = resolve(__dirname, '..', PKG_FILE) + const myPkg = fsx.readJsonSync(pathToPkg) + // first merge the devDependencies + pkg.devDependencies = Object.assign(pkg.devDependencies || {}, myPkg.devDependencies) + // next add the ava options + pkg.ava = myPkg.ava + // finally add some of the scripts + const keys = ["test", "lint", "build", "clean", "ts-node", "docs"] + pkg.scripts = keys.reduce((obj: any, key: string) => ( + Object.assign(obj, {[key]: myPkg.scripts[key]}) + ), pkg.scripts || {}) + pkg.dependencies = Object.assign(pkg.dependencies || {}, myPkg.dependencies) + + return pkg +} diff --git a/src/main.ts b/src/main.ts index c04f39e..0b301fe 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,76 +1,11 @@ -// main.ts -import fsx from 'fs-extra' -import { join, resolve } from 'path' -import { CustomError } from './custom-error' - -// the main method -type configObj = { - to?: String, - skipInstall? : Boolean -} -const PKG_FILE: string = 'package.json' - -// re-export -export { CustomError } - -/** - * @param {array} arg -- process.argv - * @return {promise} resolve nothing - */ -export async function processArg(argv: Array): Promise { - return Promise.resolve(argv.slice(2)) - .then(args => { - return args.reduce((a: configObj, arg: String) => { - if (a.to !== undefined) { - a.to = arg - } - else if (arg.toLowerCase() === '--to') { - a.to = '' // placeholder - } - else if (arg === '--skipInstall') { - a.skipInstall = true - } - return a - }, {}) - }) -} - -/** - * pass the `to` prop and switch over to that directory - * @param {string} where to - * @return {*} - */ -export function changeAndGetPkg(where: string): any { - if (fsx.existsSync(where)) { - process.chdir(where) - const dir = process.cwd() - const pkgFile = join(dir, PKG_FILE) - if (fsx.existsSync(pkgFile)) { - return fsx.readJsonSync(pkgFile) - } - } - // just for f**king around with Typescript - throw new CustomError(new TypeError(`${where} does not exist`)) -} +// just create a top level main function /** - * copy over the properties - * @param {object} pkg - * @return {object} + * Top level API + * @param {args} array from process.argv + * @return {void} + * @public */ -export function copyProps(pkg: any): any { - const pathToPkg = resolve(__dirname, '..', PKG_FILE) - const myPkg = fsx.readJsonSync(pathToPkg) - // first merge the devDependencies - pkg.devDependencies = Object.assign(pkg.devDependencies || {}, myPkg.devDependencies) - // next add the ava options - pkg.ava = myPkg.ava - // finally add some of the scripts - const keys = ["test", "lint", "build", "clean", "ts-node", "docs"] - pkg.scripts = keys.reduce((obj: any, key: string) => ( - Object.assign(obj, {[key]: myPkg.scripts[key]}) - ), pkg.scripts || {}) - pkg.dependencies = Object.assign(pkg.dependencies || {}, myPkg.dependencies) - - return pkg +export function main(args: array) { + } diff --git a/tests/main.test.ts b/tests/lib.test.ts similarity index 98% rename from tests/main.test.ts rename to tests/lib.test.ts index 34fa629..cd095c1 100644 --- a/tests/main.test.ts +++ b/tests/lib.test.ts @@ -7,7 +7,7 @@ import { changeAndGetPkg, CustomError, copyProps -} from '../src/main' +} from '../src/lib' const fixtures: string = join(__dirname, 'fixtures') -- Gitee From a6b5ffcaf4eb83f544bb9655954c1dcb8d01c346 Mon Sep 17 00:00:00 2001 From: to1source-me Date: Thu, 20 May 2021 22:39:26 +0800 Subject: [PATCH 6/9] build and the original test all passed --- dist/lib.d.ts | 36 ++++++++++++++++ dist/lib.js | 110 +++++++++++++++++++++++++++++++++++++++++++++++ dist/lib.js.map | 1 + dist/main.d.ts | 26 +++-------- dist/main.js | 79 ++++++++-------------------------- dist/main.js.map | 2 +- src/lib.ts | 55 ++++++++++++++++++++---- src/main.ts | 23 +++++++++- 8 files changed, 238 insertions(+), 94 deletions(-) create mode 100644 dist/lib.d.ts create mode 100644 dist/lib.js create mode 100644 dist/lib.js.map diff --git a/dist/lib.d.ts b/dist/lib.d.ts new file mode 100644 index 0000000..5b161ed --- /dev/null +++ b/dist/lib.d.ts @@ -0,0 +1,36 @@ +import { CustomError } from './custom-error'; +declare type configObj = { + to?: string; + skipInstall?: boolean; +}; +export { CustomError }; +/** + * @param {array} arg -- process.argv + * @return {promise} resolve nothing + */ +export declare function processArg(argv: Array): Promise; +/** + * pass the `to` prop and switch over to that directory + * @param {string} where to + * @return {array} [ pkgFile, json ] + */ +export declare function changeAndGetPkg(where: string): any; +/** + * copy over the properties + * @param {object} pkg + * @return {object} + */ +export declare function copyProps(pkg: any): any; +/** + * just overwrite the existing package.json + * @param {string} pkgFile path to package.json + * @param {object} pkg content of the json + * @return {promise} not throw error that means success + */ +export declare function overwritePkgJson(pkgFile: string, pkg: any): Promise; +/** + * Execute a npm install if they didn't supply the --noInstall + * @param {object} args from command line + * @return {void} + */ +export declare function runInstall(args: any): void; diff --git a/dist/lib.js b/dist/lib.js new file mode 100644 index 0000000..67eed0f --- /dev/null +++ b/dist/lib.js @@ -0,0 +1,110 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.runInstall = exports.overwritePkgJson = exports.copyProps = exports.changeAndGetPkg = exports.processArg = exports.CustomError = void 0; +const tslib_1 = require("tslib"); +// lib.ts libraries of functions +const path_1 = require("path"); +const child_process_1 = require("child_process"); +const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); +const custom_error_1 = require("./custom-error"); +Object.defineProperty(exports, "CustomError", { enumerable: true, get: function () { return custom_error_1.CustomError; } }); +const PKG_FILE = 'package.json'; +/** + * @param {array} arg -- process.argv + * @return {promise} resolve nothing + */ +function processArg(argv) { + return tslib_1.__awaiter(this, void 0, void 0, function* () { + return Promise.resolve(argv) + .then(args => { + return args.reduce((a, arg) => { + if (a.to !== undefined) { + a.to = arg; + } + else if (arg.toLowerCase() === '--to') { + a.to = ''; // placeholder + } + else if (arg === '--skipInstall') { + a.skipInstall = true; + } + return a; + }, {}); + }); + }); +} +exports.processArg = processArg; +/** + * pass the `to` prop and switch over to that directory + * @param {string} where to + * @return {array} [ pkgFile, json ] + */ +function changeAndGetPkg(where) { + if (fs_extra_1.default.existsSync(where)) { + process.chdir(where); + const dir = process.cwd(); + const pkgFile = path_1.join(dir, PKG_FILE); + if (fs_extra_1.default.existsSync(pkgFile)) { + // return a tuple instead + return [ + pkgFile, + fs_extra_1.default.readJsonSync(pkgFile) + ]; + } + } + // just for f**king around with Typescript + throw new custom_error_1.CustomError(new TypeError(`${where} does not exist`)); +} +exports.changeAndGetPkg = changeAndGetPkg; +/** + * copy over the properties + * @param {object} pkg + * @return {object} + */ +function copyProps(pkg) { + const pathToPkg = path_1.resolve(__dirname, '..', PKG_FILE); + const myPkg = fs_extra_1.default.readJsonSync(pathToPkg); + // first merge the devDependencies + pkg.devDependencies = Object.assign(pkg.devDependencies || {}, myPkg.devDependencies); + // next add the ava options + pkg.ava = myPkg.ava; + // finally add some of the scripts + const keys = ["test", "lint", "build", "clean", "ts-node", "docs"]; + pkg.scripts = keys.reduce((obj, key) => (Object.assign(obj, { [key]: myPkg.scripts[key] })), pkg.scripts || {}); + pkg.dependencies = Object.assign(pkg.dependencies || {}, myPkg.dependencies); + return pkg; +} +exports.copyProps = copyProps; +/** + * just overwrite the existing package.json + * @param {string} pkgFile path to package.json + * @param {object} pkg content of the json + * @return {promise} not throw error that means success + */ +function overwritePkgJson(pkgFile, pkg) { + return fs_extra_1.default.writeJson(pkgFile, pkg); +} +exports.overwritePkgJson = overwritePkgJson; +/** + * Execute a npm install if they didn't supply the --noInstall + * @param {object} args from command line + * @return {void} + */ +function runInstall(args) { + if (args.skipInstall !== true) { + child_process_1.exec("npm install", { cwd: process.cwd() }, (error, stdout, stderr) => { + if (error) { + console.error(`ERROR:`, error); + return; + } + console.log(`stdout`, stdout); + if (stderr) { + console.error(`stderr`, stderr); + } + }); + } + else { + console.log(`All done nothing to do`); + } +} +exports.runInstall = runInstall; +//# sourceMappingURL=lib.js.map \ No newline at end of file diff --git a/dist/lib.js.map b/dist/lib.js.map new file mode 100644 index 0000000..0eb1245 --- /dev/null +++ b/dist/lib.js.map @@ -0,0 +1 @@ +{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":";;;;AAAA,gCAAgC;AAChC,+BAAoC;AACpC,iDAAoC;AACpC,gEAA0B;AAC1B,iDAA4C;AAUnC,4FAVA,0BAAW,OAUA;AAHpB,MAAM,QAAQ,GAAW,cAAc,CAAA;AAKvC;;;GAGG;AACH,SAAsB,UAAU,CAAC,IAAmB;;QAClD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;aACzB,IAAI,CAAC,IAAI,CAAC,EAAE;YACX,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAY,EAAE,GAAW,EAAE,EAAE;gBAC/C,IAAI,CAAC,CAAC,EAAE,KAAK,SAAS,EAAE;oBACtB,CAAC,CAAC,EAAE,GAAG,GAAG,CAAA;iBACX;qBACI,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM,EAAE;oBACrC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAA,CAAC,cAAc;iBACzB;qBACI,IAAI,GAAG,KAAK,eAAe,EAAE;oBAChC,CAAC,CAAC,WAAW,GAAG,IAAI,CAAA;iBACrB;gBACD,OAAO,CAAC,CAAA;YACV,CAAC,EAAE,EAAE,CAAC,CAAA;QACR,CAAC,CAAC,CAAA;IACN,CAAC;CAAA;AAhBD,gCAgBC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,KAAa;IAC3C,IAAI,kBAAG,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QACzB,OAAO,CAAC,KAAK,CAAC,KAAK,C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AAY,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAE5E,OAAO,GAAG,CAAA;AACZ,CAAC;AAfD,8BAeC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,OAAe,EAAE,GAAQ;IACxD,OAAO,kBAAG,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AACpC,CAAC;AAFD,4CAEC;AAED;;;;GAIG;AACH,SAAgB,UAAU,CAAC,IAAS;IAClC,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,EAAE;QAC7B,oBAAI,CAAC,aAAa,EACb,EAAC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAC,EACtB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YACxB,IAAI,KAAK,EAAE;gBACT,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;gBAC9B,OAAM;aACP;YACD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;YAC7B,IAAI,MAAM,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;aAChC;QACH,CAAC,CAAC,CAAA;KACN;SAAM;QACL,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;KACtC;AACH,CAAC;AAjBD,gCAiBC"} \ No newline at end of file diff --git a/dist/main.d.ts b/dist/main.d.ts index 57466d4..62bc95c 100644 --- a/dist/main.d.ts +++ b/dist/main.d.ts @@ -1,23 +1,7 @@ -import { CustomError } from './custom-error'; -declare type configObj = { - to?: String; - skipInstall?: Boolean; -}; -export { CustomError }; /** - * @param {array} arg -- process.argv - * @return {promise} resolve nothing + * Top level API + * @param {args} array from process.argv + * @return {void} + * @public */ -export declare function processArg(argv: Array): Promise; -/** - * pass the `to` prop and switch over to that directory - * @param {string} where to - * @return {*} - */ -export declare function changeAndGetPkg(where: string): any; -/** - * copy over the properties - * @param {object} pkg - * @return {object} - */ -export declare function copyProps(pkg: any): any; +export declare function main(): Promise; diff --git a/dist/main.js b/dist/main.js index 5bf653b..94b0a7a 100644 --- a/dist/main.js +++ b/dist/main.js @@ -1,72 +1,27 @@ "use strict"; +// just create a top level main function Object.defineProperty(exports, "__esModule", { value: true }); -exports.copyProps = exports.changeAndGetPkg = exports.processArg = exports.CustomError = void 0; +exports.main = void 0; const tslib_1 = require("tslib"); -// main.ts -const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); -const path_1 = require("path"); -const custom_error_1 = require("./custom-error"); -Object.defineProperty(exports, "CustomError", { enumerable: true, get: function () { return custom_error_1.CustomError; } }); -const PKG_FILE = 'package.json'; +const lib_1 = require("./lib"); /** - * @param {array} arg -- process.argv - * @return {promise} resolve nothing + * Top level API + * @param {args} array from process.argv + * @return {void} + * @public */ -function processArg(argv) { +function main() { return tslib_1.__awaiter(this, void 0, void 0, function* () { - return Promise.resolve(argv.slice(2)) + // there is no point of accepting input anyway + return lib_1.processArg(process.argv.slice(2)) .then(args => { - return args.reduce((a, arg) => { - if (a.to !== undefined) { - a.to = arg; - } - else if (arg.toLowerCase() === '--to') { - a.to = ''; // placeholder - } - else if (arg === '--skipInstall') { - a.skipInstall = true; - } - return a; - }, {}); - }); + const [pkgFile, _pkg] = lib_1.changeAndGetPkg(args.to || process.cwd()); + const pkg = lib_1.copyProps(_pkg); + return { args, pkg, pkgFile }; + }) + .then(({ args, pkg, pkgFile }) => (lib_1.overwritePkgJson(pkgFile, pkg) + .then(() => lib_1.runInstall(args)))); }); } -exports.processArg = processArg; -/** - * pass the `to` prop and switch over to that directory - * @param {string} where to - * @return {*} - */ -function changeAndGetPkg(where) { - if (fs_extra_1.default.existsSync(where)) { - process.chdir(where); - const dir = process.cwd(); - const pkgFile = path_1.join(dir, PKG_FILE); - if (fs_extra_1.default.existsSync(pkgFile)) { - return fs_extra_1.default.readJsonSync(pkgFile); - } - } - // just for f**king around with Typescript - throw new custom_error_1.CustomError(new TypeError(`${where} does not exist`)); -} -exports.changeAndGetPkg = changeAndGetPkg; -/** - * copy over the properties - * @param {object} pkg - * @return {object} - */ -function copyProps(pkg) { - const pathToPkg = path_1.resolve(__dirname, '..', PKG_FILE); - const myPkg = fs_extra_1.default.readJsonSync(pathToPkg); - // first merge the devDependencies - pkg.devDependencies = Object.assign(pkg.devDependencies || {}, myPkg.devDependencies); - // next add the ava options - pkg.ava = myPkg.ava; - // finally add some of the scripts - const keys = ["test", "lint", "build", "clean", "ts-node", "docs"]; - pkg.scripts = keys.reduce((obj, key) => (Object.assign(obj, { [key]: myPkg.scripts[key] })), pkg.scripts || {}); - pkg.dependencies = Object.assign(pkg.dependencies || {}, myPkg.dependencies); - return pkg; -} -exports.copyProps = copyProps; +exports.main = main; //# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/dist/main.js.map b/dist/main.js.map index 46591dc..462933d 100644 --- a/dist/main.js.map +++ b/dist/main.js.map @@ -1 +1 @@ -{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;AAAA,UAAU;AACV,gEAA0B;AAC1B,+BAAoC;AACpC,iDAA4C;AAUnC,4FAVA,0BAAW,OAUA;AAHpB,MAAM,QAAQ,GAAW,cAAc,CAAA;AAKvC;;;GAGG;AACH,SAAsB,UAAU,CAAC,IAAmB;;QAClD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aAClC,IAAI,CAAC,IAAI,CAAC,EAAE;YACX,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAY,EAAE,GAAW,EAAE,EAAE;gBAC/C,IAAI,CAAC,CAAC,EAAE,KAAK,SAAS,EAAE;oBACtB,CAAC,CAAC,EAAE,GAAG,GAAG,CAAA;iBACX;qBACI,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM,EAAE;oBACrC,CAAC,CAAC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A;IACN,CAAC;CAAA;AAbD,oBAaC"} \ No newline at end of file diff --git a/src/lib.ts b/src/lib.ts index 9996e80..8e13652 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1,12 +1,13 @@ // lib.ts libraries of functions -import fsx from 'fs-extra' import { join, resolve } from 'path' +import { exec } from 'child_process' +import fsx from 'fs-extra' import { CustomError } from './custom-error' // the main method type configObj = { - to?: String, - skipInstall? : Boolean + to?: string, + skipInstall? : boolean } const PKG_FILE: string = 'package.json' @@ -17,10 +18,10 @@ export { CustomError } * @param {array} arg -- process.argv * @return {promise} resolve nothing */ -export async function processArg(argv: Array): Promise { - return Promise.resolve(argv.slice(2)) +export async function processArg(argv: Array): Promise { + return Promise.resolve(argv) .then(args => { - return args.reduce((a: configObj, arg: String) => { + return args.reduce((a: configObj, arg: string) => { if (a.to !== undefined) { a.to = arg } @@ -38,7 +39,7 @@ export async function processArg(argv: Array): Promise { /** * pass the `to` prop and switch over to that directory * @param {string} where to - * @return {*} + * @return {array} [ pkgFile, json ] */ export function changeAndGetPkg(where: string): any { if (fsx.existsSync(where)) { @@ -46,7 +47,11 @@ export function changeAndGetPkg(where: string): any { const dir = process.cwd() const pkgFile = join(dir, PKG_FILE) if (fsx.existsSync(pkgFile)) { - return fsx.readJsonSync(pkgFile) + // return a tuple instead + return [ + pkgFile, + fsx.readJsonSync(pkgFile) + ] } } // just for f**king around with Typescript @@ -74,3 +79,37 @@ export function copyProps(pkg: any): any { return pkg } + +/** + * just overwrite the existing package.json + * @param {string} pkgFile path to package.json + * @param {object} pkg content of the json + * @return {promise} not throw error that means success + */ +export function overwritePkgJson(pkgFile: string, pkg: any): Promise { + return fsx.writeJson(pkgFile, pkg) +} + +/** + * Execute a npm install if they didn't supply the --noInstall + * @param {object} args from command line + * @return {void} + */ +export function runInstall(args: any) { + if (args.skipInstall !== true) { + exec("npm install", + {cwd: process.cwd()}, + (error, stdout, stderr) => { + if (error) { + console.error(`ERROR:`, error) + return + } + console.log(`stdout`, stdout) + if (stderr) { + console.error(`stderr`, stderr) + } + }) + } else { + console.log(`All done nothing to do`) + } +} diff --git a/src/main.ts b/src/main.ts index 0b301fe..bc497f6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,11 +1,30 @@ // just create a top level main function +import { + processArg, + changeAndGetPkg, + copyProps, + overwritePkgJson, + runInstall +} from './lib' + /** * Top level API * @param {args} array from process.argv * @return {void} * @public */ -export function main(args: array) { - +export async function main() { + // there is no point of accepting input anyway + return processArg(process.argv.slice(2)) + .then(args => { + const [ pkgFile, _pkg ] = changeAndGetPkg(args.to || process.cwd()) + const pkg = copyProps(_pkg) + + return { args, pkg, pkgFile } + }) + .then(({ args, pkg, pkgFile }) => ( + overwritePkgJson(pkgFile, pkg) + .then(() => runInstall(args)) + )) } -- Gitee From 713683a69c7ff4e50e74e4a134c86edbb11ad97e Mon Sep 17 00:00:00 2001 From: to1source-me Date: Thu, 20 May 2021 22:52:42 +0800 Subject: [PATCH 7/9] working on the final test --- index.js | 25 ++----------------------- src/lib.ts | 40 ++++++++++++++++++++++------------------ src/main.ts | 6 +++--- tests/main.test.ts | 9 +++++++++ 4 files changed, 36 insertions(+), 44 deletions(-) create mode 100644 tests/main.test.ts diff --git a/index.js b/index.js index a75cc9d..0653195 100644 --- a/index.js +++ b/index.js @@ -1,26 +1,5 @@ #!/usr/bin/env node // this is just the entry point where it gets call -const { processArg } = require('./dist/main.js') -const fsx = require('fs-extra') -const { join } = require('path') +const { main } = require('./dist/main.js') -processArg(process.argv) - .then(config => { - console.log(`Hello LOL`, config) - - // little test - if (config.to && fsx.existsSync(config.to)) { - process.chdir(config.to) - - const dir = process.cwd() - - console.log(dir) - - const pkgFile = join(dir, 'package.json') - console.log(pkgFile) - const pkg = fsx.readJsonSync(pkgFile) - console.log(pkg.name, pkg.version) - } - - - }) +main(process.argv.slice(2)) diff --git a/src/lib.ts b/src/lib.ts index 8e13652..07ed9a6 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -93,23 +93,27 @@ export function overwritePkgJson(pkgFile: string, pkg: any): Promise { /** * Execute a npm install if they didn't supply the --noInstall * @param {object} args from command line - * @return {void} + * @return {promise} */ -export function runInstall(args: any) { - if (args.skipInstall !== true) { - exec("npm install", - {cwd: process.cwd()}, - (error, stdout, stderr) => { - if (error) { - console.error(`ERROR:`, error) - return - } - console.log(`stdout`, stdout) - if (stderr) { - console.error(`stderr`, stderr) - } - }) - } else { - console.log(`All done nothing to do`) - } +export function runInstall(args: any): Promise { + return new Promise((resolver, rejecter) => { + if (args.skipInstall !== true) { + exec("npm install", + {cwd: process.cwd()}, + (error, stdout, stderr) => { + if (error) { + console.error(`ERROR:`, error) + return rejecter(false) + } + console.log(`stdout`, stdout) + if (stderr) { + console.error(`stderr`, stderr) + } + resolver(true) + }) + } else { + console.log(`All done nothing to do`) + resolver(true) + } + }) } diff --git a/src/main.ts b/src/main.ts index bc497f6..61b017f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,13 +10,13 @@ import { /** * Top level API - * @param {args} array from process.argv + * @param {Array} _args from process.argv * @return {void} * @public */ -export async function main() { +export async function main(_args: Array) { // there is no point of accepting input anyway - return processArg(process.argv.slice(2)) + return processArg(_args) .then(args => { const [ pkgFile, _pkg ] = changeAndGetPkg(args.to || process.cwd()) const pkg = copyProps(_pkg) diff --git a/tests/main.test.ts b/tests/main.test.ts new file mode 100644 index 0000000..9eefd7c --- /dev/null +++ b/tests/main.test.ts @@ -0,0 +1,9 @@ +import test from 'ava' +import { main } from '../src/main' + + + +test(`End to end test`, async t => { + const res = await main() + +}) -- Gitee From f43ac34f630d89b664b9c5aaabcf5bb5a60aab3e Mon Sep 17 00:00:00 2001 From: to1source-me Date: Thu, 20 May 2021 23:17:00 +0800 Subject: [PATCH 8/9] test passed --- README.md | 17 ++++++++++++++++- src/lib.ts | 2 +- tests/main.test.ts | 25 +++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8288703..7fa2036 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # create-tsdev -> Using npx to generate a TS dev env. +> Using npx to generate a latest (2021) Typescript development environment for node.js side + +This setup is using [esbuild](https://esbuild.github.io/getting-started/) (claim to be 3 times faster than webpack / babel) and [ava.js](https://github.com/avajs/) a real modern testing suite for node.js (My options ava.js is way way way better than this [joker](https://jestjs.io)) ## Installation @@ -20,6 +22,19 @@ Please note you need to init your project before you can use this tool. By default it will init the TS dev env inside your project root. Or you can pass `--to /where/your/project/root`. So it will switch over to that folder. +You can also pass `--skipInstall` so it won't run the `npm install` in the end. + +## Credits + +The idea is based on this [blog post](https://www.metachris.com/2021/04/starting-a-typescript-project-in-2021/#:~:text=In%20tsconfig.json%2C%20add%20DOM%20to%20the%20list%20of,can%20attach%20custom%20properties%20to%20window%20like%20this%3A) + +## TODOS + +- Add options to add github / gitlab CI actions +- Option to setup postCSS and browser env +- for ava.js, work out a way to use esbuild instead of `node-ts/register` (just like using `esm`) + + --- Joel Chu (c) 2021 diff --git a/src/lib.ts b/src/lib.ts index 07ed9a6..08e3535 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -97,7 +97,7 @@ export function overwritePkgJson(pkgFile: string, pkg: any): Promise { */ export function runInstall(args: any): Promise { return new Promise((resolver, rejecter) => { - if (args.skipInstall !== true) { + if (args.skipInstall !== true && process.env.NODE_ENV !== 'test') { exec("npm install", {cwd: process.cwd()}, (error, stdout, stderr) => { diff --git a/tests/main.test.ts b/tests/main.test.ts index 9eefd7c..da2539d 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -1,9 +1,30 @@ import test from 'ava' +import { removeSync, copySync, existsSync, readJsonSync } from 'fs-extra' +import { join } from 'path' + import { main } from '../src/main' +const from = join(__dirname, 'fixtures', 'package-tpl.json') +const to = join(__dirname, 'tmp') +const pkgFile = join(to, 'package.json') + +test.before(() => { + copySync(from , pkgFile) +}) + +test.after(() => { + removeSync(to) +}) test(`End to end test`, async t => { - const res = await main() - + const res = await main(['--to', to]) + t.true(res) + t.true(existsSync(pkgFile)) + + const pkg = readJsonSync(pkgFile) + + t.true(pkg.dependencies !== undefined) + t.true(pkg.scripts !== undefined) + t.is(pkg.scripts.test, "ava") }) -- Gitee From 114c3a4f897a1be8f0b99f06993f924717f79254 Mon Sep 17 00:00:00 2001 From: to1source-me Date: Thu, 20 May 2021 23:17:36 +0800 Subject: [PATCH 9/9] 0.1.0 build --- dist/lib.d.ts | 4 ++-- dist/lib.js | 36 ++++++++++++++++++++---------------- dist/lib.js.map | 2 +- dist/main.d.ts | 4 ++-- dist/main.js | 6 +++--- dist/main.js.map | 2 +- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/dist/lib.d.ts b/dist/lib.d.ts index 5b161ed..c849675 100644 --- a/dist/lib.d.ts +++ b/dist/lib.d.ts @@ -31,6 +31,6 @@ export declare function overwritePkgJson(pkgFile: string, pkg: any): Promise; diff --git a/dist/lib.js b/dist/lib.js index 67eed0f..5ef06a5 100644 --- a/dist/lib.js +++ b/dist/lib.js @@ -87,24 +87,28 @@ exports.overwritePkgJson = overwritePkgJson; /** * Execute a npm install if they didn't supply the --noInstall * @param {object} args from command line - * @return {void} + * @return {promise} */ function runInstall(args) { - if (args.skipInstall !== true) { - child_process_1.exec("npm install", { cwd: process.cwd() }, (error, stdout, stderr) => { - if (error) { - console.error(`ERROR:`, error); - return; - } - console.log(`stdout`, stdout); - if (stderr) { - console.error(`stderr`, stderr); - } - }); - } - else { - console.log(`All done nothing to do`); - } + return new Promise((resolver, rejecter) => { + if (args.skipInstall !== true && process.env.NODE_ENV !== 'test') { + child_process_1.exec("npm install", { cwd: process.cwd() }, (error, stdout, stderr) => { + if (error) { + console.error(`ERROR:`, error); + return rejecter(false); + } + console.log(`stdout`, stdout); + if (stderr) { + console.error(`stderr`, stderr); + } + resolver(true); + }); + } + else { + console.log(`All done nothing to do`); + resolver(true); + } + }); } exports.runInstall = runInstall; //# sourceMappingURL=lib.js.map \ No newline at end of file diff --git a/dist/lib.js.map b/dist/lib.js.map index 0eb1245..ff8fea7 100644 --- a/dist/lib.js.map +++ b/dist/lib.js.map @@ -1 +1 @@ -{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":";;;;AAAA,gCAAgC;AAChC,+BAAoC;AACpC,iDAAoC;AACpC,gEAA0B;AAC1B,iDAA4C;AAUnC,4FAVA,0BAAW,OAUA;AAHpB,MAAM,QAAQ,GAAW,cAAc,CAAA;AAKvC;;;GAGG;AACH,SAAsB,UAAU,CAAC,IAAmB;;QAClD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;aACzB,IAAI,CAAC,IAAI,CAAC,EAAE;YACX,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAY,EAAE,GAAW,EAAE,EAAE;gBAC/C,IAAI,CAAC,CAAC,EAAE,KAAK,SAAS,EAAE;oBACtB,CAAC,CAAC,EAAE,GAAG,GAAG,CAAA;iBACX;qBACI,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM,EAAE;oBACrC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAA,CAAC,cAAc;iBACzB;qBACI,IAAI,GAAG,KAAK,eAAe,EAAE;oBAChC,CAAC,CAAC,WAAW,GAAG,IAAI,CAAA;iBACrB;gBACD,OAAO,CAAC,CAAA;YACV,CAAC,EAAE,EAAE,CAAC,CAAA;QACR,CAAC,CAAC,CAAA;IACN,CAAC;CAAA;AAhBD,gCAgBC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,KAAa;IAC3C,IAAI,kBAAG,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QACzB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACpB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;QACzB,MAAM,OAAO,GAAG,WAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;QACnC,IAAI,kBAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE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AC,CAAA;iBACvB;gBACD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;gBAC7B,IAAI,MAAM,EAAE;oBACV,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;iBAChC;gBACD,QAAQ,CAAC,IAAI,CAAC,CAAA;YAChB,CAAC,CAAC,CAAA;SACN;aAAM;YACL,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;YACrC,QAAQ,CAAC,IAAI,CAAC,CAAA;SACf;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AArBD,gCAqBC"} \ No newline at end of file diff --git a/dist/main.d.ts b/dist/main.d.ts index 62bc95c..6b60381 100644 --- a/dist/main.d.ts +++ b/dist/main.d.ts @@ -1,7 +1,7 @@ /** * Top level API - * @param {args} array from process.argv + * @param {Array} _args from process.argv * @return {void} * @public */ -export declare function main(): Promise; +export declare function main(_args: Array): Promise; diff --git a/dist/main.js b/dist/main.js index 94b0a7a..ef79707 100644 --- a/dist/main.js +++ b/dist/main.js @@ -6,14 +6,14 @@ const tslib_1 = require("tslib"); const lib_1 = require("./lib"); /** * Top level API - * @param {args} array from process.argv + * @param {Array} _args from process.argv * @return {void} * @public */ -function main() { +function main(_args) { return tslib_1.__awaiter(this, void 0, void 0, function* () { // there is no point of accepting input anyway - return lib_1.processArg(process.argv.slice(2)) + return lib_1.processArg(_args) .then(args => { const [pkgFile, _pkg] = lib_1.changeAndGetPkg(args.to || process.cwd()); const pkg = lib_1.copyProps(_pkg); diff --git a/dist/main.js.map b/dist/main.js.map index 462933d..b2988be 100644 --- a/dist/main.js.map +++ b/dist/main.js.map @@ -1 +1 @@ -{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AAAA,wCAAwC;;;;AAExC,+BAMc;AAEd;;;;;GAKG;AACH,SAAsB,IAAI;;QACxB,8CAA8C;QAC9C,OAAO,gBAAU,CAAC,OAAO,CAAC,IAAI,C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BAAU,CAAC,IAAI,CAAC,CAAC,CAChC,CAAC,CAAA;IACN,CAAC;CAAA;AAbD,oBAaC"} \ No newline at end of file -- Gitee