buner 1.0.5 → 1.0.7

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.
@@ -1,77 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import { execSync } from 'child_process';
3
- import path from 'path';
4
- import fs from 'fs';
5
-
6
- function isInGitRepository(): boolean {
7
- try {
8
- execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
9
-
10
- return true;
11
- } catch (_) {
12
- /* empty */
13
- }
14
-
15
- return false;
16
- }
17
-
18
- function isInMercurialRepository(): boolean {
19
- try {
20
- execSync('hg --cwd . root', { stdio: 'ignore' });
21
-
22
- return true;
23
- } catch (_) {
24
- /* empty */
25
- }
26
-
27
- return false;
28
- }
29
-
30
- function isDefaultBranchSet(): boolean {
31
- try {
32
- execSync('git config init.defaultBranch', { stdio: 'ignore' });
33
-
34
- return true;
35
- } catch (_) {
36
- /* empty */
37
- }
38
-
39
- return false;
40
- }
41
-
42
- const tryGitInit = (root: string): boolean => {
43
- let didInit = false;
44
-
45
- try {
46
- execSync('git --version', { stdio: 'ignore' });
47
- if (isInGitRepository() || isInMercurialRepository()) {
48
- return false;
49
- }
50
-
51
- execSync('git init', { stdio: 'ignore' });
52
- didInit = true;
53
-
54
- if (!isDefaultBranchSet()) {
55
- execSync('git checkout -b main', { stdio: 'ignore' });
56
- }
57
-
58
- execSync('git add -A', { stdio: 'ignore' });
59
- execSync('git commit -m "Initial commit from Create App"', {
60
- stdio: 'ignore',
61
- });
62
-
63
- return true;
64
- } catch (e) {
65
- if (didInit) {
66
- try {
67
- fs.rmSync(path.join(root, '.git'), { recursive: true, force: true });
68
- } catch (_) {
69
- /* empty */
70
- }
71
- }
72
-
73
- return false;
74
- }
75
- };
76
-
77
- export { tryGitInit };
@@ -1,26 +0,0 @@
1
- /* eslint-disable no-console */
2
- import { exec } from 'node:child_process';
3
-
4
- import chalk from 'chalk';
5
-
6
- const { red } = chalk;
7
-
8
- const install = async () => {
9
- return new Promise((resolve, reject) => {
10
- exec('npm install', (error, stdout) => {
11
- if (error) {
12
- reject(error);
13
-
14
- console.log(`${red(error)}`);
15
-
16
- return;
17
- }
18
-
19
- console.log(stdout);
20
-
21
- resolve(stdout);
22
- });
23
- });
24
- };
25
-
26
- export { install };
@@ -1,40 +0,0 @@
1
- import fs from 'fs';
2
-
3
- const isFolderEmpty = (root: string): boolean => {
4
- const validFiles = [
5
- '.DS_Store',
6
- '.git',
7
- '.gitattributes',
8
- '.gitignore',
9
- '.gitlab-ci.yml',
10
- '.hg',
11
- '.hgcheck',
12
- '.hgignore',
13
- '.idea',
14
- '.npmignore',
15
- '.travis.yml',
16
- 'LICENSE',
17
- 'Thumbs.db',
18
- 'docs',
19
- 'mkdocs.yml',
20
- 'npm-debug.log',
21
- 'yarn-debug.log',
22
- 'yarn-error.log',
23
- 'yarnrc.yml',
24
- '.yarn',
25
- ];
26
-
27
- const conflicts = fs
28
- .readdirSync(root)
29
- .filter((file) => !validFiles.includes(file))
30
- // Support IntelliJ IDEA-based editors
31
- .filter((file) => !/\.iml$/.test(file));
32
-
33
- if (conflicts.length > 0) {
34
- return false;
35
- }
36
-
37
- return true;
38
- };
39
-
40
- export { isFolderEmpty };
@@ -1,14 +0,0 @@
1
- import fs from 'fs';
2
-
3
- const isWriteable = async (directory: string): Promise<boolean> => {
4
- try {
5
- await fs.promises.access(directory, fs.constants.W_OK);
6
-
7
- return true;
8
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
- } catch (err) {
10
- return false;
11
- }
12
- };
13
-
14
- export { isWriteable };
@@ -1,7 +0,0 @@
1
- import fs from 'fs';
2
-
3
- const makeDir = (root: string, options = { recursive: true }): Promise<string | undefined> => {
4
- return fs.promises.mkdir(root, options);
5
- };
6
-
7
- export { makeDir };
@@ -1,17 +0,0 @@
1
- import validateProjectName from 'validate-npm-package-name';
2
-
3
- export function validateNpmName(name: string): {
4
- valid: boolean;
5
- problems?: string[];
6
- } {
7
- const nameValidation = validateProjectName(name);
8
-
9
- if (nameValidation.validForNewPackages && !name.startsWith('-')) {
10
- return { valid: true };
11
- }
12
-
13
- return {
14
- valid: false,
15
- problems: [...(nameValidation.errors || []), ...(nameValidation.warnings || [])],
16
- };
17
- }
@@ -1,72 +0,0 @@
1
- /* eslint-disable no-console */
2
- import fs from 'fs/promises';
3
- import path from 'path';
4
- import { fileURLToPath } from 'url';
5
- import os from 'os';
6
-
7
- import chalk from 'chalk';
8
-
9
- import { copy } from './helpers/copy.js';
10
- import { install } from './helpers/install.js';
11
- import { formatFiles } from './helpers/format-files.js';
12
- import packageJson_ from '../package.json';
13
-
14
- export const filename = fileURLToPath(import.meta.url);
15
- export const dirname = path.dirname(filename);
16
-
17
- interface Props {
18
- appName: string;
19
- root: string;
20
- }
21
-
22
- const { cyan } = chalk;
23
-
24
- const installTemplate = async (model: Props) => {
25
- const { appName, root } = model;
26
-
27
- console.log('\nInitializing project');
28
- const copySource = ['**'];
29
-
30
- await copy(copySource, root, {
31
- cwd: path.join(dirname, '..'),
32
- });
33
-
34
- await formatFiles(root);
35
-
36
- const packageJson = {
37
- name: appName,
38
- description: '',
39
- version: '0.1.0',
40
- type: 'module',
41
- private: true,
42
- scripts: {
43
- start: 'buner dev',
44
- dev: 'buner dev',
45
- serve: 'buner serve',
46
- build: 'buner build',
47
- generate: 'buner generate',
48
- eshn: 'buner eshn',
49
- inte: 'buner inte',
50
- styles: 'buner styles',
51
- prerender: 'buner prerender',
52
- },
53
- dependencies: {
54
- buner: `^${packageJson_.version}`,
55
- react: '^19.0.0',
56
- 'react-dom': '^19.0.0',
57
- 'react-router-dom': '^7.0.0',
58
- },
59
- };
60
-
61
- await fs.writeFile(path.join(root, 'package.json'), JSON.stringify(packageJson, null, 2) + os.EOL);
62
-
63
- console.log('\nInstalling dependencies:');
64
-
65
- for (const dependency in packageJson.dependencies) {
66
- console.log(`- ${cyan(dependency)}`);
67
- }
68
-
69
- await install();
70
- };
71
-
72
- export { installTemplate };
package/migrate-scss.ts DELETED
@@ -1,42 +0,0 @@
1
- /* eslint-disable no-console */
2
- import { execSync } from 'child_process';
3
-
4
- import { glob } from 'glob';
5
-
6
- const migration = async () => {
7
- const usableFiles = ['./xpack/styles/root.scss'];
8
-
9
- const forwardableFiles = [
10
- './src/assets/styles/style-base.scss',
11
- './src/assets/styles/style.all.scss',
12
- './src/assets/styles/00-abstracts/_abstracts.scss',
13
- './src/assets/styles/01-mixins/_mixins.scss',
14
- './src/assets/styles/02-base/_base.scss',
15
- ];
16
-
17
- for (const file of forwardableFiles) {
18
- try {
19
- console.log(`Migrating ${file}`);
20
- execSync(`bunx sass-migrator --migrate-deps module --forward=all ${file}`, { stdio: 'inherit' });
21
- } catch (err) {
22
- console.error((err as Error).message);
23
- }
24
- }
25
-
26
- const componentFiles = await glob(['./src/atoms/**/*.scss', './src/molecules/**/*.scss', './src/organisms/**/*.scss'], { nodir: true });
27
-
28
- const allFiles = [...usableFiles, ...componentFiles];
29
-
30
- for (const file of allFiles) {
31
- try {
32
- console.log(`Migrating ${file}`);
33
- execSync(`bunx sass-migrator module --migrate-deps ${file}`, { stdio: 'inherit' });
34
- } catch (err) {
35
- console.error((err as Error).message);
36
- }
37
- }
38
- };
39
-
40
- migration().catch((err) => {
41
- console.error('An error occurred during migration:', (err as Error).message);
42
- });
package/prerender.ts DELETED
@@ -1,229 +0,0 @@
1
- /* eslint-disable no-console */
2
- // Pre-render the app into static HTML.
3
- // run `npm run generate` and then `dist/static` can be served as a static site.
4
-
5
- import fs from 'fs';
6
- import path from 'path';
7
- import { pathToFileURL } from 'url';
8
- import crypto from 'node:crypto';
9
-
10
- import jsBeautify, { CSSBeautifyOptions, HTMLBeautifyOptions, JSBeautifyOptions } from 'js-beautify';
11
- import * as cheerio from 'cheerio';
12
- import slash from 'slash';
13
- import _ from 'lodash';
14
- import { loadEnv } from 'vite';
15
- import chalk from 'chalk';
16
-
17
- interface RenderedPage {
18
- name: string;
19
- url: string;
20
- fileName: string;
21
- }
22
- const argvModeIndex = process.argv.indexOf('--mode');
23
- const mode =
24
- argvModeIndex >= 0 && argvModeIndex < process.argv.length - 1 && !process.argv[argvModeIndex + 1].startsWith('-')
25
- ? process.argv[argvModeIndex + 1]
26
- : 'production';
27
-
28
- const projectRoot = process.cwd();
29
- const xpackEnv = loadEnv(mode, projectRoot);
30
- const toAbsolute = (p: string) => path.resolve(projectRoot, p);
31
- const log = console.log.bind(console);
32
-
33
- const template = fs.readFileSync(toAbsolute(process.env.VITE_TEMPLATE ?? 'dist/static/index.html'), 'utf-8');
34
- const { render, routesToPrerender } = await import(pathToFileURL(toAbsolute('./dist/server/entry-server.js')).href);
35
-
36
- const beautifyOptions: HTMLBeautifyOptions | JSBeautifyOptions | CSSBeautifyOptions = {
37
- indent_size: 2,
38
- indent_char: ' ',
39
- keep_array_indentation: false,
40
- break_chained_methods: false,
41
- indent_scripts: 'normal',
42
- brace_style: 'collapse',
43
- space_before_conditional: true,
44
- unescape_strings: false,
45
- jslint_happy: false,
46
- end_with_newline: false,
47
- wrap_line_length: 0,
48
- indent_inner_html: false,
49
- comma_first: false,
50
- e4x: false,
51
- indent_empty_lines: false,
52
- wrap_attributes: 'force',
53
- max_preserve_newlines: 5,
54
- preserve_newlines: true,
55
- };
56
-
57
- // determine routes to pre-render from src/pages
58
-
59
- const updateResourcePath = ($: cheerio.CheerioAPI, tagName: string, attr: string, addHash: boolean) => {
60
- $(tagName).each((_, el) => {
61
- const href = $(el).attr(attr);
62
-
63
- if (href && href.startsWith('/')) {
64
- let newPath = href;
65
-
66
- if (process.env.VITE_DOMAIN) {
67
- newPath = process.env.VITE_DOMAIN + newPath;
68
- }
69
-
70
- if (
71
- href.startsWith(xpackEnv.VITE_BASE_URL) &&
72
- !href.startsWith(xpackEnv.VITE_BASE_URL + 'assets/vendors/') &&
73
- ['.css', '.ico', '.js', '.webmanifest', '.svg'].includes(path.extname(href).toLowerCase()) &&
74
- !/\.0x[a-z0-9]{8}\.\w+$/gi.test(href)
75
- ) {
76
- const path = toAbsolute('dist/static/' + href.substring(xpackEnv.VITE_BASE_URL.length));
77
-
78
- if (fs.existsSync(path)) {
79
- const content = fs.readFileSync(path);
80
- const sha1Hash = crypto.createHash('sha1');
81
-
82
- sha1Hash.update(content);
83
- const hash = sha1Hash.digest('base64url').substring(0, 10);
84
-
85
- if (addHash) {
86
- newPath += '?v=' + hash;
87
- }
88
- } else if (path.endsWith('mock-api.js')) {
89
- // Skip
90
- } else {
91
- // Log warning
92
- log(chalk.yellow('Cannot find:', path));
93
- }
94
- }
95
-
96
- if (newPath != href) {
97
- $(el).attr(attr, newPath);
98
- }
99
- }
100
- });
101
- };
102
-
103
- const removeStyleBase = ($: cheerio.CheerioAPI) => {
104
- $('link[rel="stylesheet"]').each((_, el) => {
105
- const href = $(el).attr('href');
106
-
107
- if (href?.includes('style-base')) {
108
- $(el).remove();
109
- }
110
- });
111
- };
112
-
113
- const removeDuplicateAssets = ($: cheerio.CheerioAPI, selector: string, attr: string, paths: string[]) => {
114
- $(selector).each((_, el) => {
115
- if ($(el).attr('data-pl-inplace') === 'true') {
116
- return;
117
- }
118
-
119
- const path = $(el).attr(attr);
120
-
121
- if (!path) {
122
- return;
123
- }
124
-
125
- const index = $(el).index();
126
- const parent = $(el).parent().clone();
127
- const child = parent.children()[index];
128
-
129
- parent.empty();
130
- parent.append(child);
131
- const html = parent.html();
132
-
133
- $(el).after('\n<!-- ' + html + ' -->');
134
-
135
- if (paths.includes(path)) {
136
- $(el).remove();
137
-
138
- return;
139
- }
140
-
141
- paths.push(path);
142
-
143
- $(el).removeAttr('data-pl-require');
144
-
145
- if ($(el).attr('type') === 'module') {
146
- const deferValue = $(el).attr('defer');
147
-
148
- if ($(el).attr('defer') === '' || deferValue === 'defer' || deferValue === 'true') {
149
- $(el).removeAttr('defer');
150
- }
151
- }
152
-
153
- $('head').append(el);
154
- });
155
- };
156
-
157
- const viteAbsoluteUrl = (remain: string, addExtension = false): string => {
158
- const baseUrl = xpackEnv.VITE_BASE_URL;
159
- const normalizedRemain =
160
- (remain?.startsWith('/') ? remain : '/' + remain) + (addExtension && !remain.endsWith('/') ? (xpackEnv.VITE_PATH_EXTENSION ?? '') : '');
161
-
162
- if (!baseUrl) {
163
- return normalizedRemain;
164
- }
165
-
166
- if (!baseUrl.endsWith('/')) {
167
- return baseUrl + normalizedRemain;
168
- }
169
-
170
- const len = baseUrl.length;
171
-
172
- return baseUrl.substring(0, len - 1) + normalizedRemain;
173
- };
174
-
175
- const renderPage = async (renderedPages: RenderedPage[], addHash: boolean) => {
176
- // pre-render each route...
177
- for (const route of routesToPrerender) {
178
- const output = await render(viteAbsoluteUrl(route.route, true));
179
-
180
- const destLocalizedFolderPath = toAbsolute('dist/static');
181
-
182
- let html = template.replace('<!--app-html-->', output.html ?? '').replace('@style.scss', '/assets/css/' + route.name + '.css');
183
- const $ = cheerio.load(html);
184
- const paths: string[] = [];
185
-
186
- removeDuplicateAssets($, 'link[data-pl-require][href]', 'href', paths);
187
- removeDuplicateAssets($, 'script[data-pl-require][src]', 'src', paths);
188
- updateResourcePath($, 'link', 'href', addHash);
189
- updateResourcePath($, 'script', 'src', addHash);
190
- updateResourcePath($, 'img', 'src', addHash);
191
- if (route.route === '/') {
192
- removeStyleBase($);
193
- }
194
-
195
- $('head title').text(route.name);
196
-
197
- const fileName = (route.route === '/' ? '/index' : route.route) + '.html';
198
- const filePath = `${destLocalizedFolderPath}${fileName}`;
199
-
200
- if (!fs.existsSync(path.dirname(filePath))) {
201
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
202
- }
203
-
204
- html = $.html();
205
-
206
- html = jsBeautify.html_beautify(html, beautifyOptions);
207
- html = html.replace('/* app-styles */', output.styles);
208
-
209
- fs.writeFileSync(toAbsolute(filePath), html);
210
- log('pre-rendered:', slash(filePath));
211
-
212
- renderedPages.push({
213
- name: _.kebabCase(fileName.replaceAll(/\.\w+$/gi, '')),
214
- url: `${process.env.VITE_DOMAIN ?? ''}${fileName}`,
215
- fileName: fileName,
216
- });
217
- }
218
- };
219
-
220
- (async () => {
221
- const renderedPages: RenderedPage[] = [];
222
- const pool: Promise<unknown>[] = [];
223
-
224
- const addHash = !!process.argv.includes('--add-hash');
225
-
226
- pool.push(renderPage(renderedPages, addHash));
227
-
228
- await Promise.all(pool);
229
- })();
package/scripts.ts DELETED
@@ -1,56 +0,0 @@
1
- /* eslint-disable no-console */
2
- import fs from 'fs';
3
- import path from 'path';
4
-
5
- import chokidar from 'chokidar';
6
- import { glob } from 'glob';
7
- import slash from 'slash';
8
- import { transformWithEsbuild } from 'vite';
9
-
10
- const log = console.log.bind(console);
11
-
12
- const scriptCompile = async (inputPath: string) => {
13
- console.log('compile:', slash(inputPath));
14
-
15
- const code = fs.readFileSync(inputPath, 'utf8');
16
-
17
- return transformWithEsbuild(code, inputPath, {
18
- minify: true,
19
- format: 'esm',
20
- sourcemap: path.basename(inputPath).includes('critical') ? false : 'external',
21
- })
22
- .then((result) => {
23
- const savePath = path.resolve('public/assets/js/' + path.parse(inputPath).name + '.js');
24
- const saveDir = path.dirname(savePath);
25
-
26
- if (!fs.existsSync(saveDir)) {
27
- fs.mkdirSync(saveDir);
28
- }
29
-
30
- fs.writeFileSync(savePath, result.code);
31
- })
32
- .catch((error) => {
33
- log(error);
34
- });
35
- };
36
-
37
- const run = async () => {
38
- if (process.argv.includes('--watch')) {
39
- const watcher = chokidar.watch('src/assets/scripts/**/*.{js,jsx,ts,tsx}');
40
-
41
- watcher
42
- .on('add', scriptCompile)
43
- .on('change', scriptCompile)
44
- .on('unlink', (path) => log(`File ${path} has been removed`));
45
- } else {
46
- const pool: Promise<any>[] = [];
47
-
48
- glob.sync('src/assets/scripts/**/*.{js,jsx,ts,tsx}').forEach((p) => pool.push(scriptCompile(p)));
49
-
50
- await Promise.all(pool);
51
- }
52
- };
53
-
54
- await run();
55
-
56
- export {};
package/server.ts DELETED
@@ -1,29 +0,0 @@
1
- /* eslint-disable no-console */
2
- import path from 'path';
3
-
4
- import { loadEnv } from 'vite';
5
-
6
- import { startServer } from './xpack/create-server.js';
7
-
8
- console.log('[INIT] server');
9
-
10
- const argvModeIndex = process.argv.indexOf('--mode');
11
- const mode =
12
- argvModeIndex >= 0 && argvModeIndex < process.argv.length - 1 && !process.argv[argvModeIndex + 1].startsWith('-')
13
- ? process.argv[argvModeIndex + 1]
14
- : 'production';
15
- const root = process.cwd();
16
- const xpackEnv = loadEnv(mode, root);
17
- const isTest = !!xpackEnv.VITE_TEST_BUILD || process.env.NODE_ENV === 'test';
18
- const port = xpackEnv.VITE_PORT ? parseInt(xpackEnv.VITE_PORT) : 5000;
19
-
20
- if (!isTest) {
21
- console.log(root);
22
- startServer({
23
- root,
24
- isTest,
25
- port,
26
- hmrPort: port + 1,
27
- baseUrl: xpackEnv.VITE_BASE_URL,
28
- });
29
- }
package/states.ts DELETED
@@ -1,63 +0,0 @@
1
- /* eslint-disable no-console */
2
- import fs from 'fs';
3
-
4
- import chokidar from 'chokidar';
5
- import debounce from 'debounce';
6
- import { glob } from 'glob';
7
-
8
- const isWatch = process.argv.includes('--watch');
9
- const log = console.log.bind(console);
10
-
11
- const states: { [path: string]: string } = {};
12
-
13
- const buildStates = debounce(() => {
14
- const output: any[] = [];
15
-
16
- const keys = Object.keys(states);
17
-
18
- [].forEach.call(keys, (key) => {
19
- const state = states[key];
20
-
21
- if (!state) {
22
- return;
23
- }
24
-
25
- try {
26
- output.push(JSON.parse(state));
27
- } catch (error: any) {
28
- console.log(error);
29
- }
30
- });
31
-
32
- const json = JSON.stringify(output, null, ' ');
33
-
34
- fs.writeFileSync('public/pl-states.json', json);
35
- }, 500);
36
-
37
- const setStates = (statePath: string) => {
38
- const state = fs.readFileSync(statePath, 'utf-8');
39
-
40
- states[statePath] = state;
41
- buildStates();
42
- };
43
-
44
- const removeStates = (statePath: string) => {
45
- delete states[statePath];
46
- buildStates();
47
- };
48
-
49
- if (isWatch) {
50
- const watcher = chokidar.watch('src/**/*.states.json');
51
-
52
- watcher
53
- .on('ready', () => {
54
- log('States are ready!');
55
- })
56
- .on('add', (path) => setStates(path))
57
- .on('change', (path) => setStates(path))
58
- .on('unlink', (path) => removeStates(path));
59
- } else {
60
- glob.sync('src/**/*.states.json').forEach((path) => setStates(path));
61
- }
62
-
63
- export {};