Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# general
LICENSE
.gitignore
.keep

# configuration files
.dockerignore
Dockerfile

# package manager
pnpm-lock.yaml
.npmrc.example

# packages
.prettierignore
.husky

# files
*.sh
*.toml
*.env*

# images
*.ico
*.svg
14 changes: 8 additions & 6 deletions packages/builder-rslib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mainset/builder-rslib",
"version": "0.2.0",
"version": "0.3.0-rc.2",
"description": "Builder for node packages",
"homepage": "https://github.com/mainset/dev-stack-fe/tree/main/packages/builder-rslib",
"bugs": {
Expand All @@ -15,22 +15,24 @@
"type": "module",
"sideEffects": false,
"files": [
"dist"
"dist",
"src/@types"
],
"exports": {
".": {
"types": "./dist/types/index.d.mts",
"import": "./dist/esm/index.mjs"
}
},
"./global-types": "./src/@types/bundler.d.ts"
},
"scripts": {
"build": "ms-cli source-code --exec compile",
"dev": "cross-env NODE_ENV=development ms-cli source-code --exec watch"
},
"dependencies": {
"@rsbuild/plugin-react": "^1.4.1",
"@rsbuild/plugin-sass": "^1.4.0",
"@rslib/core": "^0.15.0"
"@rsbuild/plugin-react": "^1.4.5",
"@rsbuild/plugin-sass": "^1.5.0",
"@rslib/core": "^0.20.0"
},
"devDependencies": {
"@mainset/cli": "workspace:^",
Expand Down
4 changes: 4 additions & 0 deletions packages/builder-rslib/src/@types/bundler.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.module.scss' {
const styles: { [className: string]: string };
export = styles;
}
15 changes: 12 additions & 3 deletions packages/builder-rslib/src/rslib.node-sourcer.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const nodeSourcerCommonPresetRslib = defineConfig({
// OutBase: runtimePathById.dist,
output: {
filename: {
js: 'esm/index.mjs',
js: '[name].mjs',
},
distPath: {
root: path.join(runtimePathById.dist, 'esm'),
},
},
autoExternal: {
Expand All @@ -32,7 +35,10 @@ const nodeSourcerCommonPresetRslib = defineConfig({
// OutBase: runtimePathById.dist,
output: {
filename: {
js: 'cjs/index.cjs',
js: '[name].cjs',
},
distPath: {
root: path.join(runtimePathById.dist, 'cjs'),
},
},
autoExternal: {
Expand All @@ -46,7 +52,10 @@ const nodeSourcerCommonPresetRslib = defineConfig({
],
source: {
entry: {
index: [path.join(runtimePathById.src, 'index.mts')],
index: path.join(
runtimePathById.src,
process.env.MS_CLI__RSLIB_BUNDLESS_MODE ? '/**/*' : 'index.mts',
),
},
},
output: {
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mainset/cli",
"version": "0.4.4",
"version": "0.5.0-rc.2",
"description": "A unified CLI tool for accelerating development, based on mainset vision of front-end infrastructure",
"homepage": "https://github.com/mainset/dev-stack-fe/tree/main/packages/cli",
"bugs": {
Expand All @@ -15,7 +15,8 @@
"type": "module",
"sideEffects": false,
"files": [
"dist"
"dist",
"src/commands/init/templates"
],
"exports": {
"./runtime": {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/index.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './init/index.mjs';
export * from './node-sourcer.mjs';
export * from './source-code.mjs';
export * from './web-app.mjs';
1 change: 1 addition & 0 deletions packages/cli/src/commands/init/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './init.mjs';
192 changes: 192 additions & 0 deletions packages/cli/src/commands/init/init.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import { Command } from 'commander';
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { stdin as input, stdout as output } from 'node:process';
import * as readline from 'node:readline/promises';

import { runtimePathById } from '../../runtime/index.mjs';
import {
consoleColorize,
initProcessCatchErrorLogger,
} from '../../utils/index.mjs';

async function handleConfigurationDependencies(targetDir: string) {
const rl = readline.createInterface({ input, output });

let shouldInstall = true;
try {
const answer = await rl.question(
'Do you want to install development dependencies (@mainset/dev-stack-fe etc.)? (Y/n) ',
);
shouldInstall = answer.trim().toLowerCase() !== 'n';
} catch {
// default true
}

if (shouldInstall) {
let packageManager = 'npm';
try {
const answer = await rl.question(
'Which package manager do you use? (npm/pnpm/yarn/bun/other) [npm]: ',
);
packageManager = answer.trim().toLowerCase() || 'npm';
} catch {
// default npm
}

rl.close();

let installCommand = '';
const packages = [
'@mainset/dev-stack-fe',
'@mainset/cli',
'cross-env',
'eslint',
'husky',
'prettier',
'stylelint',
].join(' ');

if (['npm', 'pnpm', 'yarn', 'bun'].includes(packageManager)) {
const cmd = packageManager === 'npm' ? 'install' : 'add';
installCommand = `${packageManager} ${cmd} -D ${packages}`;
} else {
// assume 'other' is the binary name user typed if not in basic list
installCommand = `${packageManager} i -D ${packages}`;
}

console.log(
consoleColorize(
'BLUE',
`\n\nInstalling dependencies with:\n${installCommand}\n`,
),
);

try {
execSync(installCommand, {
cwd: targetDir,
stdio: 'inherit',
env: { ...process.env, NODE_ENV: 'development' },
});
console.log(
consoleColorize('BRIGHT_GREEN', 'Dependencies installed successfully.'),
);
} catch (error) {
console.error(
consoleColorize(
'BRIGHT_RED',
`\n❌ Failed to install dependencies automatically.`,
),
);
console.log(
consoleColorize(
'BRIGHT_YELLOW',
`Please run the following command manually:\n\n ${installCommand}\n`,
),
);
}
// Close readline if not installing
} else {
rl.close();
}
}

function registerInitCommand(program: Command) {
program
.command('init [appName]')
.description('Run init project or configuration process')
.option(
'-m, --mode <type>',
'Initialization mode: app, package or config',
'application',
)
.option('-p, --path <relativePath>', 'Initialization path', './')
.action(async (appName, options) => {
// Use runtimePathById.root to resolve the target directory relative to the project root
const targetDir = path.resolve(
runtimePathById.root,
options.path,
appName || '',
);

if (options.mode === 'application') {
if (!appName) {
console.error(
consoleColorize(
'BRIGHT_RED',
`\n[mainset cli][init] App name is required for application initialization.`,
),
);
process.exit(1);
}

// ========== Application mode ==========
console.log('\n🏗️ [mainset cli] init: application');

try {
// Use runtimePathById.msCLISrc to resolve the template directory relative to the CLI runtime
const templateDir = path.resolve(
runtimePathById.msCLISrc,
'../../../src/commands/init/templates/application',
);

if (fs.existsSync(targetDir)) {
console.error(
consoleColorize(
'BRIGHT_YELLOW',
`\n[mainset cli][init] Directory "${appName}" already exists at "${targetDir}". Aborting.`,
),
);
process.exit(1);
}

fs.cpSync(templateDir, targetDir, { recursive: true });

console.log(
`\n✅ Application "${appName}" initialized successfully.\n`,
);
} catch (error) {
initProcessCatchErrorLogger('init', error, 'application');
}
} else if (options.mode === 'config') {
// ========== Configuration mode ==========
console.log('\n🏗️ [mainset cli] init: configuration');

try {
const templateDir = path.resolve(
runtimePathById.msCLISrc,
'../../../src/commands/init/templates/configuration',
);

if (!fs.existsSync(templateDir)) {
console.log(
consoleColorize(
'BRIGHT_YELLOW',
`\n[mainset cli][init] Configuration template not found at ${templateDir}`,
),
);
return;
}

fs.cpSync(templateDir, targetDir, { recursive: true });

console.log('\n✅ Configuration initialized successfully.\n');

await handleConfigurationDependencies(targetDir);
} catch (error) {
initProcessCatchErrorLogger('init', error, 'configuration');
}
} else {
console.error(
consoleColorize(
'BRIGHT_YELLOW',
`[mainset cli][init] Unknown init mode: "${options.mode}"`,
),
);
process.exit(1);
}
});
}

export { registerInitCommand };
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_REMOTE_URL=https://httpbin.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { SSRConfigParams } from '@mainset/cli/ssr-server';

declare const proxyConfigByPath: SSRConfigParams['proxyConfigByPath'];

export default proxyConfigByPath;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const proxyConfigByPath = {
'/api-example/': {
context: ['/api-example/'],
target: process.env.API_REMOTE_URL,
pathRewrite: { '^/api-example/': '/' },
changeOrigin: true,
},
};

export default proxyConfigByPath;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import proxyConfigByPath from './proxy.config.mjs';

const serveStaticConfig = {
proxyConfigByPath,
};

export default serveStaticConfig;
Loading
Loading