Skip to content

Commit

Permalink
create: Convert to ESM syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-ac-martin committed May 10, 2022
1 parent f61cf22 commit b70ce67
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 30 deletions.
6 changes: 3 additions & 3 deletions lib-govuk/create/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dist_dir = ./dist
source_dir = ../..
target_dir = $(build_dir)/skel
sources := $(wildcard \
$(source_dir)/plopfile.js \
$(source_dir)/plopfile.mjs \
$(source_dir)/pnpm-lock.yaml \
)
docs_source_dir = $(build_dir)/apps/template
Expand All @@ -25,7 +25,7 @@ skel_proto_deps = \
$(proto_target_dir)/src/common/loading-page.tsx \
$(proto_target_dir)/src/common/page-wrap.tsx \
$(proto_target_dir)/src/common/error-page.tsx
plopfile = $(build_dir)/plopfile.js
plopfile = $(build_dir)/plopfile.mjs

.PHONY: all clean debug

Expand Down Expand Up @@ -59,7 +59,7 @@ $(dist_dir)/skel-prototype.tar: $(skel_proto_deps)
mkdir -p '$(@D)'
cd 'build/' && tar -cf '../$(@)' 'skel-prototype/'

$(plopfile): $(source_dir)/plopfile.js
$(plopfile): $(source_dir)/plopfile.mjs
mkdir -p '$(@D)'
$(cp) '$(<)' '$(@D)'

Expand Down
6 changes: 2 additions & 4 deletions lib-govuk/create/bin/create
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#! /usr/bin/env node
'use strict';

const { resolve } = require('path');
const { runPlop } = require('@not-govuk/plop-pack-internal');
import { resolve } from 'path';
import { runPlop } from '@not-govuk/plop-pack-internal';

const plopfile = resolve(__dirname, '..', 'plopfile.js');

Expand Down
1 change: 1 addition & 0 deletions lib-govuk/create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.4.2",
"description": "A project and prototype initialiser.",
"main": "plopfile.js",
"type": "module",
"bin": "bin/create",
"files": [
"/bin",
Expand Down
14 changes: 9 additions & 5 deletions lib-govuk/create/plopfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
'use strict';
import { resolve } from 'path';
import { extendGenerator } from '@not-govuk/plop-pack-internal';
import { createRequire } from 'node:module';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const { resolve } = require('path');
const { extendGenerator } = require('@not-govuk/plop-pack-internal');
const plopPackInternal = require.resolve('@not-govuk/plop-pack-internal');
const require = createRequire(import.meta.url);
const __dirname = path.dirname(fileURLToPath(import.meta.url));

const plopPackInternal = require.resolve('@not-govuk/plop-pack-internal');
const tarball = resolve(__dirname, 'dist', 'skel.tar');
const tarballPrototype = resolve(__dirname, 'dist', 'skel-prototype.tar');

module.exports = plop => {
export default plop => {
const parent = require.resolve('@not-govuk/create-internal');

plop.load(plopPackInternal, undefined, { actionTypes: true, generators: false, helpers: true, partials: false });
Expand Down
6 changes: 3 additions & 3 deletions lib/create/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ skel_deps = \
$(target_dir)/.github/workflows/main.yml \
$(patsubst $(source_dir)/%,$(target_dir)/%,$(sources)) \
$(patsubst $(docs_source_dir)/%,$(docs_target_dir)/%,$(docs_sources)) \
$(target_dir)/plopfile.js \
$(target_dir)/plopfile.mjs \
$(docs_target_dir)/package.json
plopfile = $(target_dir)/plopfile.js
plopfile = $(target_dir)/plopfile.mjs

.PHONY: all clean

Expand Down Expand Up @@ -114,7 +114,7 @@ $(target_dir)/.github/workflows/main.yml: $(source_dir)/.github/workflows/main.y
mkdir -p '$(@D)'
sed -n '/deploy-/q;p' '$(<)' | sed 's/app: \[.*\]/app: []/' > '$(@)'

$(target_dir)/plopfile.js: $(source_dir)/plopfile.js
$(target_dir)/plopfile.mjs: $(source_dir)/plopfile.mjs
mkdir -p '$(@D)'
sed 's/plop-pack/plop-pack-internal/' '$(<)' > '$(@)'

Expand Down
6 changes: 2 additions & 4 deletions lib/create/bin/create
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#! /usr/bin/env node
'use strict';

const { resolve } = require('path');
const { runPlop } = require('@not-govuk/plop-pack-internal');
import { resolve } from 'path';
import { runPlop } from '@not-govuk/plop-pack-internal';

const plopfile = resolve(__dirname, '..', 'plopfile.js');

Expand Down
1 change: 1 addition & 0 deletions lib/create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.4.2",
"description": "A project and prototype initialiser.",
"main": "plopfile.js",
"type": "module",
"bin": "bin/create",
"files": [
"/bin",
Expand Down
17 changes: 11 additions & 6 deletions lib/create/plopfile.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use strict';

const shell = require('shelljs');
const { resolve } = require('path');
const skelPackage = require('./dist/package.base.json');
import shell from 'shelljs';
import { createRequire } from 'node:module';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import skelPackage from './dist/package.base.json';

const require = createRequire(import.meta.url);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const plopPackInternal = require.resolve('@not-govuk/plop-pack-internal');

const cmd = (command, options) => {
Expand Down Expand Up @@ -59,7 +62,7 @@ const init = () => {
console.log('');
};

module.exports = plop => {
export const plopFile = plop => {
plop.load(plopPackInternal, undefined, { actionTypes: true, generators: false, helpers: true, partials: false });

if (!defaults) {
Expand Down Expand Up @@ -229,3 +232,5 @@ module.exports = plop => {
]
});
};

export default plopFile;
5 changes: 0 additions & 5 deletions plopfile.js

This file was deleted.

5 changes: 5 additions & 0 deletions plopfile.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const plopFunction = async (plop) => {
await plop.load('@not-govuk/plop-pack');
};

export default plopFunction;

0 comments on commit b70ce67

Please sign in to comment.