-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 🎸 add create pkg cli * refactor: 💡 move to @ice/pkg * chore: 🤖 publsih files to npm * feat: 🎸 typo of docusaurus & refact * refactor: 💡 refact code * fix: 🐛 remove core.js * ci: 🎡 pass ci * fix: 🐛 generate material instead of projects * fix: 🐛 remove generate project pkg * chore: 🤖 version * feat: 🎸 remove iceworks * chore: 🤖 error in package.lock * refactor: 💡 lint * refactor: 💡 refact * feat: 🎸 reduce inquirer
- Loading branch information
Showing
31 changed files
with
539 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Changelog | ||
|
||
## 1.0.1 | ||
|
||
- [fix] remove `@@appworks/cli`. | ||
|
||
## 1.0.0 | ||
|
||
- init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# @ice/create-pkg | ||
|
||
Create pkg-cli projects by npm initing. | ||
|
||
## Usage | ||
|
||
```shell | ||
$ npm init @ice/pkg component-name | ||
|
||
# or with pnpm | ||
$ pnpm init @ice/pkg component-name | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "@ice/create-pkg", | ||
"version": "1.0.1", | ||
"description": "npm init @ice/pkg", | ||
"type": "module", | ||
"exports": "./esnext/index.js", | ||
"files": [ | ||
"es", | ||
"esnext" | ||
], | ||
"bin": { | ||
"create-pkg": "./esnext/index.js" | ||
}, | ||
"scripts": { | ||
"build": "pkg-cli build" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@ice/pkg-cli": "1.0.0-beta.3", | ||
"typescript": "^4.5.4" | ||
}, | ||
"dependencies": { | ||
"@iceworks/generate-material": "^1.0.12", | ||
"cac": "^6.7.12", | ||
"consola": "^2.15.3", | ||
"fs-extra": "^10.0.0", | ||
"ice-npm-utils": "^3.0.2", | ||
"inquirer": "^8.2.1", | ||
"validate-npm-package-name": "^3.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import fs from 'fs-extra'; | ||
|
||
export async function checkEmpty(dir: string): Promise<boolean> { | ||
let files: string[] = fs.readdirSync(dir); | ||
files = files.filter((filename) => { | ||
return ['node_modules', '.git', '.DS_Store', '.iceworks-tmp', 'build', '.bzbconfig'].indexOf(filename) === -1; | ||
}); | ||
if (files.length && files.length > 0) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env node | ||
|
||
import { fileURLToPath } from 'url'; | ||
import consola from 'consola'; | ||
import { cac } from 'cac'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import inquirer from 'inquirer'; | ||
import { downloadMaterialTemplate, generateMaterial } from '@iceworks/generate-material'; | ||
import { checkEmpty } from './checkEmpty.js'; | ||
import { inquirPackageName } from './inquirPackageName.js'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
const cli = cac('@ice/create-pkg'); | ||
|
||
(async () => { | ||
cli.command('[...args]', 'Target dirname to generate', { | ||
allowUnknownOptions: false, | ||
ignoreOptionDefaultValue: true, | ||
}) | ||
.action(async (args) => { | ||
const targetDirname = args[0] ?? '.'; | ||
|
||
const dirPath = path.join(process.cwd(), targetDirname); | ||
await create(dirPath, targetDirname); | ||
}); | ||
|
||
cli.help(); | ||
|
||
const pkgPath = path.join(__dirname, '../package.json'); | ||
const { version } = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')); | ||
consola.info('@ice/create-pkg version: ', version); | ||
|
||
cli.version(version); | ||
|
||
cli.parse(process.argv, { run: true }); | ||
})() | ||
.catch((err) => { | ||
consola.error(err); | ||
process.exit(1); | ||
}); | ||
|
||
async function create(dirPath: string, dirname: string): Promise<void> { | ||
await fs.ensureDir(dirPath); | ||
const empty = await checkEmpty(dirPath); | ||
|
||
if (!empty) { | ||
const { go } = await inquirer.prompt({ | ||
type: 'confirm', | ||
name: 'go', | ||
message: | ||
'Files exist in the current directory already. Are you sure to continue ?', | ||
default: false, | ||
}); | ||
if (!go) process.exit(1); | ||
} | ||
|
||
const tempDir = path.join(dirPath, '.tmp'); | ||
|
||
await downloadMaterialTemplate(tempDir, '@ice/template-pkg-react'); | ||
|
||
const npmName = await inquirPackageName(); | ||
|
||
await generateMaterial({ | ||
rootDir: dirPath, | ||
templateOptions: { | ||
npmName, | ||
}, | ||
materialTemplateDir: tempDir, | ||
materialType: 'component', | ||
}); | ||
|
||
await fs.remove(tempDir); | ||
|
||
console.log(); | ||
console.log('Initialize component successfully.'); | ||
console.log(); | ||
console.log(` cd ${dirname}`); | ||
console.log(' npm install'); | ||
console.log(' npm start'); | ||
console.log(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import inquirer from 'inquirer'; | ||
import { checkAliInternal } from 'ice-npm-utils'; | ||
import validateName from 'validate-npm-package-name'; | ||
|
||
function generateNpmName(name: string, npmScope?: string): string { | ||
if (name.charAt(0) === '@') { | ||
return name; | ||
} | ||
|
||
return npmScope ? `${npmScope}/${name}` : name; | ||
} | ||
|
||
export async function inquirPackageName() { | ||
const isIntranet = checkAliInternal(); | ||
|
||
const { forIntranet } = await (isIntranet | ||
? inquirer.prompt([ | ||
{ | ||
type: 'confirm', | ||
message: 'generate components that are only available on the Intranet', | ||
name: 'forIntranet', | ||
}, | ||
]) | ||
: { forIntranet: false }); | ||
|
||
let npmScope = null; | ||
if (forIntranet) { | ||
npmScope = (await inquirer.prompt([ | ||
{ | ||
type: 'list', | ||
message: 'please select the npm scope', | ||
name: 'npmScope', | ||
default: '@ali', | ||
choices: ['@ali', '@alife', '@alipay', '@kaola'], | ||
}, | ||
]))?.npmScope; | ||
} | ||
|
||
const { npmName } = await inquirer.prompt([ | ||
{ | ||
type: 'input', | ||
name: 'npmName', | ||
message: 'package name', | ||
default: 'example-component', | ||
validate: (value) => { | ||
const name = generateNpmName(value, npmScope); | ||
if (!validateName(name).validForNewPackages) { | ||
return `NPM package name ${name} not validate, please retry`; | ||
} | ||
return true; | ||
}, | ||
}, | ||
]); | ||
|
||
return generateNpmName(npmName, npmScope); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
packages/plugin-docusarus/package.json → packages/plugin-docusaurus/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"baseUrl": "./", | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": ["src"] | ||
} |
Oops, something went wrong.