@nice-move/init 0.3.12 → 0.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nice-move/init",
3
- "version": "0.3.12",
3
+ "version": "0.5.0",
4
4
  "description": "Initialize your frontend workspaces",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -36,30 +36,33 @@
36
36
  "url": "https://github.com/nice-move/nice-move/issues"
37
37
  },
38
38
  "bin": {
39
- "nice-move-init": "bin/index.mjs"
39
+ "nice-move-init": "dist/cli.mjs"
40
40
  },
41
- "main": "index.mjs",
42
- "dependencies": {
41
+ "files": [],
42
+ "scripts": {
43
+ "build": "best-shot prod",
44
+ "prepublishOnly": "npm run build"
45
+ },
46
+ "devDependencies": {
43
47
  "centra": "^2.5.0",
44
- "chalk": "^4.1.2",
48
+ "chalk": "^5.0.1",
49
+ "cheetor": "^0.13.0",
45
50
  "deepmerge": "^4.2.2",
46
- "execa": "^6.0.0",
47
- "fs-chain": "^8.1.1",
51
+ "execa": "^6.1.0",
52
+ "fs-chain": "^8.2.1",
48
53
  "is-git-dirty": "^2.0.1",
49
54
  "is-git-repository": "^2.0.0",
50
- "ora": "^6.0.1",
51
- "os-locale": "^6.0.1",
55
+ "ora": "^6.1.0",
56
+ "os-locale": "^6.0.2",
52
57
  "parse-author": "^2.0.0",
53
58
  "prompts": "^2.4.2",
54
59
  "semver-regex": "^4.0.2",
55
- "settingz": "^0.1.0",
56
60
  "stringify-author": "^0.1.3",
57
- "user-meta": "^1.0.0",
58
61
  "validate-npm-package-name": "^3.0.0",
59
62
  "yarn-install": "^1.0.0"
60
63
  },
61
64
  "engines": {
62
- "node": "^12.22.0 || ^14.17.0 || >=16.13.0"
65
+ "node": "^14.17.0 || >=16.13.0"
63
66
  },
64
67
  "publishConfig": {
65
68
  "access": "public",
@@ -1,11 +0,0 @@
1
- import { Text } from 'fs-chain';
2
-
3
- import { cyan } from '../lib/color.mjs';
4
-
5
- export function EditorConfig() {
6
- return new Text()
7
- .source('../../template/.editorconfig.tpl', import.meta.url)
8
- .output('.editorconfig')
9
- .logger('Create/Overwrite', cyan('.editorconfig'))
10
- .catch(console.warn);
11
- }
@@ -1,89 +0,0 @@
1
- import { type } from 'os';
2
-
3
- import { Text } from 'fs-chain';
4
- import ora from 'ora';
5
-
6
- import { cyan, green, red } from '../lib/color.mjs';
7
- import { download } from '../lib/utils.mjs';
8
-
9
- const regexp =
10
- /# Created by https?:\/\/(www\.)?(toptal\.com\/developers\/gitignore|gitignore\.io)\/api\/\S+[\S\s]+# End of https?:\/\/(www\.)?(toptal\.com\/developers\/gitignore|gitignore\.io)\/api\/\S+/;
11
-
12
- const Types = {
13
- Windows_NT: 'windows',
14
- Linux: 'linux',
15
- Darwin: 'macos',
16
- };
17
-
18
- function getPlatform(context) {
19
- try {
20
- if (regexp.test(context)) {
21
- return [
22
- ...new Set([
23
- ...context
24
- .match(/gitignore\.io\/api\/(\S+)/)[1]
25
- .split(',')
26
- .filter((item) => item !== 'node'),
27
- Types[type()],
28
- ]),
29
- ].sort();
30
- }
31
- throw new Error('fail');
32
- } catch {
33
- return Types[type()];
34
- }
35
- }
36
-
37
- export async function GitFile() {
38
- await new Text()
39
- .source('../../template/.gitattributes.tpl', import.meta.url)
40
- .output('.gitattributes')
41
- .logger('Create/Overwrite', cyan('.gitattributes'));
42
-
43
- const spinner = ora({
44
- text: 'Downloading template from `gitignore.io`',
45
- }).start();
46
-
47
- const message = `Create/Overwrite ${cyan('.gitignore')}`;
48
-
49
- return new Text()
50
- .source('.gitignore')
51
- .onFail()
52
- .onDone((oldText = '') => {
53
- const platform = getPlatform(oldText);
54
- return download(`https://gitignore.io/api/node,${platform}`)
55
- .then((newText) => {
56
- const [match] = oldText.match(regexp) || [];
57
-
58
- const io = (
59
- match
60
- ? oldText.replace(regexp, newText)
61
- : `${oldText.trim()}\n\n${newText}`
62
- )
63
- .replace(
64
- /(www\.)?toptal\.com\/developers\/gitignore/g,
65
- 'gitignore.io',
66
- )
67
- .trim()
68
- .split(/\n\n\+/g)
69
- .filter((item) => item.trim())
70
- .join('\n\n');
71
-
72
- return `${io}\n`;
73
- })
74
- .catch(() => oldText || 'node_modules\n');
75
- })
76
- .output()
77
- .then(() => {
78
- spinner.stopAndPersist({
79
- symbol: green('√'),
80
- text: message,
81
- });
82
- })
83
- .catch((error) => {
84
- spinner.stopAndPersist({
85
- symbol: red('×'),
86
- text: `${message} - ${error.message}`,
87
- });
88
- });
89
- }
@@ -1,31 +0,0 @@
1
- import { Text } from 'fs-chain';
2
- import { getPkg } from 'settingz';
3
-
4
- import { cyan } from '../lib/color.mjs';
5
- import { getAuthorName } from '../lib/utils.mjs';
6
-
7
- export async function License() {
8
- const { license, author = '' } = getPkg();
9
-
10
- const isMIT = license === 'MIT';
11
-
12
- if (isMIT || license === 'Unlicense') {
13
- const holder = await getAuthorName(author);
14
-
15
- return new Text()
16
- .source(
17
- isMIT ? '../../template/mit.tpl' : '../../template/unlicense.tpl',
18
- import.meta.url,
19
- )
20
- .onDone((text) =>
21
- isMIT
22
- ? text
23
- .replace('{{year}}', new Date().getFullYear())
24
- .replace('{{holder}}', holder)
25
- : text,
26
- )
27
- .output('LICENSE')
28
- .logger('Create/Overwrite', cyan('LICENSE'))
29
- .catch(console.warn);
30
- }
31
- }
@@ -1,35 +0,0 @@
1
- import deepmerge from 'deepmerge';
2
- import { Json } from 'fs-chain';
3
-
4
- import { cyan } from '../lib/color.mjs';
5
- import latest from '../lib/latest.mjs';
6
-
7
- const pkg = 'package.json';
8
-
9
- export function Package(info) {
10
- return new Json()
11
- .config({ pretty: true })
12
- .source(pkg)
13
- .onFail()
14
- .onDone((old = {}) =>
15
- deepmerge.all([
16
- {
17
- engines: {
18
- node: latest.lts,
19
- },
20
- publishConfig:
21
- info.private || old.private
22
- ? undefined
23
- : {
24
- access: 'public',
25
- registry: 'https://registry.npmjs.org/',
26
- },
27
- },
28
- old,
29
- info,
30
- ]),
31
- )
32
- .output()
33
- .logger('Add project info to', cyan(pkg))
34
- .catch(console.warn);
35
- }
package/action/readme.mjs DELETED
@@ -1,22 +0,0 @@
1
- import { Text } from 'fs-chain';
2
- import { getPkg } from 'settingz';
3
-
4
- import { cyan } from '../lib/color.mjs';
5
-
6
- export async function Readme() {
7
- const { name, description } = getPkg();
8
-
9
- new Text()
10
- .source('README.md')
11
- .onFail()
12
- .onDone((text) =>
13
- !text
14
- ? [`# ${name}`, description ? `${description}.\n` : '']
15
- .filter(Boolean)
16
- .join('\n\n')
17
- : text,
18
- )
19
- .output()
20
- .logger('Create', cyan('README.md'))
21
- .catch(console.warn);
22
- }
@@ -1,28 +0,0 @@
1
- import { Text } from 'fs-chain';
2
- import { osLocale } from 'os-locale';
3
-
4
- import { cyan } from '../lib/color.mjs';
5
-
6
- export async function Registry() {
7
- const InChina = (await osLocale()) === 'zh-CN';
8
-
9
- if (InChina) {
10
- new Text()
11
- .source('.npmrc')
12
- .onFail()
13
- .onDone((text = '') => {
14
- if (
15
- text.trim() &&
16
- /registry\s*=\s*["']?https:\/\/mirrors\.tencent\.com\/npm\/["']?/i.test(
17
- text,
18
- )
19
- ) {
20
- return text;
21
- }
22
- return `registry = https://mirrors.tencent.com/npm/\r${text}`;
23
- })
24
- .output()
25
- .logger('Set registry to China mirror in', cyan('.npmrc'))
26
- .catch(console.warn);
27
- }
28
- }
package/bin/index.mjs DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { init } from '../index.mjs';
4
-
5
- const io = init();
6
-
7
- if (io && io.catch) {
8
- io.catch((error) => {
9
- if (error.message !== 'cancel') {
10
- throw error;
11
- }
12
- });
13
- }
package/index.mjs DELETED
@@ -1,41 +0,0 @@
1
- import { EditorConfig } from './action/editorconfig.mjs';
2
- import { GitFile } from './action/git-file.mjs';
3
- import { License } from './action/license.mjs';
4
- import { Package } from './action/package.mjs';
5
- import { Readme } from './action/readme.mjs';
6
- import { Registry } from './action/registry.mjs';
7
- import { Prompt } from './prompt/index.mjs';
8
-
9
- export async function init() {
10
- const {
11
- Dependencies,
12
- GitInit,
13
- Install,
14
- info,
15
- options: { isGit } = {},
16
- } = await Prompt();
17
-
18
- console.log('-'.repeat(32));
19
-
20
- const actions = [
21
- GitInit,
22
- Registry,
23
- () => Package(info),
24
- Readme,
25
- License,
26
- EditorConfig,
27
- () => (GitInit || isGit ? GitFile() : undefined),
28
- () => (Dependencies ? Dependencies(GitInit || isGit) : undefined),
29
- Install,
30
- ].filter((func) => typeof func === 'function');
31
-
32
- for (const action of actions) {
33
- // eslint-disable-next-line no-await-in-loop
34
- const io = await action();
35
- if (io && io.catch) {
36
- io.catch((error) => {
37
- console.warn(error.message);
38
- });
39
- }
40
- }
41
- }
package/lib/color.mjs DELETED
@@ -1,3 +0,0 @@
1
- import chalk from 'chalk';
2
-
3
- export const { cyan, red, green } = chalk;
package/lib/latest.mjs DELETED
@@ -1,25 +0,0 @@
1
- export default {
2
- ava: '^3.15.0',
3
- commitlint: '^15.0.0',
4
- eslint: '^7.32.0',
5
- 'eslint-plugin-ava': '^13.1.0',
6
- garou: '^0.2.7',
7
- prettier: '^2.4.1',
8
- stylelint: '^14.1.0',
9
- typescript: '^4.5.2',
10
- '@bring-it/cli': '^0.5.6',
11
- '@playwright/test': '^1.16.3',
12
- '@types/react': '^16.14.21',
13
- postcss: '^8.3.11',
14
- react: '~16.14.0',
15
- 'react-dom': '~16.14.0',
16
- rustywind: '^0.12.2',
17
- tailwindcss: '~2.2.19',
18
- vue: '~2.6.14',
19
- 'eslint-config-base': '^0.5.69',
20
- 'stylelint-config': '^0.6.10',
21
- 'prettier-config': '^0.5.1',
22
- 'commitlint-config': '^0.4.0',
23
- cli: '^0.6.0',
24
- lts: '^12.22.0 || ^14.17.0 || >=16.13.0',
25
- };
package/lib/utils.mjs DELETED
@@ -1,61 +0,0 @@
1
- import { readdirSync } from 'fs';
2
-
3
- import centra from 'centra';
4
- import { execa } from 'execa';
5
- import stringify from 'stringify-author';
6
-
7
- export function download(url) {
8
- return centra(url)
9
- .timeout(5000)
10
- .send()
11
- .then((response) => {
12
- if (response.statusCode === 301) {
13
- return download(response.headers.location);
14
- }
15
- return response.text();
16
- })
17
- .then((response) => {
18
- const data = response.trim();
19
- if (data) {
20
- return data;
21
- }
22
- throw new Error('template download fail');
23
- });
24
- }
25
-
26
- export async function gitSupport() {
27
- try {
28
- const { stdout } = await execa('git', ['--version']);
29
- return Boolean(stdout);
30
- } catch {
31
- return false;
32
- }
33
- }
34
-
35
- export function emptyDir() {
36
- return readdirSync(process.cwd()).length === 0;
37
- }
38
-
39
- export function trim(value) {
40
- return value ? value.trim() : undefined;
41
- }
42
-
43
- function getUser() {
44
- return import('user-meta')
45
- .then(({ default: meta }) => meta)
46
- .catch(() => ({}));
47
- }
48
-
49
- export async function getAuthor(author) {
50
- if (author) {
51
- return author;
52
- }
53
-
54
- const meta = await getUser();
55
-
56
- return meta.name ? stringify(meta) : 'Unknown';
57
- }
58
-
59
- export async function getAuthorName(author) {
60
- return (await getAuthor(author)).name || 'Unknown';
61
- }
@@ -1,237 +0,0 @@
1
- import deepmerge from 'deepmerge';
2
- import { Json, Text } from 'fs-chain';
3
- import { getPkg } from 'settingz';
4
-
5
- import latest from '../lib/latest.mjs';
6
-
7
- function checkEslint({ vue, react }) {
8
- const type =
9
- (react && vue) || (!react && !vue) ? 'base' : react ? 'react' : 'vue';
10
-
11
- return {
12
- eslintConfig: {
13
- extends: `@nice-move/eslint-config-${type}`,
14
- },
15
- devDependencies: {
16
- [`@nice-move/eslint-config-${type}`]: latest['eslint-config-base'],
17
- eslint: latest.eslint,
18
- },
19
- };
20
- }
21
-
22
- const message = 'Add/Reset project dependencies';
23
-
24
- function action(isGit, wanted = {}) {
25
- return new Json()
26
- .config({ pretty: true })
27
- .source('package.json')
28
- .onFail()
29
- .onDone(async (old = {}) => {
30
- const { devDependencies = {}, dependencies = {} } = old;
31
- const {
32
- ava = 'ava' in devDependencies,
33
- commitlint = 'commitlint' in devDependencies,
34
- eslint = 'eslint' in devDependencies,
35
- garou = 'garou' in devDependencies,
36
- prettier = 'prettier' in devDependencies,
37
- react = 'react' in dependencies,
38
- stylelint = 'stylelint' in devDependencies,
39
- typescript = 'typescript' in devDependencies,
40
- vue = 'vue' in dependencies,
41
- tailwindcss = 'tailwindcss' in dependencies ||
42
- 'tailwindcss' in devDependencies,
43
- rustywind = 'rustywind' in devDependencies,
44
- postcss = 'postcss' in devDependencies,
45
- playwright = '@playwright/test' in devDependencies,
46
- 'bring-it': bringIt = '@bring-it/cli' in devDependencies,
47
- } = wanted;
48
-
49
- const useLint = eslint || stylelint || prettier || garou;
50
-
51
- const prepublishOnly = [
52
- useLint ? 'npm run lint' : undefined,
53
- ava ? 'npm test' : undefined,
54
- ].filter(Boolean);
55
-
56
- if (prepublishOnly.length > 0) {
57
- await new Text()
58
- .onDone(() => ['#!/bin/sh', '', ...prepublishOnly, ''].join('\n'))
59
- .output('.githooks/pre-commit');
60
- }
61
-
62
- if (commitlint) {
63
- await new Text()
64
- .onDone(() =>
65
- ['#!/bin/sh', '', 'npx --no-install commitlint -e', ''].join('\n'),
66
- )
67
- .output('.githooks/commit-msg');
68
- }
69
-
70
- return deepmerge.all(
71
- [
72
- old,
73
- isGit && (useLint || ava || commitlint)
74
- ? {
75
- scripts: {
76
- prepare: 'git config core.hooksPath .githooks',
77
- },
78
- }
79
- : undefined,
80
- garou
81
- ? {
82
- devDependencies: {
83
- garou: latest.garou,
84
- },
85
- }
86
- : undefined,
87
- typescript
88
- ? {
89
- devDependencies: {
90
- typescript: latest.typescript,
91
- },
92
- }
93
- : undefined,
94
- commitlint
95
- ? {
96
- commitlint: {
97
- extends: '@nice-move/commitlint-config',
98
- },
99
- devDependencies: {
100
- commitlint: latest.commitlint,
101
- '@nice-move/commitlint-config': latest['commitlint-config'],
102
- },
103
- }
104
- : undefined,
105
- useLint
106
- ? {
107
- devDependencies: {
108
- '@nice-move/cli': latest.cli,
109
- },
110
- scripts: {
111
- lint: 'nice-move lint',
112
- },
113
- }
114
- : undefined,
115
- ava
116
- ? {
117
- devDependencies: {
118
- ava: latest.ava,
119
- ...(eslint
120
- ? {
121
- 'eslint-plugin-ava': latest['eslint-plugin-ava'],
122
- }
123
- : undefined),
124
- },
125
- scripts: {
126
- prepublishOnly: old.private
127
- ? undefined
128
- : prepublishOnly.join(' && ') || undefined,
129
- test: 'ava --fail-fast',
130
- },
131
- }
132
- : undefined,
133
- eslint ? checkEslint({ react, vue }) : undefined,
134
- stylelint
135
- ? {
136
- devDependencies: {
137
- '@nice-move/stylelint-config': latest['stylelint-config'],
138
- stylelint: latest.stylelint,
139
- },
140
- stylelint: {
141
- extends: '@nice-move/stylelint-config',
142
- },
143
- }
144
- : undefined,
145
- prettier
146
- ? {
147
- devDependencies: {
148
- '@nice-move/prettier-config': latest['prettier-config'],
149
- prettier: latest.prettier,
150
- },
151
- prettier: '@nice-move/prettier-config',
152
- }
153
- : undefined,
154
- react
155
- ? {
156
- dependencies: {
157
- react: latest.react,
158
- 'react-dom': latest['react-dom'],
159
- },
160
- devDependencies: { '@types/react': latest['@types/react'] },
161
- }
162
- : undefined,
163
- vue ? { dependencies: { vue: latest.vue } } : undefined,
164
- tailwindcss
165
- ? { dependencies: { tailwindcss: latest.tailwindcss } }
166
- : undefined,
167
- rustywind
168
- ? { devDependencies: { tailwindcss: latest.rustywind } }
169
- : undefined,
170
- postcss
171
- ? { devDependencies: { postcss: latest.postcss } }
172
- : undefined,
173
- playwright
174
- ? {
175
- devDependencies: {
176
- '@playwright/test': latest['@playwright/test'],
177
- },
178
- }
179
- : undefined,
180
- bringIt
181
- ? {
182
- devDependencies: {
183
- '@bring-it/cli': latest['@bring-it/cli'],
184
- },
185
- }
186
- : undefined,
187
- ].filter(Boolean),
188
- );
189
- })
190
- .output()
191
- .logger(message)
192
- .catch(console.warn);
193
- }
194
-
195
- export function Dependencies() {
196
- const list = [
197
- 'react',
198
- 'vue',
199
- 'typescript',
200
- 'commitlint',
201
- 'eslint',
202
- 'stylelint',
203
- 'prettier',
204
- 'garou',
205
- 'rustywind',
206
- 'ava',
207
- 'playwright',
208
- 'bring-it',
209
- 'postcss',
210
- 'tailwindcss',
211
- ];
212
-
213
- const { dependencies = {}, devDependencies = {} } = getPkg();
214
-
215
- return {
216
- instructions: false,
217
- optionsPerPage: 20,
218
- message,
219
- name: 'Dependencies',
220
- type: (first) => (first === false ? null : 'multiselect'),
221
- choices: list.map((item) => ({
222
- title: item,
223
- value: item,
224
- selected: item in dependencies || item in devDependencies,
225
- })),
226
- // eslint-disable-next-line consistent-return
227
- format: (keywords) => {
228
- if (keywords.length > 0) {
229
- return (isGit) =>
230
- action(
231
- isGit,
232
- Object.fromEntries(keywords.map((item) => [item, true])),
233
- );
234
- }
235
- },
236
- };
237
- }
@@ -1,34 +0,0 @@
1
- import { execa } from 'execa';
2
-
3
- import { green, red } from '../lib/color.mjs';
4
-
5
- const message = 'Initialize as git repository';
6
-
7
- function init() {
8
- return execa('git', ['init']).then(
9
- (io) => {
10
- console.log(green('√'), message);
11
- return io;
12
- },
13
- (error) => {
14
- console.log(red('×'), message);
15
- throw error;
16
- },
17
- );
18
- }
19
-
20
- export function GitInit({ gitSupported, isGit }) {
21
- return {
22
- message,
23
- name: 'GitInit',
24
- initial: true,
25
- type: (first) =>
26
- first === false || !gitSupported || isGit ? null : 'confirm',
27
- // eslint-disable-next-line consistent-return
28
- format(value) {
29
- if (value === true) {
30
- return init;
31
- }
32
- },
33
- };
34
- }