Skip to content

Commit

Permalink
feat: scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Oct 6, 2023
1 parent dddaac1 commit 6c4cc44
Show file tree
Hide file tree
Showing 22 changed files with 3,326 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"ignorePatterns": [
"node_modules/",
"dist/"
"dist/",
"create-gopeed-ext/"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Gopeed Javascript Monerepo
# Gopeed Javascript Monorepo

Gopeed development kit for javascript.

Expand Down
12 changes: 0 additions & 12 deletions packages/create-gopeed-app/package.json

This file was deleted.

Empty file.
121 changes: 121 additions & 0 deletions packages/create-gopeed-ext/createGopeedExt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';
import chalk from 'chalk';
import commander from 'commander';
import prompts from 'prompts';
import validateNpmName from 'validate-npm-package-name';
import packageJson from './package.json' assert { type: 'json' };

let projectName;

async function initAction(program) {
if (!projectName) {
console.error('Please specify the project directory:');
console.log(` ${chalk.cyan(program.name())} ${chalk.green('<project-directory>')}`);
console.log();
console.log('For example:');
console.log(` ${chalk.cyan(program.name())} ${chalk.green('gopeed-test-extension')}`);
console.log();
console.log(`Run ${chalk.cyan(`${program.name()} --help`)} to see all options.`);
process.exit(1);
}

// check if project name is valid
const validResult = validateNpmName(projectName);
if (!validResult.validForNewPackages) {
console.error(
`Could not create a project called ${chalk.red(`"${projectName}"`)} because of npm naming restrictions:`
);

[...(validResult.errors || []), ...(validResult.warnings || [])].forEach((error) => {
console.error(chalk.red(` * ${error}`));
});
process.exit(1);
}

const projectPath = path.join(process.cwd(), projectName);
// check if target dir exists
if (fs.existsSync(projectPath)) {
console.error(
`Could not create a project called ${chalk.red(`"${projectName}"`)} because this directory already exists.`
);
process.exit(1);
}

const template = await prompts([
{
type: 'select',
name: 'value',
message: 'Choose a template',
choices: [
{ title: 'Webpack', description: 'Webpack + Eslint + Prettier', value: 'webpack' },
{ title: 'Pure', description: 'Pure Javascript', value: 'pure' },
],
initial: 0,
},
]);

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const templatePath = path.join(__dirname, 'templates', template.value);

// copy template files to target dir recursively
copyDir(templatePath, projectPath);

// print success message, and how to start the project
console.log();
console.log(`Success! Created ${chalk.cyan(projectName)} at ${chalk.cyan(projectPath)}`);
console.log('Inside that directory, you can run several commands:');
console.log();
console.log(chalk.cyan(` git init`));
console.log(' Initialize git repository');
console.log();
if (template.value !== 'pure') {
console.log(chalk.cyan(` npm install`));
console.log(' Install dependencies');
console.log();
console.log(chalk.cyan(` npm run dev`));
console.log(' Compiles and hot-reloads for development.');
console.log();
console.log(chalk.cyan(` npm run build`));
console.log(' Compiles and minifies for production.');
console.log();
}
console.log('We suggest that you begin by typing:');
console.log();
console.log(chalk.cyan(` cd ${projectName}`));
console.log();
console.log('Happy coding!');
}

function init() {
const program = new commander.Command(packageJson.name)
.version(packageJson.version)
.arguments('<project-directory>')
.usage(`${chalk.green('<project-directory>')} [options]`)
.action((name) => {
projectName = name;
})
.allowUnknownOption()
.parse(process.argv);

initAction(program);
}

function copyDir(src, dest) {
fs.mkdirSync(dest, { recursive: true });

fs.readdirSync(src, { withFileTypes: true }).forEach((entry) => {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);

if (entry.isDirectory()) {
copyDir(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
});
}

export default init;
4 changes: 4 additions & 0 deletions packages/create-gopeed-ext/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node
import init from './createGopeedExt.js';

init();
37 changes: 37 additions & 0 deletions packages/create-gopeed-ext/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "create-gopeed-ext",
"version": "1.0.0",
"keywords": [
"gopeed"
],
"description": "Create gopeed extension with no build configuration.",
"repository": {
"type": "git",
"url": "https://github.com/GopeedLab/gopeed-js",
"directory": "packages/create-react-app"
},
"license": "MIT",
"engines": {
"node": ">=14"
},
"bugs": {
"url": "https://github.com/GopeedLab/gopeed-js/issues"
},
"files": [
"index.js",
"createGopeedExt.js"
],
"bin": {
"create-gopeed-ext": "./index.js"
},
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"chalk": "^4.1.2",
"commander": "^4.1.1",
"prompts": "^2.4.2",
"validate-npm-package-name": "^5.0.0"
}
}
129 changes: 129 additions & 0 deletions packages/create-gopeed-ext/templates/pure/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
11 changes: 11 additions & 0 deletions packages/create-gopeed-ext/templates/pure/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
gopeed.events.onResolve((ctx) => {
ctx.res = {
name: "gopeed",
files: [
{
name: "test.txt",
size: 1024,
},
],
};
});
22 changes: 22 additions & 0 deletions packages/create-gopeed-ext/templates/pure/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "gopeed-extention-demo",
"author": "",
"title": "gopeed extention demo title",
"description": "gopeed extention demo description",
"icon": "",
"version": "1.0.0",
"homepage": "",
"repository": {
"url": ""
},
"scripts": [
{
"event": "onResolve",
"matches": [
"*://github.com/*"
],
"entry": "dist/index.js"
}
],
"settings": []
}
Loading

0 comments on commit 6c4cc44

Please sign in to comment.