Skip to content

Commit

Permalink
Merge pull request #14 from awesome-starter/develop
Browse files Browse the repository at this point in the history
chore: release next version
  • Loading branch information
chengpeiquan authored Jan 21, 2022
2 parents 6dda5a6 + ea0cbdd commit 20ab7fe
Show file tree
Hide file tree
Showing 40 changed files with 2,024 additions and 597 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dist/*
src/templates/*
bin/*
11 changes: 3 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@ module.exports = {
node: true,
jest: true,
},
extends: ['plugin:jsdoc/recommended', 'eslint:recommended', 'prettier'],
extends: ['eslint:recommended', 'prettier'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 13,
sourceType: 'module',
},
plugins: ['jsdoc', 'prettier'],
plugins: ['@typescript-eslint', 'prettier'],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'prettier/prettier': 'warn',
},
settings: {
jsdoc: {
mode: 'typescript',
},
},
}
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
package-lock.json
test-download
.DS_Store
dist
dist-ssr
bin
*.local
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dist
bin
*.md
*.xlsx
15 changes: 15 additions & 0 deletions favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion jest.config.js → jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* https://jestjs.io/docs/configuration
*/

module.exports = {
export default {
// All imported modules in your tests should be mocked automatically
// automock: false,

Expand Down
61 changes: 36 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{
"name": "create-preset",
"version": "0.6.9",
"description": "Provides the ability to quickly create preset projects.",
"keywords": [
"preset"
],
"license": "MIT",
"version": "0.7.0",
"author": "chengpeiquan",
"bin": {
"create-preset": "src/index.js",
"preset": "src/index.js"
},
"main": "src/index.js",
"license": "MIT",
"homepage": "https://preset.js.org",
"files": [
"src/*"
"dist"
],
"types": "./dist/types/main.d.ts",
"main": "./dist/create-preset.js",
"bin": {
"create-preset": "./dist/create-preset.js",
"preset": "./dist/create-preset.js"
},
"scripts": {
"test": "jest --no-cache",
"lint": "eslint src --ext .js,.ts",
"dev": "vite",
"build": "tsc --noEmit && vite build && npm run dts",
"dts": "tsc --emitDeclarationOnly && npm run replace",
"replace": "tscpaths -p tsconfig.json -s ./src -o ./dist/types",
"format": "prettier --write .",
"backup": "git add . && git commit -m \"chore: save the coding progress\" && git push"
},
Expand All @@ -31,32 +32,42 @@
"bugs": {
"url": "https://github.com/awesome-starter/create-preset/issues"
},
"homepage": "https://preset.js.org",
"dependencies": {
"chalk": "4.1.2",
"chalk": "^4.1.2",
"commander": "^8.3.0",
"compare-versions": "3.6.0",
"compare-versions": "^3.6.0",
"download-git-repo": "^3.0.2",
"latest-version": "5.1.0",
"leven": "3.1.0",
"latest-version": "^5.1.0",
"leven": "^3.1.0",
"minimist": "^1.2.5",
"node-fetch": "2.6.6",
"ora": "5.4.1",
"node-fetch": "^2.6.7",
"ora": "^5.4.1",
"prompts": "^2.4.2"
},
"devDependencies": {
"eslint": "^8.6.0",
"@types/lodash.escaperegexp": "^4.1.6",
"@types/minimist": "^1.2.2",
"@types/node": "^17.0.10",
"@types/prompts": "^2.0.14",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jsdoc": "^37.5.1",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.4.6",
"lint-staged": "11.1.4",
"jest": "^27.4.7",
"lint-staged": "^12.2.0",
"lodash.escaperegexp": "^4.1.2",
"prettier": "^2.5.1",
"tscpaths": "^0.0.9",
"typescript": "^4.5.4",
"vite": "^2.7.13",
"vite-plugin-banner": "^0.2.0",
"vite-plugin-commonjs-externals": "^0.1.1",
"yorkie": "^2.0.0"
},
"gitHooks": {
"pre-commit": "lint-staged",
"commit-msg": "node scripts/verifyCommit.js"
"commit-msg": "node ./scripts/verifyCommit.js"
},
"lint-staged": {
"*.js": [
Expand Down
9 changes: 9 additions & 0 deletions scripts/cjsExternalsRegexp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import escapeRegExp from 'lodash.escapeRegExp'
import pkg from '../package.json'

const deps: string = Object.keys(pkg.dependencies)
.map((name) => escapeRegExp(name))
.join('|')
const regexp: RegExp = new RegExp(`^(${deps})(/.+)?$`)

export default regexp
4 changes: 3 additions & 1 deletion scripts/verifyCommit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Invoked on the commit-msg git hook by yorkie.

const chalk = require('chalk')
const { readFileSync } = require('fs')

const msgPath = process.env.GIT_PARAMS
const msg = require('fs').readFileSync(msgPath, 'utf-8').trim()
const msg = readFileSync(msgPath, 'utf-8').trim()

const commitRE =
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
Expand Down
12 changes: 12 additions & 0 deletions src/core/configure.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* The action for `configure` command
*
* @param action - The action to operate local preset
*/
export default function configure({
cmd,
filePath,
}: {
cmd: string
filePath?: string
}): Promise<void>
23 changes: 13 additions & 10 deletions src/core/configure.js → src/core/configure.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
const chalk = require('chalk')
const { get, set, remove } = require('../libs/local')
import chalk from 'chalk'
import { get, set, remove } from '../libs/local'

/**
* The action for `configure` command
*
* @param {{ cmd: string; filePath?: string }} action - The action to operate local preset
* @param action - The action to operate local preset
*/
async function configure({ cmd, filePath }) {
export default async function configure({
cmd,
filePath,
}: {
cmd: string
filePath?: string
}) {
if (!['get', 'set', 'remove'].includes(cmd)) return

const tips = ` Run ${chalk.cyan(
Expand All @@ -32,10 +38,9 @@ async function configure({ cmd, filePath }) {

// Set the local config file path into .presetrc
case 'set': {
set(filePath)
console.log()
console.log(' ' + chalk.green('Saved successfully.'))
console.log()
const localConfigFilePath: string =
typeof filePath === 'string' ? filePath : ''
set(localConfigFilePath)
break
}

Expand All @@ -58,5 +63,3 @@ async function configure({ cmd, filePath }) {
}
}
}

module.exports = configure
7 changes: 7 additions & 0 deletions src/core/init.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* The action for `init` command
* @param targetDirFromCMD - The dir name from CMD, if there is input
*/
export default function init(
targetDirFromCMD: string | undefined
): Promise<void>
39 changes: 16 additions & 23 deletions src/core/init.js → src/core/init.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
#!/usr/bin/env node

// @ts-check
const fs = require('fs')
const path = require('path')
// Avoids autoconversion to number of the project name by defining that the args
// non associated with an option ( _ ) needs to be parsed as a string. See #4606
const argv = require('minimist')(process.argv.slice(2), { string: ['_'] })
const prompts = require('prompts')
const chalk = require('chalk')
const {
import fs from 'fs'
import path from 'path'
import prompts from 'prompts'
import chalk from 'chalk'
import {
isValidPackageName,
toValidPackageName,
pkgFromUserAgent,
} = require('../libs/pkg')
const { write, remove, emptyDir, isEmpty } = require('../libs/dir')
const { getDownloadUrl, download } = require('../libs/download')
const { getConfig } = require('../libs/config')
} from '../libs/pkg'
import { write, remove, emptyDir, isEmpty } from '../libs/dir'
import { getDownloadUrl, download } from '../libs/download'
import { getConfig } from '../libs/config'
import argv from '../libs/argv'
import type { UserInputFromCMD } from '@/types'
const cwd = process.cwd()

/**
* The action for `init` command
*
* @param {string | undefined} targetDirFromCMD - The dir name from CMD, if there is input
* @param targetDirFromCMD - The dir name from CMD, if there is input
*/
async function init(targetDirFromCMD) {
export default async function init(targetDirFromCMD: string | undefined) {
const { techStacks, templates } = await getConfig()

let targetDir = targetDirFromCMD || argv._[1]
let template = argv.template || argv.t

Expand All @@ -34,11 +30,10 @@ async function init(targetDirFromCMD) {
* @typedef { import('../types').UserInputFromCMD } UserInputFromCMD
* @type {UserInputFromCMD}
*/
let result = {
let result: UserInputFromCMD = {
projectName: '',
packageName: '',
overwrite: false,
// @ts-ignore
techStack: undefined,
variant: '',
}
Expand Down Expand Up @@ -148,7 +143,7 @@ async function init(targetDirFromCMD) {
// Get download URL from CMD
const downloadUrl = getDownloadUrl({
template,
variants: techStack.variants,
variants: techStack ? techStack.variants : [],
})

// Download template
Expand Down Expand Up @@ -193,5 +188,3 @@ async function init(targetDirFromCMD) {
}
console.log()
}

module.exports = init
4 changes: 4 additions & 0 deletions src/core/upgrade.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* The action for `upgrade` command
*/
export default function upgrade(): Promise<void>
16 changes: 7 additions & 9 deletions src/core/upgrade.js → src/core/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { exec } = require('child_process')
const prompts = require('prompts')
const ora = require('ora')
const chalk = require('chalk')
const { packageInfo } = require('../libs/pkg')
import { exec } from 'child_process'
import prompts from 'prompts'
import ora from 'ora'
import chalk from 'chalk'
import { packageInfo } from '../libs/pkg'

/**
* Upgrade the CLi
* The action for `upgrade` command
*/
async function upgrade() {
export default async function upgrade() {
const { packageName, currentVersion, latestVersion, needToUpgrade } =
await packageInfo()
console.log()
Expand Down Expand Up @@ -126,5 +126,3 @@ async function upgrade() {
spinner.succeed(chalk.green('Upgraded successfully.'))
})
}

module.exports = upgrade
3 changes: 3 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'download-git-repo'
declare module 'node-fetch'
declare module '*.json'
3 changes: 3 additions & 0 deletions src/libs/argv.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import minimist from 'minimist'
declare const argv: minimist.ParsedArgs
export default argv
6 changes: 6 additions & 0 deletions src/libs/argv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import minimist from 'minimist'

// Avoids autoconversion to number of the project name by defining that the args
// non associated with an option ( _ ) needs to be parsed as a string. See #4606
const argv = minimist(process.argv.slice(2), { string: ['_'] })
export default argv
6 changes: 6 additions & 0 deletions src/libs/cmd.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Suggest command when user input unknow command
*
* @param unknownCMD - Unknown command
*/
export declare function suggestCommands(unknownCMD: string): void
Loading

0 comments on commit 20ab7fe

Please sign in to comment.