@d-zero/create-frontend 5.0.0-alpha.10

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/CHANGELOG.md ADDED
@@ -0,0 +1,52 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [5.0.0-alpha.10](https://github.com/d-zero-dev/frontend-env/compare/v5.0.0-alpha.9...v5.0.0-alpha.10) (2024-06-11)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **scaffold:** 生成ファイルや静的ファイルがリント対象となっていたため除外設定を追加 ([0938636](https://github.com/d-zero-dev/frontend-env/commit/0938636ec260337914eaa4d0ab98aead709164fc))
11
+
12
+ # [5.0.0-alpha.9](https://github.com/d-zero-dev/frontend-env/compare/v5.0.0-alpha.8...v5.0.0-alpha.9) (2024-06-10)
13
+
14
+ **Note:** Version bump only for package @d-zero/create-frontend
15
+
16
+ # [5.0.0-alpha.8](https://github.com/d-zero-dev/frontend-env/compare/v5.0.0-alpha.7...v5.0.0-alpha.8) (2024-05-23)
17
+
18
+ **Note:** Version bump only for package @d-zero/create-frontend
19
+
20
+ # [5.0.0-alpha.7](https://github.com/d-zero-dev/frontend-env/compare/v5.0.0-alpha.6...v5.0.0-alpha.7) (2024-05-14)
21
+
22
+ **Note:** Version bump only for package @d-zero/create-frontend
23
+
24
+ # [5.0.0-alpha.6](https://github.com/d-zero-dev/frontend-env/compare/v5.0.0-alpha.5...v5.0.0-alpha.6) (2024-05-14)
25
+
26
+ ### Bug Fixes
27
+
28
+ - **repo:** fix each version ([50d50ad](https://github.com/d-zero-dev/frontend-env/commit/50d50adc605b700389e2945d03b72c5c4a00495a))
29
+
30
+ # [5.0.0-alpha.5](https://github.com/d-zero-dev/frontend-env/compare/v5.0.0-alpha.4...v5.0.0-alpha.5) (2024-05-14)
31
+
32
+ **Note:** Version bump only for package @d-zero/create-frontend
33
+
34
+ # [5.0.0-alpha.4](https://github.com/d-zero-dev/frontend-env/compare/v5.0.0-alpha.2...v5.0.0-alpha.4) (2024-05-14)
35
+
36
+ **Note:** Version bump only for package @d-zero/create-frontend
37
+
38
+ # [5.0.0-alpha.2](https://github.com/d-zero-dev/frontend-env/compare/v5.0.0-alpha.1...v5.0.0-alpha.2) (2024-05-14)
39
+
40
+ ### Bug Fixes
41
+
42
+ - **create-frontend:** fix to read `.gitignore` safely ([b192aa4](https://github.com/d-zero-dev/frontend-env/commit/b192aa4655413b75ee8830163198f016754277c9))
43
+
44
+ ### Features
45
+
46
+ - **create-frontend:** transform `package.json` as private package ([d0bcbb5](https://github.com/d-zero-dev/frontend-env/commit/d0bcbb57ecb06d850e826b3fb43781aa6716f1e3))
47
+
48
+ # 5.0.0-alpha.1 (2024-05-14)
49
+
50
+ ### Features
51
+
52
+ - **repo:** first commit ([8d3d8e5](https://github.com/d-zero-dev/frontend-env/commit/8d3d8e54ba047d5431b958d7f28af026357a4886))
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # ディーゼロ フロントエンド開発環境インストーラー
2
+
3
+ ## 使い方
4
+
5
+ ### 環境のインストール
6
+
7
+ 空のリポジトリで次のパッケージを実行します。
8
+
9
+ ```shell
10
+ npx @d-zero/create-frontend
11
+
12
+ # もしくは
13
+
14
+ yarn create @d-zero/frontend
15
+ ```
16
+
17
+ インストールで展開されるファイルは[`@d-zero/scaffold`](https://github.com/d-zero-dev/frontend-env/blob/main/packages/%40d-zero/scaffold/)に格納されています。
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ import { Plop, run } from 'plop';
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+
9
+ Plop.prepare(
10
+ {
11
+ configPath: path.join(__dirname, 'plopfile.js'),
12
+ },
13
+ (env) =>
14
+ Plop.execute(
15
+ {
16
+ ...env,
17
+ dest: process.cwd(),
18
+ },
19
+ run,
20
+ ),
21
+ );
package/index.spec.js ADDED
@@ -0,0 +1,119 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+
5
+ import { execa } from 'execa';
6
+ import { describe, test, expect, beforeEach } from 'vitest';
7
+
8
+ function getName(task) {
9
+ return encodeURIComponent(`${task.suite.name}_${task.name}`.toLowerCase());
10
+ }
11
+
12
+ beforeEach((ctx) => {
13
+ ctx.tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'test-'));
14
+ });
15
+
16
+ describe('CLI', () => {
17
+ test('npx', async ({ tmpDir, task }) => {
18
+ const dir = path.join(tmpDir, getName(task));
19
+ const { stdout } = await execa(
20
+ 'npx',
21
+ [
22
+ '@d-zero/create-frontend',
23
+ '--type',
24
+ 'burger',
25
+ '--dir',
26
+ dir,
27
+ '--no-install',
28
+ '--silent',
29
+ ],
30
+ {
31
+ failed: true,
32
+ env: {
33
+ NODE_NO_WARNINGS: '1',
34
+ },
35
+ },
36
+ );
37
+ expect(stdout.replaceAll(path.sep, '/').split('\n')).toStrictEqual([
38
+ `✔ ++ ${dir}/tsconfig.json`,
39
+ `✔ ++ ${dir}/package.json`,
40
+ `✔ ++ ${dir}/lint-staged.config.mjs`,
41
+ `✔ ++ ${dir}/eleventy.config.cjs`,
42
+ `✔ ++ ${dir}/cspell.json`,
43
+ `✔ ++ ${dir}/README.md`,
44
+ `✔ ++ ${dir}/CHANGELOG.md`,
45
+ `✔ ++ ${dir}/.textlintrc.js`,
46
+ `✔ ++ ${dir}/.stylelintrc`,
47
+ `✔ ++ ${dir}/.pug-lintrc`,
48
+ `✔ ++ ${dir}/.prettierrc.mjs`,
49
+ `✔ ++ ${dir}/.prettierignore`,
50
+ `✔ ++ ${dir}/.postcssrc.js`,
51
+ `✔ ++ ${dir}/.npmignore`,
52
+ `✔ ++ ${dir}/.markuplintrc`,
53
+ `✔ ++ ${dir}/.gitignore`,
54
+ `✔ ++ ${dir}/.eslintrc.cjs`,
55
+ `✔ ++ ${dir}/.editorconfig`,
56
+ `✔ ++ ${dir}/__assets/htdocs/index.pug`,
57
+ `✔ ++ ${dir}/__assets/htdocs/.eslintrc`,
58
+ `✔ ++ ${dir}/__assets/htdocs/js/script.ts`,
59
+ `✔ ++ ${dir}/__assets/htdocs/css/style.scss`,
60
+ `✔ ++ ${dir}/__assets/htdocs/__tmpl/index.pug`,
61
+ `✔ ++ ${dir}/__assets/htdocs/__tmpl/302_form_complete.pug`,
62
+ `✔ ++ ${dir}/__assets/htdocs/__tmpl/301_form_confirm.pug`,
63
+ `✔ ++ ${dir}/__assets/htdocs/__tmpl/300_form_input.pug`,
64
+ `✔ ++ ${dir}/__assets/htdocs/__tmpl/210_blog_index.pug`,
65
+ `✔ ++ ${dir}/__assets/htdocs/__tmpl/200_blog_index.pug`,
66
+ `✔ ++ ${dir}/__assets/htdocs/__tmpl/100_sub.pug`,
67
+ `✔ ++ ${dir}/__assets/htdocs/__tmpl/000_home.pug`,
68
+ `✔ ++ ${dir}/__assets/htdocs/__tmpl/.markuplintrc`,
69
+ `✔ ++ ${dir}/__assets/htdocs/@static/empty`,
70
+ `✔ ++ ${dir}/__assets/htdocs/@static/img/empty`,
71
+ `✔ ++ ${dir}/__assets/_libs/.markuplintrc`,
72
+ `✔ ++ ${dir}/__assets/_libs/style/theme/_index.scss`,
73
+ `✔ ++ ${dir}/__assets/_libs/style/theme/_font.scss`,
74
+ `✔ ++ ${dir}/__assets/_libs/style/theme/_dimension.scss`,
75
+ `✔ ++ ${dir}/__assets/_libs/style/theme/_color.scss`,
76
+ `✔ ++ ${dir}/__assets/_libs/style/general/_img.scss`,
77
+ `✔ ++ ${dir}/__assets/_libs/style/general/_button.scss`,
78
+ `✔ ++ ${dir}/__assets/_libs/style/general/_body.scss`,
79
+ `✔ ++ ${dir}/__assets/_libs/style/general/_all.scss`,
80
+ `✔ ++ ${dir}/__assets/_libs/style/base/_root.scss`,
81
+ `✔ ++ ${dir}/__assets/_libs/script/index.ts`,
82
+ `✔ ++ ${dir}/__assets/_libs/mixin/meta.pug`,
83
+ `✔ ++ ${dir}/__assets/_libs/img/bg-repeat-01.gif`,
84
+ `✔ ++ ${dir}/__assets/_libs/img/bg-arrow.svg`,
85
+ `✔ ++ ${dir}/__assets/_libs/data/data.yml`,
86
+ `✔ ++ ${dir}/__assets/_libs/data/blocks.html`,
87
+ `✔ ++ ${dir}/__assets/_libs/data/blocks.cjs`,
88
+ `✔ ++ ${dir}/__assets/_libs/data/blocks-burger.html`,
89
+ `✔ ++ ${dir}/__assets/_libs/data/.markuplintrc`,
90
+ `✔ ++ ${dir}/__assets/_libs/component/_c-title-page.scss`,
91
+ `✔ ++ ${dir}/__assets/_libs/component/_c-title-page.pug`,
92
+ `✔ ++ ${dir}/__assets/_libs/component/_c-pagination.scss`,
93
+ `✔ ++ ${dir}/__assets/_libs/component/_c-pagination.pug`,
94
+ `✔ ++ ${dir}/__assets/_libs/component/_c-page-sub.scss`,
95
+ `✔ ++ ${dir}/__assets/_libs/component/_c-page-home.scss`,
96
+ `✔ ++ ${dir}/__assets/_libs/component/_c-nav-sitemap.scss`,
97
+ `✔ ++ ${dir}/__assets/_libs/component/_c-nav-sitemap.pug`,
98
+ `✔ ++ ${dir}/__assets/_libs/component/_c-nav-global.scss`,
99
+ `✔ ++ ${dir}/__assets/_libs/component/_c-nav-global.pug`,
100
+ `✔ ++ ${dir}/__assets/_libs/component/_c-nav-breadcrumb.scss`,
101
+ `✔ ++ ${dir}/__assets/_libs/component/_c-nav-breadcrumb.pug`,
102
+ `✔ ++ ${dir}/__assets/_libs/component/_c-media.scss`,
103
+ `✔ ++ ${dir}/__assets/_libs/component/_c-media.pug`,
104
+ `✔ ++ ${dir}/__assets/_libs/component/_c-media-list.scss`,
105
+ `✔ ++ ${dir}/__assets/_libs/component/_c-header.scss`,
106
+ `✔ ++ ${dir}/__assets/_libs/component/_c-header.pug`,
107
+ `✔ ++ ${dir}/__assets/_libs/component/_c-footer.scss`,
108
+ `✔ ++ ${dir}/__assets/_libs/component/_c-footer.pug`,
109
+ `✔ ++ ${dir}/__assets/_libs/component/_c-content-main.scss`,
110
+ `✔ ++ ${dir}/__assets/_libs/component/_c-content-index.scss`,
111
+ `✔ ++ ${dir}/__assets/_libs/component/_c-card.scss`,
112
+ `✔ ++ ${dir}/__assets/_libs/component/_c-card.pug`,
113
+ `✔ ++ ${dir}/__assets/_libs/component/_c-card-list.scss`,
114
+ `✔ ++ ${dir}/.vscode/settings.json`,
115
+ `✔ ++ ${dir}/.vscode/extensions.json`,
116
+ '✔ Install dependencies : skipped',
117
+ ]);
118
+ });
119
+ });
package/locale.js ADDED
@@ -0,0 +1,18 @@
1
+ import { I18n } from 'i18n-js/dist/require/index.js';
2
+
3
+ const i18n = new I18n({
4
+ en: {
5
+ ["What's the type of project?"]: "What's the type of project?",
6
+ ['Destination path']: 'Destination path',
7
+ ['Install dependencies with yarn?']: 'Install dependencies with yarn?',
8
+ },
9
+ ja: {
10
+ ["What's the type of project?"]: 'プロジェクトの種類',
11
+ ['Destination path']: '出力先パス',
12
+ ['Install dependencies with yarn?']: '依存関係をyarnでインストールしますか?',
13
+ },
14
+ });
15
+
16
+ i18n.locale = process.env.LANG?.slice(0, 2) ?? 'en';
17
+
18
+ export const t = (strings) => i18n.t(strings.raw[0]);
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@d-zero/create-frontend",
3
+ "version": "5.0.0-alpha.10",
4
+ "description": "Create a new frontend project from a scaffolding template",
5
+ "repository": "https://github.com/d-zero-dev/frontend-env.git",
6
+ "author": "D-ZERO Co., Ltd.",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "type": "module",
13
+ "bin": {
14
+ "create-dzero-frontend": "./index.js"
15
+ },
16
+ "dependencies": {
17
+ "@d-zero/scaffold": "5.0.0-alpha.10",
18
+ "glob": "10.4.1",
19
+ "i18n-js": "4.4.3",
20
+ "ignore": "5.3.1",
21
+ "meow": "13.2.0",
22
+ "plop": "4.0.1"
23
+ },
24
+ "devDependencies": {
25
+ "@types/glob": "8.1.0"
26
+ },
27
+ "gitHead": "fe914746b4a443aa95604ea28b3235d08f8ecd7f"
28
+ }
package/plopfile.js ADDED
@@ -0,0 +1,180 @@
1
+ import { spawn } from 'node:child_process';
2
+ import path from 'node:path';
3
+
4
+ import { globSync } from 'glob';
5
+ import ignore from 'ignore';
6
+ import meow from 'meow';
7
+
8
+ import { t } from './locale.js';
9
+ import { readFileSafe } from './read-file-safe.js';
10
+
11
+ const cli = meow(
12
+ `
13
+ Usage
14
+ $ yarn create @d-zero/frontend
15
+ or
16
+ $ npx @d-zero/create-frontend
17
+
18
+ Options
19
+ --type, -t Specify the type of project. Then, no interactive mode will be shown.
20
+ --dir, -d Specify the destination directory. Default is the current directory.
21
+ --install Install dependencies with yarn after scaffolding.
22
+
23
+ Examples
24
+ $ yarn create @d-zero/frontend
25
+ $ yarn create @d-zero/frontend --type cms --dir ./my-cms --install
26
+ `,
27
+ {
28
+ importMeta: import.meta,
29
+ flags: {
30
+ type: {
31
+ type: 'string',
32
+ shortFlag: 't',
33
+ },
34
+ dir: {
35
+ type: 'string',
36
+ shortFlag: 'd',
37
+ },
38
+ install: {
39
+ type: 'boolean',
40
+ default: true,
41
+ },
42
+ },
43
+ },
44
+ );
45
+
46
+ /**
47
+ * @param {import('plop').NodePlopAPI} plop
48
+ */
49
+ export default function (plop) {
50
+ const scaffoldDir = path.normalize(
51
+ path.dirname(import.meta.resolve('@d-zero/scaffold').replace('file:', '')),
52
+ );
53
+
54
+ const gitignore = readFileSafe(path.resolve(scaffoldDir, '.gitignore'));
55
+ const ignoreFiles = gitignore?.split('\n').filter(Boolean) ?? [];
56
+
57
+ const ig = ignore()
58
+ // Ignore files in .gitignore
59
+ .add(ignoreFiles)
60
+ // Ignore test files
61
+ .add([
62
+ // Test directories
63
+ '**/*.test/**/*',
64
+ ]);
65
+
66
+ const scaffoldFiles = ig.filter(
67
+ globSync('**/*', {
68
+ cwd: scaffoldDir,
69
+ nodir: true,
70
+ dot: true,
71
+ }),
72
+ );
73
+
74
+ plop.setActionType('Install dependencies', (answers) => {
75
+ const dest = answers['__d-zero_scaffold_dest__'] ?? cli.flags.dir ?? '.';
76
+ const doInstall =
77
+ answers['__d-zero_scaffold_yarn_install__'] ?? cli.flags.install ?? true;
78
+
79
+ const { promise, resolve, reject } = Promise.withResolvers();
80
+
81
+ if (doInstall) {
82
+ const child = spawn('yarn', ['install'], {
83
+ cwd: path.resolve(process.cwd(), dest),
84
+ stdio: 'inherit',
85
+ });
86
+
87
+ child.on('exit', (code) => {
88
+ if (code === 0) {
89
+ resolve(': success');
90
+ } else {
91
+ reject(new Error('Failed to install dependencies'));
92
+ }
93
+ });
94
+
95
+ process.on('SIGINT', () => {
96
+ child.kill('SIGINT');
97
+ });
98
+ } else {
99
+ resolve(': skipped');
100
+ }
101
+
102
+ return promise;
103
+ });
104
+
105
+ plop.setGenerator('basic', {
106
+ description: 'Basic scaffolding',
107
+ prompts: [
108
+ {
109
+ type: 'list',
110
+ name: '__d-zero_project_type__',
111
+ message: t`What's the type of project?`,
112
+ choices: [
113
+ //
114
+ 'Static',
115
+ 'CMS (WordPress etc.)',
116
+ {
117
+ name: 'CMS (baserCMS with BurgerEditor)',
118
+ value: 'burger',
119
+ },
120
+ ],
121
+ default: cli.flags.type ?? 'burger',
122
+ filter: (val) => val.toLowerCase(),
123
+ when: !cli.flags.type,
124
+ },
125
+ {
126
+ type: 'input',
127
+ name: '__d-zero_scaffold_dest__',
128
+ message: t`Destination path`,
129
+ default: '.',
130
+ when: !cli.flags.type,
131
+ },
132
+ {
133
+ type: 'confirm',
134
+ name: '__d-zero_scaffold_yarn_install__',
135
+ message: t`Install dependencies with yarn?`,
136
+ default: true,
137
+ when: !cli.flags.type,
138
+ },
139
+ ],
140
+ actions: function (answers) {
141
+ return [
142
+ ...scaffoldFiles.map(
143
+ /**
144
+ * @see https://plopjs.com/documentation/#add
145
+ * @type {import('plop').AddActionConfig}
146
+ */
147
+ (originFile) => {
148
+ const dest = answers['__d-zero_scaffold_dest__'] ?? cli.flags.dir ?? '.';
149
+ return {
150
+ type: 'add',
151
+ path: path.resolve(dest, originFile),
152
+ templateFile: path.resolve(scaffoldDir, originFile),
153
+ transform(content) {
154
+ if (originFile === 'package.json') {
155
+ const nameCandidate = path.basename(path.resolve(dest));
156
+ const pkg = JSON.parse(content);
157
+ pkg._createdBy = `${pkg.name}@${pkg.version}`;
158
+ pkg.name = nameCandidate;
159
+ pkg.private = true;
160
+ delete pkg.version;
161
+ delete pkg.description;
162
+ delete pkg.repository;
163
+ delete pkg.author;
164
+ delete pkg.license;
165
+ delete pkg.publishConfig;
166
+ delete pkg.files;
167
+ content = JSON.stringify(pkg, null, '\t');
168
+ }
169
+ return content;
170
+ },
171
+ };
172
+ },
173
+ ),
174
+ {
175
+ type: 'Install dependencies',
176
+ },
177
+ ];
178
+ },
179
+ });
180
+ }
@@ -0,0 +1,9 @@
1
+ import fs from 'node:fs';
2
+
3
+ export function readFileSafe(filePath) {
4
+ try {
5
+ return fs.readFileSync(filePath, 'utf8');
6
+ } catch {
7
+ return null;
8
+ }
9
+ }