Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(flutter): create package #173

Merged
merged 21 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ab858c4
feat(flutter): create package
heavybeard Jun 30, 2022
a8e8bae
refactor(flutter): rename directory as other packages
Ciock Jun 30, 2022
0e56395
build: install deps with pnpm
heavybeard Jun 30, 2022
7fc7b5b
chore(flutter): prepare pubspec file
heavybeard Jun 30, 2022
7aea2f9
chore(flutter): set year and holder
heavybeard Jun 30, 2022
58d96ef
chore(flutter): add readme content
heavybeard Jun 30, 2022
a4da510
fix(flutter): remove generated stuff and add flutter_svg dep
heavybeard Jun 30, 2022
dc6c977
feat(flutter): add example file and assets in pubspec
heavybeard Jun 30, 2022
5f977b9
build: start to create flutter generation tasks
heavybeard Jun 30, 2022
974b216
build(flutter): create generation file for dart files
heavybeard Jun 30, 2022
ccb96f3
build(flutter): create entry point file after icon files creation
heavybeard Jun 30, 2022
4c155d0
feat(flutter): create icon classes
heavybeard Jun 30, 2022
c6b91b3
build(flutter): speed up file creation process
heavybeard Jul 1, 2022
abe9c65
refactor(flutter): regenerate new icon files
heavybeard Jul 1, 2022
c7f3d9c
build(flutter): append export to entry file
heavybeard Jul 1, 2022
deac1a4
build(prepublish): add pubspec version updating
heavybeard Jul 1, 2022
ae82d61
perf(flutter): ignore test from package publishing
heavybeard Jul 1, 2022
658ac4d
chore(flutter): ignore static analyzer on templates
Ciock Jul 1, 2022
1ea9a46
ci(release): add flutter package publishing
heavybeard Jul 1, 2022
8c614b4
refactor(flutter): build with svgfilename as filename
heavybeard Jul 2, 2022
7356435
refactor(flutter): import content inside the class and add width, hei…
heavybeard Jul 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
70 changes: 37 additions & 33 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,40 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master # We have to checkout master or PNPM fails. Tag should be on master anyway.
- uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: actions/setup-node@v2
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v2.1.0
with:
version: 6.27.1
run_install: true
- run: pnpm run build
- run: pnpm run prepublish-all
env:
TAG_NAME: ${{ github.ref_name }}
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Release Version ${{ github.ref_name }}
branch: master
- run: git -c user.email="actions@github.com" -c user.name="GitHub Actions" tag -fa ${{ github.ref_name }} -m "${{ github.ref_name }}"
- run: git push -f origin ${{ github.ref_name }}
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: pnpm -r publish --filter ./packages --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/checkout@v2
with:
ref: master # We have to checkout master or PNPM fails. Tag should be on master anyway.
- uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: actions/setup-node@v2
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v2.1.0
with:
version: 6.27.1
run_install: true
- run: pnpm run build
- run: pnpm run prepublish-all
env:
TAG_NAME: ${{ github.ref_name }}
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Release Version ${{ github.ref_name }}
branch: master
- run: git -c user.email="actions@github.com" -c user.name="GitHub Actions" tag -fa ${{ github.ref_name }} -m "${{ github.ref_name }}"
- run: git push -f origin ${{ github.ref_name }}
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: pnpm -r publish --filter ./packages --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: sakebook/actions-flutter-pub-publisher@v1
with:
credential: ${{ secrets.PUB_CREDENTIAL_JSON }}
package_directory: ./packages/iconoir-flutter
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
analyzer:
exclude: [bin/templates/**]
215 changes: 208 additions & 7 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'path';
import os from 'os';
import { promises as fs, readFileSync } from 'fs';
import execa from 'execa';
import { promises as fs, readFileSync } from 'fs';
import { generateTemplateFilesBatch } from 'generate-template-files';
import { Listr } from 'listr2';
import os from 'os';
import path, { basename, dirname } from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';

// Paths
const __dirname = dirname(fileURLToPath(import.meta.url));
Expand All @@ -29,6 +29,7 @@ const incompatibleNames = {
const targets = {
'meta-data': { path: 'meta-data.json' },
css: { path: 'css/iconoir.css' },
'iconoir-flutter': { flutter: true, path: 'packages/iconoir-flutter' },
'iconoir-react': { react: true, path: 'packages/iconoir-react' },
'iconoir-react-native': {
react: true,
Expand Down Expand Up @@ -250,11 +251,204 @@ const tasks = new Listr(
});
},
},
],
{ concurrent: false }
),
},
{
title: 'Building Flutter libraries',
enabled: () =>
cliTargets.length === 0 ||
cliTargets.filter((cliTarget) => targets[cliTarget]?.flutter)
.length > 0,
task: (_, task) =>
task.newListr(
[
{
title: 'Removing temporary directory',
skip: (ctx) => !ctx.tmpDir,
title: 'Creating temporary directory',
task: async (ctx) => {
await fs.rm(ctx.tmpDir, { recursive: true });
try {
ctx.tmpDir = await fs.mkdtemp(
path.join(os.tmpdir(), 'iconoir-')
);
} catch (err) {
ctx.skip = true;
throw new Error(err.message);
}
},
},
{
title:
'Copying icon files to temporary directory, while renaming icons with incompatible names',
skip: (ctx) => ctx.skip,
task: async (ctx) => {
try {
const promises = ctx.iconoirIconsFiles.map((file) => {
const srcFilePath = path.join(
iconoirIconsDir,
file
);
const iconName = file.split('.')[0];
const dstFileName =
iconName in incompatibleNames
? incompatibleNames[iconName]
: iconName;
const dstFilePath = path.join(
ctx.tmpDir,
`${dstFileName}.svg`
);

ctx.dstFilePaths = [
...(ctx.dstFilePaths ?? []),
dstFilePath,
];

return fs.copyFile(srcFilePath, dstFilePath);
});
return Promise.all(promises).catch((err) => {
ctx.skip = true;
throw new Error(err.message);
});
} catch (err) {
ctx.skip = true;
throw new Error(err.message);
}
},
},
{
skip: (ctx) => ctx.skip,
task: (_, task) => {
const targetsToBuild =
cliTargets.length > 0
? cliTargets.filter(
(cliTarget) => targets[cliTarget]?.flutter
)
: Object.keys(targets).filter(
(target) => targets[target].flutter
);
const tasks = targetsToBuild.map((target) => {
const builtIconsDir = path.join(
rootDir,
targets[target].path,
'lib'
);
return {
title: `Building ${target}`,
task: (_, task) =>
task.newListr(
[
{
title: 'Cleaning target directory',
task: async (ctx) => {
try {
const files = await fs.readdir(
builtIconsDir
);
const promises = files.map((file) => {
return fs.unlink(
path.join(builtIconsDir, file)
);
});
return Promise.all(promises).catch(
(err) => {
ctx[target] = { skip: true };
throw new Error(err.message);
}
);
} catch (err) {
ctx[target] = { skip: true };
throw new Error(err.message);
}
},
},
{
title: 'Create entry file',
task: async () => {
await fs.writeFile(
path.join(
builtIconsDir,
'iconoir_flutter.dart'
),
'library iconoir_flutter;\n\n'
);
},
},
{
title: 'Building icon files',
skip: (ctx) => ctx[target]?.skip,
task: async (ctx) => {
try {
ctx.dstFilePaths.forEach(
async (file) => {
const svgfilename =
path.parse(file).name;
// Prefix with Svg if icon name starts with a number
const iconname = `${
/^\d/.test(svgfilename)
? 'Svg'
: ''
}${svgfilename}`;

const svgfilecontent = (
await fs.readFile(file)
).toString();

await generateTemplateFilesBatch([
{
option:
'Create Icon Flutter Widget',
entry: {
folderPath:
'./bin/templates/__svgfilename__.dart',
},
dynamicReplacers: [
{
slot: '__icon__',
slotValue: iconname,
},
{
slot: '__svgfilecontent__',
slotValue: svgfilecontent,
},
{
slot: '__svgfilename__',
slotValue: svgfilename,
},
],
output: {
path: './packages/iconoir-flutter/lib/__svgfilename__(snakeCase).dart',
pathAndFileNameDefaultCase:
'(snakeCase)',
},
async onComplete(results) {
await fs.appendFile(
path.join(
builtIconsDir,
'iconoir_flutter.dart'
),
`export './${basename(
results.output.path
)}';\n`
);
},
},
]);
}
);
} catch (err) {
throw new Error(err.message);
}
},
},
],
{ concurrent: false, exitOnError: false }
),
};
});
return task.newListr(tasks, {
concurrent: true,
rendererOptions: { collapse: false },
});
},
},
],
Expand All @@ -265,6 +459,13 @@ const tasks = new Listr(
{ concurrent: true }
),
},
{
title: 'Removing temporary directory',
skip: (ctx) => !ctx.tmpDir,
task: async (ctx) => {
await fs.rm(ctx.tmpDir, { recursive: true });
},
},
],
{
concurrent: false,
Expand Down
38 changes: 26 additions & 12 deletions bin/prepublish.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import semver from 'semver';
import path from 'path';
import { updateYamlKey } from '@atomist/yaml-updater';
import fs from 'fs';
import path from 'path';
import semver from 'semver';

const PACKAGE_BASE = '';

function publishPackage(name) {
console.info('Publishing %s', name);
const newVersion = semver.valid(semver.coerce(process.env.TAG_NAME));
console.info('New version is %s', newVersion);
if (!newVersion) {
throw new Error(`Tag name ${process.env.TAG_NAME} is not valid.`);
}

const newVersion = semver.valid(semver.coerce(process.env.TAG_NAME));
console.info('New version is %s', newVersion);
if (!newVersion) {
throw new Error(`Tag name ${process.env.TAG_NAME} is not valid.`);
}
function publishNpmPackage(name) {
console.info('Publishing %s', name);

const packageJsonPath =
name === 'iconoir'
Expand All @@ -26,6 +27,19 @@ function publishPackage(name) {
console.info('package.json updated');
}

publishPackage('iconoir');
publishPackage('iconoir-react');
publishPackage('iconoir-react-native');
function publishPubPackage(name) {
const pubspecFilepath = path.join('packages', name, 'pubspec.yaml');
const pubspecContents = fs.readFileSync(pubspecFilepath).toString();

fs.writeFileSync(
pubspecFilepath,
updateYamlKey('version', newVersion, pubspecContents)
);

console.info('pubspec.yaml updated');
}

publishNpmPackage('iconoir');
publishNpmPackage('iconoir-react');
publishNpmPackage('iconoir-react-native');
publishPubPackage('iconoir-flutter');
20 changes: 20 additions & 0 deletions bin/templates/__svgfilename__.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/flutter_svg.dart';

class __icon__(pascalCase) extends StatelessWidget {
final Color? color;
final double? width;
final double? height;

const __icon__(pascalCase)({Key? key, this.color, this.width, this.height})
: super(key: key);

@override
Widget build(BuildContext context) => SvgPicture.string(
'''
__svgfilecontent__''',
color: color,
width: width,
height: height,
);
}
Loading