nsbp-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +150 -0
  3. package/bin/nsbp.js +145 -0
  4. package/package.json +43 -0
  5. package/scripts/sync-template.js +277 -0
  6. package/templates/basic/.prettierignore +5 -0
  7. package/templates/basic/.prettierrc +5 -0
  8. package/templates/basic/README.md +13 -0
  9. package/templates/basic/package.json +101 -0
  10. package/templates/basic/postcss.config.js +7 -0
  11. package/templates/basic/public/favicon.ico +0 -0
  12. package/templates/basic/public/images/test/0.jpg +0 -0
  13. package/templates/basic/public/images/test/1.jpg +0 -0
  14. package/templates/basic/public/images/test/2.jpg +0 -0
  15. package/templates/basic/public/images/test/3.jpg +0 -0
  16. package/templates/basic/public/images/test/4.jpg +0 -0
  17. package/templates/basic/public/images/test/5.jpg +0 -0
  18. package/templates/basic/scripts/start.js +3 -0
  19. package/templates/basic/src/Routers.tsx +40 -0
  20. package/templates/basic/src/client/index.tsx +37 -0
  21. package/templates/basic/src/component/Header.tsx +38 -0
  22. package/templates/basic/src/component/Layout.tsx +24 -0
  23. package/templates/basic/src/component/Loading.tsx +7 -0
  24. package/templates/basic/src/component/Theme.tsx +14 -0
  25. package/templates/basic/src/containers/Home.tsx +435 -0
  26. package/templates/basic/src/containers/Login.tsx +32 -0
  27. package/templates/basic/src/containers/Photo.tsx +162 -0
  28. package/templates/basic/src/css/test.css +13 -0
  29. package/templates/basic/src/css/test.less +8 -0
  30. package/templates/basic/src/css/test2.sass +7 -0
  31. package/templates/basic/src/css/test3.scss +8 -0
  32. package/templates/basic/src/externals/less.d.ts +4 -0
  33. package/templates/basic/src/externals/window.d.ts +3 -0
  34. package/templates/basic/src/reducers/home.ts +17 -0
  35. package/templates/basic/src/reducers/index.ts +26 -0
  36. package/templates/basic/src/reducers/photo.ts +23 -0
  37. package/templates/basic/src/server/index.ts +29 -0
  38. package/templates/basic/src/server/photo.ts +118 -0
  39. package/templates/basic/src/server/utils.tsx +158 -0
  40. package/templates/basic/src/services/home.ts +52 -0
  41. package/templates/basic/src/services/photo.ts +64 -0
  42. package/templates/basic/src/store/constants.ts +4 -0
  43. package/templates/basic/src/store/index.ts +14 -0
  44. package/templates/basic/src/styled/common.ts +26 -0
  45. package/templates/basic/src/styled/component/header.ts +166 -0
  46. package/templates/basic/src/styled/component/layout.ts +10 -0
  47. package/templates/basic/src/styled/home.ts +789 -0
  48. package/templates/basic/src/styled/photo.ts +44 -0
  49. package/templates/basic/src/styled/test.ts +14 -0
  50. package/templates/basic/src/utils/clientConfig.ts +2 -0
  51. package/templates/basic/src/utils/config.ts +7 -0
  52. package/templates/basic/src/utils/fetch.ts +26 -0
  53. package/templates/basic/src/utils/index.ts +45 -0
  54. package/templates/basic/tsconfig.json +18 -0
  55. package/templates/basic/webpack.base.js +262 -0
  56. package/templates/basic/webpack.client.js +26 -0
  57. package/templates/basic/webpack.server.js +33 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,102 @@
1
+ # NSBP CLI Changelog
2
+
3
+ All notable changes to the NSBP CLI project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2026-01-09
9
+
10
+ ### Added
11
+ - **Initial release**: CLI tool for creating NSBP (Node React SSR by Webpack) projects
12
+ - **Create command**: `nsbp create <project-name>` to scaffold new projects
13
+ - **Template system**: Built-in templates (basic, blog, ecommerce support planned)
14
+ - **Interactive prompts**: Confirmation for overwriting existing directories
15
+ - **Template synchronization**: Smart sync script (`scripts/sync-template.js`) to update CLI templates from main NSBP project
16
+
17
+ ### Changed
18
+ - **Package.json handling**: Automatic template name transformation ("nsbp-template" → user project name)
19
+ - **Build artifact filtering**: Exclude .js.map, .css.map, .txt, .json, .LICENSE.txt files from public directory during sync
20
+
21
+ ### Features
22
+ - **Skip installation option**: `--skip-install` flag to skip npm install
23
+ - **Template selection**: `--template <template>` option (currently basic only)
24
+ - **Help system**: Comprehensive help with `--help` flag
25
+ - **Version info**: `--version` flag to display CLI version
26
+ - **Project info**: `nsbp info` command to display framework information
27
+
28
+ ### Technical Details
29
+ - **Dependencies**:
30
+ - `commander` for CLI argument parsing
31
+ - `chalk` for colored console output
32
+ - `inquirer` for interactive prompts
33
+ - `fs-extra` for enhanced file operations
34
+ - **Built-in templates**: Located in `cli/templates/basic/`
35
+ - **Sync script**: Located in `cli/scripts/sync-template.js`
36
+
37
+ ### Usage
38
+
39
+ #### Installation
40
+ ```bash
41
+ # Install globally
42
+ npm install -g nsbp
43
+
44
+ # Or use with npx (no installation required)
45
+ npx nsbp create my-app
46
+ ```
47
+
48
+ #### Create a new project
49
+ ```bash
50
+ # Basic usage
51
+ nsbp create my-app
52
+
53
+ # Skip npm install
54
+ nsbp create my-app --skip-install
55
+
56
+ # Specify template (currently basic only)
57
+ nsbp create my-app --template basic
58
+ ```
59
+
60
+ #### Update CLI templates
61
+ ```bash
62
+ # Run from CLI directory
63
+ cd /path/to/nsbp/cli
64
+ npm run sync-template
65
+
66
+ # Or use the update shortcut
67
+ npm run update
68
+ ```
69
+
70
+ #### Display information
71
+ ```bash
72
+ # Show NSBP framework information
73
+ nsbp info
74
+
75
+ # Show CLI version
76
+ nsbp --version
77
+
78
+ # Show help
79
+ nsbp --help
80
+ ```
81
+
82
+ ### Notes
83
+ - This is the initial release of NSBP CLI
84
+ - The CLI currently supports the "basic" template only
85
+ - Blog and ecommerce templates are planned for future releases
86
+ - The sync script automatically filters out build artifacts to keep templates clean
87
+ - All templates are built-in; no external downloads required
88
+
89
+ ---
90
+
91
+ ## Future Plans
92
+ - **Template expansion**: Add blog and ecommerce templates
93
+ - **Advanced configuration**: Custom webpack and TypeScript configuration options
94
+ - **Plugin system**: Support for third-party templates and plugins
95
+ - **CI/CD integration**: Automated testing and deployment workflows
96
+ - **Internationalization**: Multi-language support for CLI output
97
+
98
+ ## Contributing
99
+ Contributions are welcome! Please see the main NSBP project repository for contribution guidelines.
100
+
101
+ ## License
102
+ ISC © Erishen Sun
package/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # NSBP CLI
2
+
3
+ Command-line interface for creating NSBP (Node React SSR by Webpack) projects.
4
+
5
+ ## Local Usage
6
+
7
+ The CLI is located in the `cli/` directory of the NSBP project. Run it locally:
8
+
9
+ ```bash
10
+ # Navigate to CLI directory
11
+ cd cli
12
+
13
+ # Show help
14
+ node ./bin/nsbp.js --help
15
+
16
+ # Show NSBP information
17
+ node ./bin/nsbp.js info
18
+
19
+ # Create a new project
20
+ node ./bin/nsbp.js create my-app
21
+
22
+ # Skip npm install
23
+ node ./bin/nsbp.js create my-app --skip-install
24
+ ```
25
+
26
+ ## Global Installation
27
+
28
+ To use `nsbp` command globally from anywhere:
29
+
30
+ ```bash
31
+ # Navigate to CLI directory
32
+ cd cli
33
+
34
+ # Install globally
35
+ npm link
36
+
37
+ # Now you can use from anywhere
38
+ nsbp create my-app
39
+ nsbp info
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ### Create a new project
45
+
46
+ ```bash
47
+ # Basic usage
48
+ node ./bin/nsbp.js create my-app
49
+
50
+ # Or after npm link
51
+ nsbp create my-app
52
+
53
+ # Skip npm install
54
+ node ./bin/nsbp.js create my-app --skip-install
55
+ # or
56
+ nsbp create my-app --skip-install
57
+
58
+ # Specify template (currently only basic is available)
59
+ nsbp create my-app --template basic
60
+ ```
61
+
62
+ ### Display information
63
+
64
+ ```bash
65
+ # Show NSBP framework information
66
+ nsbp info
67
+ # or
68
+ node ./bin/nsbp.js info
69
+ ```
70
+
71
+ ### Help
72
+
73
+ ```bash
74
+ # Show all commands
75
+ nsbp --help
76
+ # or
77
+ node ./bin/nsbp.js --help
78
+
79
+ # Show create command help
80
+ nsbp create --help
81
+ ```
82
+
83
+ ## Templates
84
+
85
+ - **basic**: Default template with core NSBP features (currently available)
86
+ - **blog**: Blog-focused template with article layouts (coming soon)
87
+ - **ecommerce**: E-commerce template with product pages (coming soon)
88
+
89
+ ## How it works
90
+
91
+ The CLI copies the NSBP project structure from templates/basic/ to your target directory and creates a new `package.json` with the appropriate dependencies. You get a fully functional NSBP project ready for development.
92
+
93
+ ## Template Synchronization
94
+
95
+ The CLI includes a synchronization script that keeps the built-in templates up-to-date with the main NSBP project code.
96
+
97
+ ### Sync Script
98
+ Location: `cli/scripts/sync-template.js`
99
+
100
+ ### Usage
101
+ ```bash
102
+ # From the CLI directory
103
+ cd /path/to/nsbp/cli
104
+
105
+ # Run the sync script
106
+ npm run sync-template
107
+
108
+ # Or use the update shortcut
109
+ npm run update
110
+ ```
111
+
112
+ ### Features
113
+ - **Smart copying**: Copies only source code and configuration files
114
+ - **Build artifact filtering**: Automatically excludes .js.map, .css.map, .txt, .json, and .LICENSE.txt files from public directory
115
+ - **Template transformation**: Converts main project's package.json to template format (name: "nsbp-template")
116
+ - **Integrity verification**: Checks for required files like src/Routers.tsx, scripts/start.js, and package.json
117
+
118
+ ### What gets synchronized
119
+ - `src/` - React components and routing
120
+ - `public/` - Static assets (images, favicon.ico)
121
+ - `scripts/` - Startup and utility scripts
122
+ - `webpack.*.js` - Webpack configuration files
123
+ - `tsconfig.json` - TypeScript configuration
124
+ - `postcss.config.js` - PostCSS configuration
125
+ - `package.json` - Project configuration (automatically templatized)
126
+ - `.gitignore`, `.prettierrc`, `.prettierignore`, `README.md`
127
+
128
+ ## Development
129
+
130
+ To work on the CLI locally:
131
+
132
+ ```bash
133
+ cd cli
134
+ pnpm install
135
+ # or
136
+ npm install
137
+ node ./bin/nsbp.js create test-app
138
+ ```
139
+
140
+ ## Package Information
141
+
142
+ - **Package Name**: `nsbp-cli`
143
+ - **Bin Command**: `nsbp`
144
+ - **Dependencies**: chalk, commander, fs-extra, inquirer
145
+ - **Package Manager**: Supports both npm and pnpm
146
+
147
+
148
+ ## License
149
+
150
+ ISC
package/bin/nsbp.js ADDED
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { Command } = require('commander');
4
+ const chalk = require('chalk');
5
+ const fs = require('fs-extra');
6
+ const path = require('path');
7
+ const { execSync } = require('child_process');
8
+ const inquirer = require('inquirer');
9
+
10
+ const program = new Command();
11
+
12
+ program
13
+ .name('nsbp')
14
+ .description('CLI tool to create NSBP (Node React SSR by Webpack) projects')
15
+ .version('0.1.0');
16
+
17
+ program
18
+ .command('create <project-name>')
19
+ .description('Create a new NSBP project')
20
+ .option('-t, --template <template>', 'Specify template (basic, blog, ecommerce)', 'basic')
21
+ .option('--skip-install', 'Skip npm install')
22
+ .action(async (projectName, options) => {
23
+ console.log(chalk.cyan(`🚀 Creating NSBP project: ${projectName}`));
24
+
25
+ try {
26
+ // Check if directory already exists
27
+ const targetDir = path.join(process.cwd(), projectName);
28
+ if (fs.existsSync(targetDir)) {
29
+ const { overwrite } = await inquirer.prompt([
30
+ {
31
+ type: 'confirm',
32
+ name: 'overwrite',
33
+ message: `Directory "${projectName}" already exists. Overwrite?`,
34
+ default: false,
35
+ },
36
+ ]);
37
+ if (!overwrite) {
38
+ console.log(chalk.yellow('Operation cancelled.'));
39
+ process.exit(0);
40
+ }
41
+ fs.removeSync(targetDir);
42
+ }
43
+
44
+ // Create project directory
45
+ fs.ensureDirSync(targetDir);
46
+
47
+ // Get template source path from built-in templates
48
+ const templateSource = path.join(__dirname, '../templates/basic');
49
+
50
+ // List of files/directories to copy
51
+ const copyItems = [
52
+ 'src',
53
+ 'public',
54
+ 'scripts',
55
+ 'webpack.base.js',
56
+ 'webpack.client.js',
57
+ 'webpack.server.js',
58
+ 'tsconfig.json',
59
+ 'postcss.config.js',
60
+ '.prettierrc',
61
+ '.prettierignore',
62
+ '.gitignore',
63
+ 'README.md'
64
+ ];
65
+
66
+ // Copy each item
67
+ console.log(chalk.cyan('📦 Copying project files...'));
68
+ for (const item of copyItems) {
69
+ const source = path.join(templateSource, item);
70
+ const target = path.join(targetDir, item);
71
+ if (fs.existsSync(source)) {
72
+ if (fs.statSync(source).isDirectory()) {
73
+ fs.copySync(source, target, {
74
+ filter: (src) => {
75
+ // Exclude node_modules, build, .temp_cache, etc.
76
+ const excluded = ['node_modules', '.temp_cache', 'build', '.git', '.DS_Store', '.serena'];
77
+ return !excluded.some(ex => src.includes(ex));
78
+ }
79
+ });
80
+ } else {
81
+ fs.copySync(source, target);
82
+ }
83
+ }
84
+ }
85
+
86
+ // Create package.json for new project
87
+ const originalPackage = require(path.join(templateSource, 'package.json'));
88
+ const newPackage = {
89
+ name: projectName,
90
+ version: '1.0.0',
91
+ description: `NSBP project: ${projectName}`,
92
+ scripts: originalPackage.scripts,
93
+ dependencies: originalPackage.dependencies,
94
+ devDependencies: originalPackage.devDependencies,
95
+ keywords: originalPackage.keywords,
96
+ author: originalPackage.author,
97
+ license: originalPackage.license
98
+ };
99
+
100
+ fs.writeFileSync(
101
+ path.join(targetDir, 'package.json'),
102
+ JSON.stringify(newPackage, null, 2)
103
+ );
104
+
105
+ // Optionally install dependencies
106
+ if (!options.skipInstall) {
107
+ console.log(chalk.cyan('📦 Installing dependencies...'));
108
+ process.chdir(targetDir);
109
+ execSync('npm install', { stdio: 'inherit' });
110
+ }
111
+
112
+ console.log(chalk.green(`✅ NSBP project "${projectName}" created successfully!`));
113
+ console.log(chalk.yellow('\nNext steps:'));
114
+ console.log(` cd ${projectName}`);
115
+ if (options.skipInstall) {
116
+ console.log(' npm install');
117
+ }
118
+ console.log(' npm run dev');
119
+ console.log(chalk.cyan('\nHappy coding! 🎉'));
120
+
121
+ } catch (error) {
122
+ console.error(chalk.red(`❌ Error creating project: ${error.message}`));
123
+ process.exit(1);
124
+ }
125
+ });
126
+
127
+ program
128
+ .command('info')
129
+ .description('Display information about NSBP')
130
+ .action(() => {
131
+ console.log(chalk.cyan('NSBP - Node React SSR by Webpack'));
132
+ console.log(chalk.gray('A lightweight React SSR framework with full Webpack control.'));
133
+ console.log('');
134
+ console.log(chalk.yellow('Key Features:'));
135
+ console.log(' • ~60% less resource usage than Next.js');
136
+ console.log(' • Full Webpack configuration control');
137
+ console.log(' • TypeScript support out of the box');
138
+ console.log(' • Built-in image service');
139
+ console.log('');
140
+ console.log(chalk.cyan('Website: ') + 'https://github.com/nsbp/nsbp');
141
+ console.log(chalk.cyan('Usage: ') + 'nsbp create my-app');
142
+ });
143
+
144
+ // Parse command line arguments
145
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "nsbp-cli",
3
+ "version": "0.1.0",
4
+ "description": "CLI tool for creating NSBP (Node React SSR by Webpack) projects",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "nsbp": "./bin/nsbp.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node ./bin/nsbp.js",
11
+ "test": "echo \"Error: no test specified\" && exit 1",
12
+ "sync-template": "node ./scripts/sync-template.js",
13
+ "update": "npm run sync-template"
14
+ },
15
+ "keywords": [
16
+ "nsbp",
17
+ "cli",
18
+ "react",
19
+ "ssr",
20
+ "webpack",
21
+ "scaffold",
22
+ "generator"
23
+ ],
24
+ "author": "Erishen Sun",
25
+ "license": "ISC",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/erishen/nsbp"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/erishen/nsbp/issues"
32
+ },
33
+ "homepage": "https://github.com/erishen/nsbp#readme",
34
+ "dependencies": {
35
+ "chalk": "^4.1.2",
36
+ "commander": "^11.0.0",
37
+ "fs-extra": "^11.2.0",
38
+ "inquirer": "^8.2.6"
39
+ },
40
+ "engines": {
41
+ "node": ">=16.0.0"
42
+ }
43
+ }